aboutsummaryrefslogtreecommitdiff
path: root/Types.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <miroslav.kratochvil@uni.lu>2023-10-16 19:08:27 +0200
committerMirek Kratochvil <miroslav.kratochvil@uni.lu>2023-10-16 19:08:27 +0200
commite2cec0c7a7d56058773f3534c202e1b85f57baff (patch)
treecfffdeb0b8214c455f5e84919dcc621460408d67 /Types.hs
parent56dcda56193d0148af8868d81247010c0d0b8db3 (diff)
downloadreploy-e2cec0c7a7d56058773f3534c202e1b85f57baff.tar.gz
reploy-e2cec0c7a7d56058773f3534c202e1b85f57baff.tar.bz2
reformat using new hindent (cuteness +63)
Diffstat (limited to 'Types.hs')
-rw-r--r--Types.hs234
1 files changed, 124 insertions, 110 deletions
diff --git a/Types.hs b/Types.hs
index e164d00..992c866 100644
--- a/Types.hs
+++ b/Types.hs
@@ -32,46 +32,42 @@ import qualified Text.Mustache as Mu
import qualified Text.Pandoc.Definition
-- | Information about a single deployed page (with metadata etc).
-data PageInfo =
- PageInfo
- { _pagePath :: FilePath -- ^ original path to the markdown file
- , _pageMeta :: Y.Value -- ^ YAML metadata extracted from the file
- , _pageDoc :: Text.Pandoc.Definition.Pandoc -- ^ Page data
- }
- deriving (Show)
+data PageInfo = PageInfo
+ { _pagePath :: FilePath -- ^ original path to the markdown file
+ , _pageMeta :: Y.Value -- ^ YAML metadata extracted from the file
+ , _pageDoc :: Text.Pandoc.Definition.Pandoc -- ^ Page data
+ } deriving (Show)
makeLenses ''PageInfo
-- | Complete internal state of the deployment process that holds all data
-data SiteState =
- SiteState
- { _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
- , _tagTemplate :: FilePath -- ^ Name of the template for category pages
- , _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 filenames to all page URLs
- , _dumpFinalState :: Bool -- ^ Triggers printing out the structure when the processing finishes.
- }
- deriving (Show)
+data SiteState = SiteState
+ { _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
+ , _tagTemplate :: FilePath -- ^ Name of the template for category pages
+ , _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 filenames to all page URLs
+ , _dumpFinalState :: Bool -- ^ Triggers printing out the structure when the processing finishes.
+ } deriving (Show)
makeLenses ''SiteState
@@ -82,98 +78,116 @@ type Site a = StateT SiteState IO a
siteOptions' :: Parser SiteState
siteOptions' = do
_outputDir <-
- strOption $
- long "output" <>
- short 'd' <>
- help "Directory to render the site to" <> value "_site" <> showDefault
+ strOption
+ $ long "output"
+ <> short 'd'
+ <> help "Directory to render the site to"
+ <> value "_site"
+ <> showDefault
_searchDataOut <-
- Just <$>
- (strOption $
- long "search-data-output" <>
- help "Output JSON with searchable page data to this file") <|>
- pure Nothing
+ Just
+ <$> (strOption
+ $ long "search-data-output"
+ <> help "Output JSON with searchable page data to this file")
+ <|> pure Nothing
_assetDirs <-
- many . strOption $
- long "assets" <>
- short 'a' <>
- help "Assets directory to be copied verbatim (possibly multiple paths)"
+ many . strOption
+ $ long "assets"
+ <> short 'a'
+ <> help
+ "Assets directory to be copied verbatim (possibly multiple paths)"
_sourceDirs <-
- many . strOption $
- long "source-directory" <>
- short 's' <>
- help "Path to the directory with source data (possibly multiple paths)"
+ many . strOption
+ $ long "source-directory"
+ <> short 's'
+ <> help
+ "Path to the directory with source data (possibly multiple paths)"
_notSourceDirs <-
- 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)"
+ 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)"
_tagMetaFile <-
- strOption $
- long "tag-metadata-file" <>
- help "Name of files with tag metadata" <>
- value "tag-metadata.yml" <> showDefault
+ strOption
+ $ long "tag-metadata-file"
+ <> help "Name of files with tag metadata"
+ <> value "tag-metadata.yml"
+ <> showDefault
_templateDir <-
- strOption $
- long "template-directory" <>
- help "Path to the directory with templates" <>
- value "templates" <> showDefault
+ strOption
+ $ long "template-directory"
+ <> help "Path to the directory with templates"
+ <> value "templates"
+ <> showDefault
_defaultTemplate <-
- strOption $
- long "default-template" <>
- help "Default template to use for stuff (as found in templates directory)" <>
- value "default.html" <> showDefault
+ strOption
+ $ long "default-template"
+ <> help
+ "Default template to use for stuff (as found in templates directory)"
+ <> value "default.html"
+ <> showDefault
_redirectTemplate <-
- strOption $
- long "redirect-template" <>
- help "Template for making redirect pages" <>
- value "redirect.html" <> showDefault
+ strOption
+ $ long "redirect-template"
+ <> help "Template for making redirect pages"
+ <> value "redirect.html"
+ <> showDefault
_tagTemplate <-
- strOption $
- long "tag-template" <>
- help "Template for making category view pages" <>
- value "tag.html" <> showDefault
+ strOption
+ $ long "tag-template"
+ <> help "Template for making category view pages"
+ <> value "tag.html"
+ <> showDefault
_listTemplate <-
- strOption $
- long "list-template" <>
- help "Template for making tag-listing pages" <>
- value "list.html" <> showDefault
+ strOption
+ $ long "list-template"
+ <> help "Template for making tag-listing pages"
+ <> value "list.html"
+ <> showDefault
_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 overridden by metadata specified directly in the markdown header of the pages." <>
- value ".metadata.yml" <> showDefault
+ 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 overridden by metadata specified directly in the markdown header of the pages."
+ <> value ".metadata.yml"
+ <> showDefault
_extraMeta <-
let processKeyVal :: String -> Y.Value
processKeyVal opt =
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 YAML format. May be specified multiple times."
+ 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 YAML format. May be specified multiple times."
_urlBase <-
- strOption $
- long "url-base" <>
- short 'u' <> help "Base absolute URL" <> value "/" <> showDefault
+ 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
+ strOption
+ $ long "index-filename"
+ <> help "Base absolute URL"
+ <> value "index.html"
+ <> showDefault
_appendUrlIndex <-
- switch $
- long "append-url-index" <>
- help
- "Append 'index.html' to all urls, negating server problems with directory index settings."
+ switch
+ $ long "append-url-index"
+ <> help
+ "Append 'index.html' to all urls, negating server problems with directory index settings."
_dumpFinalState <-
- switch $
- long "dump-state" <>
- short 'D' <>
- help "Print out the complete internal state after the site is built"
+ switch
+ $ long "dump-state"
+ <> short 'D'
+ <> help
+ "Print out the complete internal state after the site is built"
pure
SiteState
{ _pages = M.empty
@@ -191,6 +205,6 @@ siteOptions' = do
siteOptions =
info
(siteOptions' <**> helper)
- (fullDesc <>
- progDesc "Build a R3 static site" <>
- header "reploy - the R3 static site builder")
+ (fullDesc
+ <> progDesc "Build a R3 static site"
+ <> header "reploy - the R3 static site builder")