aboutsummaryrefslogtreecommitdiff
path: root/reploy.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2025-01-29 20:37:50 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2025-01-29 20:37:50 +0100
commit859a65e61d9dc6cd68f048fda0f0da4b9bcc1396 (patch)
tree3b37bfe7a58f073985cb5bd9a6dbdd38f0236077 /reploy.hs
parent5fabdce6b81427c99bcc17b0f75e3f4dadd2194c (diff)
downloadreploy-859a65e61d9dc6cd68f048fda0f0da4b9bcc1396.tar.gz
reploy-859a65e61d9dc6cd68f048fda0f0da4b9bcc1396.tar.bz2
extra metadata loading from a yaml file
Diffstat (limited to 'reploy.hs')
-rw-r--r--reploy.hs28
1 files changed, 28 insertions, 0 deletions
diff --git a/reploy.hs b/reploy.hs
index dbdb091..cf4de56 100644
--- a/reploy.hs
+++ b/reploy.hs
@@ -26,6 +26,7 @@ import qualified Data.Aeson as AE
import qualified Data.Aeson.Key as K
import qualified Data.Aeson.KeyMap as KM
import qualified Data.ByteString.Lazy as B
+import qualified Data.ByteString.UTF8
import Data.Digest.Pure.SHA (sha256, showDigest)
import Data.Foldable (traverse_)
import Data.List (inits, nub, sort)
@@ -511,10 +512,37 @@ renderSearchData = use searchDataOut >>= traverse_ go
putStrLn $ "S -> " ++ out
AE.encodeFile out $ Y.array (concat ps)
+-- | Souce extra metadata accordingly to the metadata specifications
+sourceExtraMetadata :: Site ()
+sourceExtraMetadata = do
+ use extraMetaSpec
+ >>= fmap (foldl objMerge Y.Null) . traverse loadSpec
+ >>= assign extraMeta
+ where
+ loadSpec :: MetaSpec -> Site Y.Value
+ loadSpec (MetaSpecInline yaml) =
+ case Y.decodeEither' $ Data.ByteString.UTF8.fromString yaml of
+ Right v -> pure v
+ Left err ->
+ error
+ $ "cannot parse extra metadata from inline YAML: "
+ ++ Y.prettyPrintParseException err
+ loadSpec (MetaSpecFile path) = do
+ res <- io $ Y.decodeFileEither path
+ case res of
+ Right v -> pure v
+ Left err ->
+ error
+ $ "cannot load YAML metadata from "
+ ++ path
+ ++ ": "
+ ++ Y.prettyPrintParseException err
+
-- | Build the whole site.
main = do
init <- Options.Applicative.execParser siteOptions
flip runStateT init $ do
+ sourceExtraMetadata
installAssets
use sourceDirs >>= traverse sourcePages
use sourceDirs >>= traverse sourceTagMeta