diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-08-03 17:43:40 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-08-03 17:43:40 +0200 |
commit | 52b67951f1e8a7f1af9b85d4ae8e7689d194574a (patch) | |
tree | 88076113c7020e8483e5f47afa618d6449034f7e /provider/posts/blog-rss.md | |
parent | 230688a0b842cf57b316a7ba62910ca387afbce7 (diff) | |
download | dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar.gz dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar.bz2 dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar.xz dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.zip |
Working prototype in hakyll
Diffstat (limited to 'provider/posts/blog-rss.md')
-rw-r--r-- | provider/posts/blog-rss.md | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/provider/posts/blog-rss.md b/provider/posts/blog-rss.md new file mode 100644 index 0000000..095ff56 --- /dev/null +++ b/provider/posts/blog-rss.md | |||
@@ -0,0 +1,43 @@ | |||
1 | --- | ||
2 | title: dirty-haskell.org´s rss feeds | ||
3 | published: 2015-03-29 | ||
4 | tags: Blog Software | ||
5 | --- | ||
6 | |||
7 | I extended the software suite inherited from [math.kleen.org](http://math.kleen.org) to include support for rss feeds. | ||
8 | The heart of the issue is a ~80 line haskell script I chose to call, in a bout of creativity, "generate-rss.hs". | ||
9 | The script uses the [feed](http://hackage.haskell.org/package/feed-0.3.9.2) package. | ||
10 | |||
11 | generate-rss.hs gets passed a title and a list of paths below ./lists to incorporate as items. | ||
12 | It generates an empty feed structure, adds title and a (hardcoded) base url for RSS metadata, and iterates over the given paths — generating for each path an item to be included in the finished feed. | ||
13 | This procedure makes use of a state monad (StateT (Feed, Maybe ClockTime) IO ()) to sequentially add items to the feed and keep track of the modification/change time of the newest path examined. | ||
14 | Each item carries a title, an url, a date, and contents as follows: | ||
15 | |||
16 | - The date used is the modification/change time of the path supplied as a command line argument at the beginning of the program (usually a symbolic link in ./lists) — as such it is the time the post was linked into the particular list we´re generating a RSS feed for (this was not a deliberate design choice but a side effect of the canonical implementation — it was later decided that this behaviour was in fact the one expected all along). | ||
17 | - The url is generated by following, recursively, the trail of symbolic links starting in ./lists, assuming the final target is indeed in ./posts, and forming the filename of that target into a (hopefully) functional url in a hardcoded fashion. | ||
18 | - The title is extracted from the markdown file using a function shamelessly copied from extract-title.hs (The author wrote that one too, after all). | ||
19 | - The contents are read into Pandoc and rendered into [AsciiDoc](http://en.wikipedia.org/wiki/AsciiDoc) format (it seemed convenient at the time). | ||
20 | |||
21 | Along the way two helper functions were introduced — if an implementation of those already exists in Prelude or somewhere else common please mail in a comment: | ||
22 | |||
23 | ~~~ {.haskell} | ||
24 | (<->) :: [(a -> b)] -> a -> [b] | ||
25 | [] <-> _ = [] | ||
26 | (f:fs) <-> x = (f x:fs <-> x) | ||
27 | |||
28 | (<-->) :: [(a -> a)] -> a -> a | ||
29 | [] <--> x = x | ||
30 | (f:fs) <--> x = fs <--> (f x) | ||
31 | ~~~ | ||
32 | |||
33 | ## Update ## | ||
34 | |||
35 | ~~~ {.haskell} | ||
36 | import Control.Applicative ((<*>), pure) | ||
37 | |||
38 | (<->) fs = (<*>) fs . pure | ||
39 | |||
40 | (<-->) = flip $ foldl (.) id | ||
41 | ~~~ | ||
42 | |||
43 | Thanks, viktor. | ||