Added compile rule on assets.

Assets declared throughout Components are gathered in a FileTree
structure. At compile time, the assets tree is flattened to give all
assets paths and each asset is matched and copied.
This prevents unused assets that are in the source to be deployed.
This commit is contained in:
Etienne Werly 2023-06-19 22:17:20 +02:00
parent 4a900ab57c
commit 978dffb671
2 changed files with 8 additions and 3 deletions

View file

@ -11,6 +11,7 @@ import Text.Blaze.Html
import Components
import Core.Compilers
import Core.Render
import Utils.FileTree
import Kit.Templates.Index ( indexTemplate )
import Kit.Templates.Post ( postTemplate )
@ -18,6 +19,9 @@ import Kit.Templates.Post ( postTemplate )
allTemplates :: [Component Html]
allTemplates = [postTemplate, indexTemplate]
assets :: [FilePath]
assets = map tail . getPaths . getAssets . mconcat $ allTemplates
allCss :: String
allCss = show . getCss . mconcat $ allTemplates
@ -52,7 +56,7 @@ main = hakyll $ do
route $ constRoute "css/default.css"
compile css
match "assets/img/*" $ do
match (fromList . map fromFilePath $ assets) $ do
route idRoute
compile copyFileCompiler

View file

@ -9,6 +9,7 @@ module Components
, addAsset'
, getHtml
, getCss
, getAssets
) where
import Clay ( Css
@ -61,5 +62,5 @@ getCss :: Component a -> Css
getCss = mconcat . map snd . Map.toList . cssMap . snd . runWriter
-- |Get a Component's assets tree
getFileTree :: Component a -> FileTree
getFileTree = assetsTree . snd . runWriter
getAssets :: Component a -> FileTree
getAssets = assetsTree . snd . runWriter