more dynamic structure

This commit is contained in:
Gregor Kleen 2023-05-13 21:22:11 +02:00
parent 71c636bba3
commit 9fbd4ac9eb
11 changed files with 124 additions and 21 deletions

2
Gupfile Normal file
View File

@ -0,0 +1,2 @@
checksum.gup:
**/.*.chksum

14
checksum.gup Normal file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env zsh
gup --always
base=${2:t}
base=${base#"."}
base=${base%".chksum"}
base=${2:h}/${base}
while IFS= read -d $'\0' file; do
if [[ -f "${file}" ]]; then
b2sum "${file}"
else
echo "${file}"
fi
done > >(gup --contents) < <(find "${base}" -print0)

7
content/markdown.md Normal file
View File

@ -0,0 +1,7 @@
---
title: Seite unterstützt Markdown
tags: meta
sort: 0
---
Text kann auch in allen Pandoc-unterstützten Formaten angegeben werden, statt nur in HTML.
Hier: Markdown

8
content/tags.md Normal file
View File

@ -0,0 +1,8 @@
---
title: Tags sind echte Tags
tags:
- meta
- example
sort: 100
---
Beliebig viele Tags pro Item.

View File

@ -1,3 +1,11 @@
---
title: Seite befindet sich im Aufbau
tags:
- index
- meta
sort: -9001
---
```{=html}
<div class="px-4 py-5 my-5 text-center">
<h1 class="display-5 fw-bold text-body-emphasis">UniWorX Systems</h1>
<div class="col-lg-6 mx-auto">
@ -7,3 +15,4 @@
</p>
</div>
</div>
```

View File

@ -1,6 +1,6 @@
#!/usr/bin/env sh
gup --always
gup -u node_modules
gup -u node_modules webpack.config.js postcss.config.js
gup -u .src.chksum
rm -rf dist
yarn run build

View File

@ -1,5 +1,5 @@
#!/usr/bin/env sh
gup --always
gup -u package.json yarn.lock
yarn install
touch node_modules

View File

@ -6,9 +6,8 @@ default-extensions:
- NoImplicitPrelude
- ViewPatterns
- DerivingStrategies
- DeriveGeneric
- GeneralizedNewtypeDeriving
- TypeApplications
- MultiWayIf
language: GHC2021
executables:
site:

View File

@ -4,15 +4,15 @@ import Prelude
import Hakyll
import qualified Data.List as List
import Data.List qualified as List
import Data.Maybe
import System.FilePath
import qualified System.FilePath.Glob as Glob
import System.FilePath.Glob qualified as Glob
import qualified Data.Yaml as Yaml
import Data.Yaml qualified as Yaml
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Map qualified as Map
import Control.Monad
@ -32,15 +32,9 @@ main = hakyllWith config $ do
frontendManifest <-
preprocess $
Yaml.decodeFileThrow @_ @(Map String [FilePath]) "frontend/dist/.manifest.yaml"
match "content/index.html" $ do
route $ stripPathPrefix "content"
let context =
defaultContext
<> jsContext
<> cssContext
let
frontendContext = jsContext <> cssContext
where
cssContext = listField "css" innerContext genCSSItems
where
innerContext = urlField "url"
@ -56,9 +50,56 @@ main = hakyllWith config $ do
resources = filter (Glob.match p) $ frontendManifest Map.! entryPoint
forM resources $ load . fromFilePath . ("frontend/dist" </>) . dropDrive
tags <- buildTags "content/**" $ fromCapture "*.html"
match "content/**" $ do
compile $ do
getResourceBody
>>= loadAndApplyTemplate "templates/site-layout.html" context
pandocCompiler
>>= relativizeUrls
tagsRules tags $ \_tag posts -> do
route idRoute
compile $ do
let
ctx =
mconcat
[ listField "tags-nav" defaultContext (mapM (uncurry renderTagNav) $ tagsMap tags)
, listField "posts" postContext (postsSort =<< loadAll posts)
, frontendContext
, defaultContext
]
renderTagNav tag ids = do
let
navRoute
| tag == "index" = "/"
| otherwise = "/" <> tag <> ".html"
tagNavCtx =
mconcat
[ constField "tag" tag
, constField "route" navRoute
, listField "posts" (constField "tag" tag <> constField "route" navRoute <> postContext) (postsSort =<< mapM load ids)
]
makeItem (mempty :: String)
>>= loadAndApplyTemplate "templates/tag-nav.html" tagNavCtx
>>= relativizeUrls
postContext =
mconcat
[ field "identifier" (return . takeBaseName . toFilePath . itemIdentifier)
, defaultContext
]
postsSort :: [Item w] -> Compiler [Item w]
postsSort = sortOnM $ \Item{itemIdentifier} -> getMetadataField itemIdentifier "sort"
where
sortOnM :: forall m a b. (Monad m, Ord b) => (a -> m b) -> [a] -> m [a]
sortOnM f = fmap (map snd . List.sortOn fst) . mapM (\x -> (,x) <$> f x)
makeItem (mempty :: String)
>>= loadAndApplyTemplate "templates/tag.html" ctx
>>= loadAndApplyTemplate "templates/site-layout.html" ctx
>>= relativizeUrls
match "frontend/dist/wp-*/**" $ do

11
templates/tag-nav.html Normal file
View File

@ -0,0 +1,11 @@
<li>
<a href="$route$">$tag$</a>
<ul>
$for(posts)$
<li>
<a href="$route$#$identifier$">$title$</a>
</li>
$endfor$
</ul>
</li>

12
templates/tag.html Normal file
View File

@ -0,0 +1,12 @@
<nav>
<ul>
$for(tags-nav)$
$body$
$endfor$
</ul>
</nav>
$for(posts)$
<article id="$identifier$">
$body$
</article>
$endfor$