diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-08-10 15:26:21 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-08-10 15:26:21 +0200 |
| commit | 859e07942e3a3b4074513627a60513f0fa624154 (patch) | |
| tree | ca68ef17ada97715dcbfb8db6da9f74435798ea0 /src/Main.hs | |
| parent | 1c5ef0a9c52a273eb1b54ac9b8c8e2642b5c7376 (diff) | |
| download | flevum-859e07942e3a3b4074513627a60513f0fa624154.tar.gz | |
Diffstat (limited to 'src/Main.hs')
| -rw-r--r-- | src/Main.hs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/Main.hs b/src/Main.hs index 61a44b5..7dff99a 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -4,7 +4,7 @@ module Main where import Control.Monad (forM) -import Data.List (isPrefixOf, isSuffixOf) +import Data.List (isPrefixOf, isSuffixOf, isInfixOf) import Data.Time.Format (TimeLocale(..)) import Hakyll.Core.Compiler ( Compiler @@ -53,10 +53,10 @@ import Hakyll.Web.Template.Context , boolField , constField , defaultContext + , field , listField , listFieldWith , dateFieldWith - , teaserField ) import Hakyll.Web.Template.List (recentFirst, sortRecentFirst) import System.FilePath @@ -174,10 +174,28 @@ localizedTimeLocale = TimeLocale , amPm = ("AM", "PM") } +-- Reads teaser metadata field and formats it as HTML. +teaserDescriptionField :: Context String +teaserDescriptionField = field "teaser" withItem + where + withItem item = + let itemIdentifier' = itemIdentifier item + in getMetadataField itemIdentifier' "teaser" + >>= withMetadataField itemIdentifier' + paragraphMap "" = "</p><p>" + paragraphMap paragraph = paragraph + withMetadataField _ (Just teaser) + | "<p>" `isInfixOf` teaser = pure teaser + | otherwise = pure $ "<p>" + <> unlines (paragraphMap <$> lines teaser) + <> "</p>" + withMetadataField itemIdentifier' Nothing = fail + $ "No teaser defined for " <> show itemIdentifier' + postCtx :: Tags -> Context String postCtx tags = dateFieldWith localizedTimeLocale "published" "%e. %B %Y" - <> teaserField "teaser" "content" + <> teaserDescriptionField <> flevumContext tags flevumContext :: Tags -> Context String |
