3 import Data.Default (def)
4 import Data.List qualified as List
5 import Data.Map.Strict qualified as Map
6 import Data.Time qualified as Time
9 import Text.Atom.Feed qualified as Atom
10 import Text.Blaze.Html5 ((!))
11 import Text.Blaze.Html5 qualified as H
12 import Text.Pandoc (runPure)
13 import Text.Pandoc.Writers (writeHtml5String)
23 mkFeed :: Model -> Filter -> Atom.Feed
24 mkFeed model filt@Filter{..} =
26 (absoluteLink model (Left ""))
27 --(absoluteLink model (Right (RouteFilterAtom filt)))
28 (Atom.TextString [fmt|{orgName} - {feedTitle filt}|])
29 (atomTime . List.maximum . mapMaybe (metaUpdated . pageMeta) . Map.elems $ modelPosts model)
34 { Atom.personName = orgName
35 , Atom.personEmail = Just [fmt|contact@{domainName}|]
37 , --, Atom.feedIcon = Just $ absoluteLink model (Left "static/img/feedIcon.png")
40 | post@(_slug, Page{..}) <- filterPosts model filt
41 , isJust $ metaUpdated pageMeta
43 , Atom.feedLinks = one $ Atom.nullLink [fmt|https://{domainName}|]
44 , Atom.feedCategories = Atom.newCategory . unTag <$> maybeToList filterTag
47 atomTime = toText . Time.formatTime Time.defaultTimeLocale "%Y-%m-%d"
48 feedEntry (pageName, Page{..}) =
51 (Atom.TextString $ metaTitle pageMeta)
52 (atomTime (fromMaybe (error "Pages without date") $ metaUpdated pageMeta))
54 { Atom.entryCategories = Atom.newCategory . unTag <$> metaTags pageMeta
55 , Atom.entryLinks = one $ Atom.nullLink pageLink
56 , Atom.entrySummary = Atom.TextString . markdownText <$> metaSummary pageMeta
60 either (error . show) id $
61 runPure $ writeHtml5String def pageDoc
64 pageLink = absoluteLink model $ Right $ RoutePage pageName
66 feedList :: Model -> H.Html
68 H.h2 ! classes ["text-blue-800", "text-xl"] $ "Feed of all posts"
69 H.table ! classes ["my-2", "table-fixed", "w-full"] $
72 forM_ (Nothing : (Just <$> [minBound ..])) $ \lang ->
73 cell $ mkLink lang Nothing
74 H.h2 ! classes ["text-blue-800", "text-xl"] $ "Feeds by tag"
75 H.table ! classes ["my-2", "table-fixed", "w-full"] $ do
76 forM_ (allTags model) $ \tag -> H.tr $ do
77 icell (renderTag model True tag)
78 forM_ (Nothing : (Just <$> [minBound ..])) $ \lang ->
79 cell $ mkLink lang (Just tag)
89 ! hrefRoute model (RouteFilterAtom (Filter lang tag))
90 $ maybe "Any" langText lang
91 cell = H.td ! classes ["text-right", "w-1/4"]
92 icell = H.td ! classes ["text-left", "w-1/4"]