From 402107a237a7039b0aa2028f6c21939e53c98dc4 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Sun, 15 Oct 2023 22:22:18 +0200 Subject: support tag metadata, make much everything nicer --- Types.hs | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'Types.hs') diff --git a/Types.hs b/Types.hs index 4e1e037..e164d00 100644 --- a/Types.hs +++ b/Types.hs @@ -20,6 +20,7 @@ -- | Separated-out main types of the deployment scriptage. module Types where +import AesonUtils import Control.Monad.Trans.State.Lazy import qualified Data.ByteString.UTF8 import qualified Data.Map as M @@ -29,7 +30,6 @@ import Lens.Micro.TH import Options.Applicative import qualified Text.Mustache as Mu import qualified Text.Pandoc.Definition -import AesonUtils -- | Information about a single deployed page (with metadata etc). data PageInfo = @@ -45,30 +45,20 @@ makeLenses ''PageInfo -- | Complete internal state of the deployment process that holds all data data SiteState = SiteState - -- | Map of page mounts to `PageInfo` - { _pages :: M.Map FilePath PageInfo - -- | Map of redirects (from -> to) - , _redirects :: M.Map FilePath FilePath - -- | Map of tags, assigning to each tag sequence a list of - -- tagged page mounts - , _htags :: M.Map [String] [FilePath] - -- | Map of tags, assigning to each tag sequence a list of tagged page - -- mounts. This one is expanded (tags imply parent categories). - , _ehtags :: M.Map [String] [FilePath] - -- | Map of "short" tags to expanded human-friendly names - , _tagNames :: M.Map String String - -- | List of installed files (enables sharing) - , _installs :: S.Set (String, FilePath) - -- | List of installed files (prevents overwriting) - , _targets :: S.Set FilePath - -- | Map of Mustache templates organized by template search path (within - -- the template directory) - , _templates :: M.Map FilePath Mu.Template + { _pages :: M.Map FilePath PageInfo -- ^ Map of page mounts to `PageInfo` + , _redirects :: M.Map FilePath FilePath -- ^ Map of redirects (from -> to) + , _htags :: M.Map [String] [FilePath] -- ^ Map of tags, assigning to each tag sequence a list of tagged page mounts + , _ehtags :: M.Map [String] [FilePath] -- ^ Map of tags, assigning to each tag sequence a list of tagged page mounts. This one is expanded (tags imply parent categories). + , _tagMeta :: M.Map [String] Y.Value -- ^ Map of tags to expanded human-friendly names + , _installs :: S.Set (String, FilePath) -- ^ List of copy-installed files (among other, this enables sharing) + , _targets :: S.Set FilePath -- ^ List of files installed to the target site (this allows us to throw an error in case anything would write to the same target twice) + , _templates :: M.Map FilePath Mu.Template -- ^ Map of Mustache templates organized by template search path (within the template directory) , _outputDir :: FilePath -- ^ Directory for output , _searchDataOut :: Maybe FilePath -- ^ File to write the searchable versions of pages to (as JSON) , _assetDirs :: [FilePath] -- ^ Directory for output , _sourceDirs :: [FilePath] -- ^ Path to page source data , _notSourceDirs :: [FilePath] -- ^ Subdirectories of source dirs where pages should not be sourced + , _tagMetaFile :: FilePath -- ^ Name of the "tag metadata" files to find in the source directories. , _templateDir :: FilePath -- ^ Path to template directory , _defaultTemplate :: FilePath -- ^ Name of the default template , _redirectTemplate :: FilePath -- ^ Name of the template for redirect pages @@ -76,8 +66,9 @@ data SiteState = , _listTemplate :: FilePath -- ^ Name of the template for listing pages , _extraMeta :: Y.Value -- ^ Extra metadata added to rendering of all templates , _metadataSuffix :: FilePath -- ^ File suffix to search for a extra metadata (e.g., if the suffix is ".extra", the extra metadata for file "page.md" will be looked for in "page.md.extra"). These are best autogenerated with a script that sources the data from git or so. + , _indexFile :: FilePath -- ^ Name of the "index" files to be generated. , _urlBase :: FilePath -- ^ "Root route" to prepend to all absolute links. - , _appendUrlIndex :: Bool -- ^ Append full @index.html@ to all page URLs + , _appendUrlIndex :: Bool -- ^ Append full index filenames to all page URLs , _dumpFinalState :: Bool -- ^ Triggers printing out the structure when the processing finishes. } deriving (Show) @@ -116,6 +107,11 @@ siteOptions' = do long "exclude-source-directory" <> help "Names of subdirectories of the sources that should never be used for sourcing pages (possibly multiple directory names)" + _tagMetaFile <- + strOption $ + long "tag-metadata-file" <> + help "Name of files with tag metadata" <> + value "tag-metadata.yml" <> showDefault _templateDir <- strOption $ long "template-directory" <> @@ -144,7 +140,8 @@ siteOptions' = do _metadataSuffix <- strOption $ long "metadata-suffix" <> - help "Suffix for YAML files with base metadata for each markdown page. Metadata from files override the extra metadata specified on commandline, but are overriden by metadata specified directly in the markdown header." <> + help + "Suffix for YAML files with base metadata for each markdown page. Metadata from files override the extra metadata specified on commandline, but are overridden by metadata specified directly in the markdown header of the pages." <> value ".metadata.yml" <> showDefault _extraMeta <- let processKeyVal :: String -> Y.Value @@ -153,7 +150,8 @@ siteOptions' = do Right v -> v Left err -> error $ - "cannot parse YAML in --extra-metadata: " ++ Y.prettyPrintParseException err + "cannot parse YAML in --extra-metadata: " ++ + Y.prettyPrintParseException err in fmap (foldl objMerge Y.Null . map processKeyVal) . many . strOption $ long "extra-metadata" <> help @@ -162,6 +160,10 @@ siteOptions' = do strOption $ long "url-base" <> short 'u' <> help "Base absolute URL" <> value "/" <> showDefault + _indexFile <- + strOption $ + long "index-filename" <> + help "Base absolute URL" <> value "index.html" <> showDefault _appendUrlIndex <- switch $ long "append-url-index" <> @@ -178,7 +180,7 @@ siteOptions' = do , _redirects = M.empty , _htags = M.empty , _ehtags = M.empty - , _tagNames = M.empty + , _tagMeta = M.empty , _installs = S.empty , _targets = S.empty , _templates = M.empty -- cgit v1.2.3