aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2025-01-29 20:39:57 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2025-01-29 20:39:57 +0100
commiteeb49be54a981b3a92cd518a984c59f547ac14d6 (patch)
tree40c8be9e1e8019268c2f264ea8051c47892933d9
parent7596161a26f9738d22f5e6ea70bc4ea872ee9652 (diff)
parentf0258edf003fd58fe6df6b858bbccbc0efd70e08 (diff)
downloadreploy-eeb49be54a981b3a92cd518a984c59f547ac14d6.tar.gz
reploy-eeb49be54a981b3a92cd518a984c59f547ac14d6.tar.bz2
Merge changes from the old gitlab
-rw-r--r--Dockerfile2
-rw-r--r--Types.hs40
-rw-r--r--reploy.cabal73
-rw-r--r--reploy.hs28
-rw-r--r--templates/header.html6
-rw-r--r--test.yml3
6 files changed, 102 insertions, 50 deletions
diff --git a/Dockerfile b/Dockerfile
index 4a35c65..9dbe0ea 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -31,4 +31,4 @@ WORKDIR /data
COPY assets /data/assets/
COPY templates /data/templates/
COPY pages /data/pages/
-ENTRYPOINT ["/root/.cabal/bin/reploy"]
+ENTRYPOINT ["/root/.local/bin/reploy"]
diff --git a/Types.hs b/Types.hs
index e42dafa..78f0013 100644
--- a/Types.hs
+++ b/Types.hs
@@ -20,9 +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
import qualified Data.Set as S
import qualified Data.Yaml as Y
@@ -40,6 +38,14 @@ data PageInfo = PageInfo
makeLenses ''PageInfo
+-- | Information about where to source all extra metadata
+data MetaSpec
+ = MetaSpecInline String
+ | MetaSpecFile FilePath
+ deriving (Show)
+
+makeLenses ''MetaSpec
+
-- | 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`
@@ -62,6 +68,7 @@ data SiteState = SiteState
, _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
+ , _extraMetaSpec :: [MetaSpec] -- ^ sources for the extra metadata
, _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.
@@ -151,20 +158,20 @@ siteOptions' = do
"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"
- <> short 'e'
- <> help
- "Extra metadata to add to pages rendering in YAML format. May be specified multiple times."
+ _extraMetaSpec <-
+ many
+ $ asum
+ [ fmap MetaSpecInline . strOption
+ $ long "extra-metadata"
+ <> short 'e'
+ <> help
+ "Extra metadata to add to pages rendering in YAML format. May be specified multiple times."
+ , fmap MetaSpecFile . strOption
+ $ long "extra-metadata-file"
+ <> short 'E'
+ <> help
+ "Extra metadata to add to pages rendering, loaded from a YAML file. May be specified multiple times."
+ ]
_urlBase <-
strOption
$ long "url-base"
@@ -199,6 +206,7 @@ siteOptions' = do
, _installs = S.empty
, _targets = S.empty
, _templates = M.empty
+ , _extraMeta = Y.Null
, ..
}
diff --git a/reploy.cabal b/reploy.cabal
index d49776c..d4d5f57 100644
--- a/reploy.cabal
+++ b/reploy.cabal
@@ -1,38 +1,45 @@
-cabal-version: 3.0
-
-name: reploy
-synopsis: Straightforward static all-in-one website builder
-category: Web
-version: 0.3.2.0
-build-type: Simple
-license: Apache-2.0
-license-file: LICENSE
+cabal-version: 3.0
+name: reploy
+synopsis: Straightforward static all-in-one website builder
+category: Web
+version: 0.3.3.0
+build-type: Simple
+license: Apache-2.0
+license-file: LICENSE
executable reploy
main-is: reploy.hs
- other-modules: Types, AesonUtils, Utils, Tags, FormatOpts
- build-depends: base == 4.*
- , aeson ^>= 2.1
- , bytestring
- , containers
- , data-default
- , directory
- , extra
- , filepath
- , microlens
- , microlens-aeson
- , microlens-mtl
- , microlens-th
- , mustache
- , optparse-applicative
- , pandoc
- , pandoc-types
- , parsec
- , scientific
- , SHA
- , text
- , transformers
- , utf8-string
- , yaml
+ other-modules:
+ AesonUtils
+ FormatOpts
+ Tags
+ Types
+ Utils
+
+ build-depends:
+ , aeson ^>=2.1 || ^>=2.2
+ , base >=4 && <5
+ , bytestring
+ , containers
+ , data-default
+ , directory
+ , extra
+ , filepath
+ , microlens
+ , microlens-aeson
+ , microlens-mtl
+ , microlens-th
+ , mustache
+ , optparse-applicative
+ , pandoc
+ , pandoc-types
+ , parsec
+ , scientific
+ , SHA
+ , text
+ , transformers
+ , utf8-string
+ , yaml
+
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wunused-imports
default-language: Haskell2010
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
diff --git a/templates/header.html b/templates/header.html
index d4e4799..2eb2531 100644
--- a/templates/header.html
+++ b/templates/header.html
@@ -1,4 +1,10 @@
<header>
+ {{?menu_items}}Menu:
+ <ul>
+ {{#menu_items}}<li>{{.}}</li>{{/menu_items}}
+ </ul>
+ {{/menu_items}}
+
Navigation:
<ul>
<li><a href="{{#pageLink}}/{{/pageLink}}">{{#pageName}}/{{/pageName}}</a></li>
diff --git a/test.yml b/test.yml
new file mode 100644
index 0000000..0ae8131
--- /dev/null
+++ b/test.yml
@@ -0,0 +1,3 @@
+menu_items:
+ - item1
+ - item2