diff options
Diffstat (limited to 'Types.hs')
| -rw-r--r-- | Types.hs | 97 |
1 files changed, 47 insertions, 50 deletions
@@ -20,9 +20,9 @@ -- | 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 Data.List.NonEmpty (nonEmpty, toList) import qualified Data.Map as M import qualified Data.Set as S import qualified Data.Yaml as Y @@ -45,39 +45,30 @@ 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) - , _assetDir :: FilePath -- ^ Directory for output + , _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 , _tagTemplate :: FilePath -- ^ Name of the template for category pages , _listTemplate :: FilePath -- ^ Name of the template for listing pages - , _extraMeta :: [(String, Y.Value)] -- ^ Extra metadata added to rendering of all templates - , _timestampSuffix :: FilePath -- ^ File to search for a timestamp (e.g., if the prefix is ".ts", a timestamp for file "page.md" will be looked for in "page.md.ts"). These are best autogenerated with a script that sources the data from git or so. + , _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) @@ -101,23 +92,26 @@ siteOptions' = do long "search-data-output" <> help "Output JSON with searchable page data to this file") <|> pure Nothing - _assetDir <- - strOption $ + _assetDirs <- + many . strOption $ long "assets" <> short 'a' <> - help "Assets directory to be copied verbatim" <> - value "assets" <> showDefault + help "Assets directory to be copied verbatim (possibly multiple paths)" _sourceDirs <- - fmap (maybe ["pages"] toList . nonEmpty) . many . strOption $ + many . strOption $ long "source-directory" <> short 's' <> - help - "Path to the directory with source data (possibly multiple paths, defaults to a single directory \"pages\")" + help "Path to the directory with source data (possibly multiple paths)" _notSourceDirs <- - fmap (maybe ["assets"] toList . nonEmpty) . many . strOption $ + many . strOption $ long "exclude-source-directory" <> help - "Names of subdirectories of the sources that should never be used for sourcing pages (possibly multiple directory names, defaults to a single directory \"assets\")" + "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" <> @@ -126,7 +120,7 @@ siteOptions' = do _defaultTemplate <- strOption $ long "default-template" <> - help "Default template to use for stuff (found in templates directory)" <> + help "Default template to use for stuff (as found in templates directory)" <> value "default.html" <> showDefault _redirectTemplate <- strOption $ @@ -143,30 +137,33 @@ siteOptions' = do long "list-template" <> help "Template for making tag-listing pages" <> value "list.html" <> showDefault - _timestampSuffix <- + _metadataSuffix <- strOption $ - long "timestamp-prefix" <> - help "Timestamp file suffix for markdowns" <> - value ".timestamp" <> showDefault + 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 overridden by metadata specified directly in the markdown header of the pages." <> + value ".metadata.yml" <> showDefault _extraMeta <- - let processKeyVal :: String -> (String, Y.Value) + let processKeyVal :: String -> Y.Value processKeyVal opt = - case break (== ':') opt of - (k, ':':v) -> - case Y.decodeEither' $ Data.ByteString.UTF8.fromString v of - Right v -> (k, v :: Y.Value) - Left err -> - error $ - "cannot parse key:val in --extra-metadata: " ++ show err - _ -> error "cannot process key:val in --extra-metadata" - in fmap (map processKeyVal) . many . strOption $ + case Y.decodeEither' $ Data.ByteString.UTF8.fromString opt of + Right v -> v + Left err -> + error $ + "cannot parse YAML in --extra-metadata: " ++ + Y.prettyPrintParseException err + in fmap (foldl objMerge Y.Null . map processKeyVal) . many . strOption $ long "extra-metadata" <> help - "Extra metadata to add to pages rendering in format `key:<yaml>'. May be specified multiple times." + "Extra metadata to add to pages rendering in YAML format. May be specified multiple times." _urlBase <- 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" <> @@ -183,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 |
