From 859e07942e3a3b4074513627a60513f0fa624154 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 10 Aug 2026 15:26:21 +0200 Subject: Remove teasers that repeat the content --- src/Main.hs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/Main.hs') 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 "" = "

" + paragraphMap paragraph = paragraph + withMetadataField _ (Just teaser) + | "

" `isInfixOf` teaser = pure teaser + | otherwise = pure $ "

" + <> unlines (paragraphMap <$> lines teaser) + <> "

" + 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 -- cgit v1.2.3