From b522150a3946634db6a099f3ba101e9f66266791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20van=20Br=C3=BCgge?= Date: Sat, 23 Mar 2024 00:35:08 +0000 Subject: [PATCH] Add atom feed --- src/Main.hs | 13 +++++++++++-- templates/atom.xml | 21 +++++++++++++++++++++ templates/shell.html | 9 ++++++--- 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 templates/atom.xml diff --git a/src/Main.hs b/src/Main.hs index a687934..f919a8f 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -77,9 +77,12 @@ getRendered _ = error "Could not find content key in object" buildRules :: Action () buildRules = do allPosts <- mapP buildPost =<< getDirectoryFiles "." ["articles//*.md"] - buildPostList Nothing allPosts + sortedPosts <- buildPostList Nothing allPosts + buildAtomFeed (take 15 sortedPosts) + let allTags = Set.toList $ foldr (Set.union . Set.fromList . tags) Set.empty allPosts void . forP allTags $ \tag -> buildPostList (Just (tag, "tags" tag)) (filter (elem tag . tags) allPosts) + copyStaticFiles buildPost :: FilePath -> Action Post @@ -96,7 +99,7 @@ buildPost srcPath = cacheAction ("build" :: T.Text, srcPath) $ do writeFile' (outputFolder T.unpack postUrl "index.html") . T.unpack $ rendered convert $ A.Object postData' -buildPostList :: Maybe (String, FilePath) -> [Post] -> Action () +buildPostList :: Maybe (String, FilePath) -> [Post] -> Action [Post] buildPostList tag posts = do let posts' = sortOn (Down . date) posts let postData = A.Object $ KM.fromList $ @@ -105,6 +108,12 @@ buildPostList tag posts = do ] <> maybe [] (\(t, _) -> [(fromText "tag", A.String (T.pack t))]) tag rendered <- getRendered <$> renderTemplates postData ["postList.html", "shell.html"] writeFile' (outputFolder <> maybe "" snd tag "index.html") . T.unpack $ rendered + pure posts' + +buildAtomFeed :: [Post] -> Action () +buildAtomFeed posts = do + rendered <- getRendered <$> renderTemplates (A.Object $ KM.fromList [(fromText "posts", A.toJSON posts)]) ["atom.xml"] + writeFile' (outputFolder "atom.xml") . T.unpack $ rendered copyStaticFiles :: Action () copyStaticFiles = do diff --git a/templates/atom.xml b/templates/atom.xml new file mode 100644 index 0000000..8ec7331 --- /dev/null +++ b/templates/atom.xml @@ -0,0 +1,21 @@ + + + + Programming & Proving + + {{updated}} + + Jan van Brügge + + urn:uuid:52dd550f-4e75-420d-a0a1-e501a1dec9fe + + {{#posts}} + + {{title}} + + https://jvanbruegge.github.io/blog/{{url}} + {{date}} + {{description}} + + {{/posts}} + diff --git a/templates/shell.html b/templates/shell.html index 648da74..62bf5ee 100644 --- a/templates/shell.html +++ b/templates/shell.html @@ -1,16 +1,18 @@ + - + Programming & Proving by Jan van Brügge + +
@@ -20,6 +22,7 @@