Skip to content

Commit b5ef8ed

Browse files
authored
add rss/atom feeds (#63)
1 parent 7d17841 commit b5ef8ed

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

app/Main.hs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
{-# LANGUAGE OverloadedStrings #-}
22

33
import Hakyll
4-
import Text.Pandoc.Highlighting
5-
import Text.Pandoc.Options (WriterOptions (..))
6-
import Prelude
4+
import Prelude
5+
import Text.Pandoc.Highlighting
6+
import Text.Pandoc.Options (WriterOptions (..))
77

88
main :: IO ()
9-
main = hakyll $ do
10-
match "images/*" $ do
9+
main = hakyll do
10+
match "images/*" do
1111
route idRoute
1212
compile copyFileCompiler
1313

14-
match "files/*" $ do
14+
match "files/*" do
1515
route idRoute
1616
compile copyFileCompiler
1717

18-
match "css/*" $ do
18+
match "css/*" do
1919
route idRoute
2020
compile compressCssCompiler
2121

22-
match "CNAME" $ do
22+
match "CNAME" do
2323
route idRoute
2424
compile copyFileCompiler
2525

26-
match (fromList ["about.rst", "contact.markdown"]) $ do
26+
match (fromList ["about.rst", "contact.markdown"]) do
2727
route $ setExtension "html"
2828
compile $ pandocCompiler'
2929
>>= loadAndApplyTemplate "templates/default.html" defaultContext
3030
>>= relativizeUrls
3131

32-
match "cv.html" $ do
32+
match "cv.html" do
3333
route idRoute
3434
compile $ getResourceBody
3535
>>= loadAndApplyTemplate "templates/default.html" defaultContext
3636
>>= relativizeUrls
3737

38-
match "posts/*" $ do
38+
match "posts/*" do
3939
route $ setExtension "html"
4040
compile $ pandocCompiler'
4141
>>= loadAndApplyTemplate "templates/post.html" postCtx
42+
>>= saveSnapshot "content"
4243
>>= loadAndApplyTemplate "templates/default.html" postCtx
4344
>>= relativizeUrls
4445

45-
create ["archive.html"] $ do
46+
create ["archive.html"] do
4647
route idRoute
47-
compile $ do
48+
compile do
4849
posts <- recentFirst =<< loadAll "posts/*"
4950
let archiveCtx =
5051
listField "posts" postCtx (return posts) `mappend`
@@ -56,15 +57,23 @@ main = hakyll $ do
5657
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
5758
>>= relativizeUrls
5859

59-
create ["css/syntax.css"] $ do
60+
create ["css/syntax.css"] do
6061
route idRoute
61-
compile $ do
62+
compile do
6263
makeItem $ styleToCss pandocCodeStyle
6364

65+
create ["atom.xml"] do
66+
route idRoute
67+
compile $ mkFeed renderAtom
68+
69+
create ["rss.xml"] do
70+
route idRoute
71+
compile $ mkFeed renderRss
6472

65-
match "index.html" $ do
73+
74+
match "index.html" do
6675
route idRoute
67-
compile $ do
76+
compile do
6877
posts <- recentFirst =<< loadAll "posts/*"
6978
let indexCtx =
7079
listField "posts" postCtx (return posts) `mappend`
@@ -95,3 +104,19 @@ pandocCompiler' =
95104
defaultHakyllWriterOptions
96105
{ writerHighlightStyle = Just pandocCodeStyle
97106
}
107+
108+
type FeedRenderer = FeedConfiguration -> Context String -> [Item String] -> Compiler (Item String)
109+
110+
mkFeed :: FeedRenderer -> Compiler (Item String)
111+
mkFeed render = do
112+
let feedCtx = postCtx `mappend` bodyField "description"
113+
feedConfiguration = FeedConfiguration
114+
{ feedTitle = "mrcjkb"
115+
, feedDescription = "My Hakyll site"
116+
, feedAuthorName = "Marc Jakobi"
117+
, feedAuthorEmail = "[email protected]"
118+
, feedRoot = "mrcjkb.dev"
119+
}
120+
posts <- fmap (take 10) . recentFirst =<< loadAllSnapshots "posts/*" "content"
121+
render feedConfiguration feedCtx posts
122+

posts/2023-06-06-luarocks-test.markdown

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class: container
1010
<a href="https://github.com/nvim-neorocks/nvim-busted-action">
1111
<img src="https://avatars.githubusercontent.com/u/124081866?s=400&u=0da379a468d46456477a1f68048b020cf7a99f34&v=4" alt="nvim-busted-action">
1212
</a>
13-
<h2>🌒</h>
1413
</div>
1514
<!-- markdownlint-restore -->
1615

templates/default.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<a href="/contact.html">Contact</a>
2121
<a href="/cv.html">CV</a>
2222
<a href="/archive.html">Archive</a>
23+
<a href="/rss.xml">RSS feed</a>
24+
<a href="/atom.xml">Atom feed</a>
2325
</nav>
2426
</div>
2527
</header>

0 commit comments

Comments
 (0)