Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few changes to 05-snapshots... to complete the instructions. #941

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions web/tutorials/05-snapshots-feeds.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ renderRss :: FeedConfiguration
```

As you can see, they have exactly the same signature: we're going to use
`renderAtom` in this tutorial, but it's trivial to change this to an RSS feed.
`renderAtom` in this tutorial, but it's trivial to change this to an RSS feed.
We are going to consume this function from the context of the `create` combinator,
which lets us define our own rules to register against the `hakyll` combinator:

```haskell
create ["atom.xml"] $ do
makeFeed :: Rules ()
makeFeed = create ["atom.xml"] $ do
route idRoute
compile $ do
let feedCtx = postCtx `mappend`
Expand Down Expand Up @@ -116,7 +119,7 @@ Including the post body
With this modification, we can update our Atom code. Instead of loading the
compiled posts, we just load their content (i.e. the snapshot we just took).

We update the `Context` to map `$description$` to the post body, and we're done!
We update the `Context` to map `$description$` to the post body:

```haskell
create ["atom.xml"] $ do
Expand All @@ -127,3 +130,19 @@ create ["atom.xml"] $ do
loadAllSnapshots "posts/*" "content"
renderAtom myFeedConfiguration feedCtx posts
```

We're almost done; we just need to register our newly defined rules against the `hakyll`
combinator:

```haskell
match "posts/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
makeFeed
```

Now whenever we (re)build our site, a corresponding `rss.xml` or `atom.xml` file is generated.