on master help sign in
Added RSS module.
commit1736710b9e0685f3c3503519e38e9744ba9bb144 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSat 6 Mar 2010, 15:39 (17 years ago) parentf47fd1a
10 files changed+158−68
data/templates/rss-item.xml+5 data/templates/rss.xml+9 hakyll.cabal+54−50 src/Text/Hakyll.hs+15−8 src/Text/Hakyll/Hakyll.hs+14−5 src/Text/Hakyll/Internal/Render.hs+1−1 src/Text/Hakyll/RenderAction.hs+2−1 src/Text/Hakyll/Renderables.hs+1−1 src/Text/Hakyll/Rss.hs+57 src/Text/Hakyll/Tags.hs−2
data/templates/rss-item.xmlnew file+5
@@ -0,0 +1,5 @@
1+<item>
2+ <title>$title</title>
3+ <link>$absolute/$url</link>
4+ <description>$description</description>
5+</item>
data/templates/rss.xmlnew file+9
@@ -0,0 +1,9 @@
1+<?xml version="1.0" ?>
2+<rss version="2.0">
3+ <channel>
4+ <title>$title</title>
5+ <link>$absolute</link>
6+ <description>$description</description>
7+ $body
8+ </channel>
9+</rss>
hakyll.cabal+54−50
@@ -1,56 +1,60 @@
1−Name: hakyll
2−Version: 1.4
1+Name: hakyll
2+Version: 1.4
33
4−Synopsis: A simple static site generator library.
5−Description:
6− A simple static site generator library, mainly aimed at
7− creating blogs and brochure sites.
8−Author: Jasper Van der Jeugt
9−Maintainer: jaspervdj@gmail.com
10−Homepage: http://jaspervdj.be/hakyll
11−Bug-Reports: http://github.com/jaspervdj/Hakyll/issues
12−License: BSD3
13−License-File: LICENSE
14−Category: Text
15−Cabal-Version: >= 1.6
4+Synopsis: A simple static site generator library.
5+Description: A simple static site generator library, mainly aimed at
6+ creating blogs and brochure sites.
7+Author: Jasper Van der Jeugt
8+Maintainer: jaspervdj@gmail.com
9+Homepage: http://jaspervdj.be/hakyll
10+Bug-Reports: http://github.com/jaspervdj/Hakyll/issues
11+License: BSD3
12+License-File: LICENSE
13+Category: Text
14+Cabal-Version: >= 1.6
15+Data-Dir: data
16+Data-Files: templates/rss.xml
17+ templates/rss-item.xml
1618
17−build-type: Simple
19+build-type: Simple
1820
1921source-repository head
20− type: git
21− location: git://github.com/jaspervdj/Hakyll.git
22+ type: git
23+ location: git://github.com/jaspervdj/Hakyll.git
2224
2325library
24− ghc-options: -Wall
25− hs-source-dirs: src/
26− build-depends: base >= 4 && < 5,
27− filepath >= 1.1,
28− directory >= 1,
29− containers >= 0.1,
30− pandoc >= 1,
31− regex-base >= 0.83,
32− regex-tdfa >= 0.92,
33− network >= 2,
34− mtl >= 1.1,
35− old-locale >= 1,
36− old-time >= 1,
37− time >= 1,
38− binary >= 0.5,
39− QuickCheck >= 2
40− exposed-modules: Network.Hakyll.SimpleServer
41− Text.Hakyll
42− Text.Hakyll.Context
43− Text.Hakyll.File
44− Text.Hakyll.Hakyll
45− Text.Hakyll.Regex
46− Text.Hakyll.Render
47− Text.Hakyll.RenderAction
48− Text.Hakyll.Renderables
49− Text.Hakyll.Paginate
50− Text.Hakyll.Util
51− Text.Hakyll.Tags
52− Text.Hakyll.Internal.Cache
53− Text.Hakyll.Internal.CompressCss
54− Text.Hakyll.Internal.Page
55− Text.Hakyll.Internal.Render
56− Text.Hakyll.Internal.Template
26+ ghc-options: -Wall
27+ hs-source-dirs: src
28+ build-depends: base >= 4 && < 5,
29+ filepath >= 1.1,
30+ directory >= 1,
31+ containers >= 0.1,
32+ pandoc >= 1,
33+ regex-base >= 0.83,
34+ regex-tdfa >= 0.92,
35+ network >= 2,
36+ mtl >= 1.1,
37+ old-locale >= 1,
38+ old-time >= 1,
39+ time >= 1,
40+ binary >= 0.5,
41+ QuickCheck >= 2
42+ exposed-modules: Network.Hakyll.SimpleServer
43+ Text.Hakyll
44+ Text.Hakyll.Context
45+ Text.Hakyll.File
46+ Text.Hakyll.Hakyll
47+ Text.Hakyll.Regex
48+ Text.Hakyll.Render
49+ Text.Hakyll.RenderAction
50+ Text.Hakyll.Renderables
51+ Text.Hakyll.Paginate
52+ Text.Hakyll.Util
53+ Text.Hakyll.Tags
54+ Text.Hakyll.Rss
55+ Text.Hakyll.Internal.Cache
56+ Text.Hakyll.Internal.CompressCss
57+ Text.Hakyll.Internal.Page
58+ Text.Hakyll.Internal.Render
59+ Text.Hakyll.Internal.Template
60+ other-modules: Paths_hakyll
src/Text/Hakyll.hs+15−8
@@ -28,16 +28,23 @@ import Text.Hakyll.File
2828-- | The default hakyll configuration.
2929defaultHakyllConfiguration :: HakyllConfiguration
3030defaultHakyllConfiguration = HakyllConfiguration
31− { additionalContext = M.empty
32− , siteDirectory = "_site"
33− , cacheDirectory = "_cache"
34− , enableIndexUrl = False
35− , previewPollDelay = 1000000
31+ { absoluteUrl = ""
32+ , additionalContext = M.empty
33+ , siteDirectory = "_site"
34+ , cacheDirectory = "_cache"
35+ , enableIndexUrl = False
36+ , previewPollDelay = 1000000
3637 }
3738
38−-- | Main function to run Hakyll with the default configuration.
39−hakyll :: Hakyll () -> IO ()
40−hakyll = hakyllWithConfiguration defaultHakyllConfiguration
39+-- | Main function to run Hakyll with the default configuration. The
40+-- absolute URL is only used in certain cases, for example RSS feeds et
41+-- cetera.
42+hakyll :: String -- ^ Absolute URL of your site. Used in certain cases.
43+ -> Hakyll () -- ^ You code.
44+ -> IO ()
45+hakyll absolute = hakyllWithConfiguration configuration
46+ where
47+ configuration = defaultHakyllConfiguration { absoluteUrl = absolute }
4148
4249-- | Main function to run hakyll with a custom configuration.
4350hakyllWithConfiguration :: HakyllConfiguration -> Hakyll () -> IO ()
src/Text/Hakyll/Hakyll.hs+14−5
@@ -3,26 +3,30 @@ module Text.Hakyll.Hakyll
33 ( HakyllConfiguration (..)
44 , Hakyll
55 , askHakyll
6+ , getAdditionalContext
67 ) where
78
89import Control.Monad.Reader (ReaderT, ask)
910import Control.Monad (liftM)
11+import qualified Data.Map as M
1012
1113import Text.Hakyll.Context (Context)
1214
1315-- | Hakyll global configuration type.
1416data HakyllConfiguration = HakyllConfiguration
15− { -- | An additional context to use when rendering. This additional context
17+ { -- | Absolute URL of the site.
18+ absoluteUrl :: String
19+ , -- | An additional context to use when rendering. This additional context
1620 -- is used globally.
1721 additionalContext :: Context
1822 , -- | Directory where the site is placed.
19− siteDirectory :: FilePath
23+ siteDirectory :: FilePath
2024 , -- | Directory for cache files.
21− cacheDirectory :: FilePath
25+ cacheDirectory :: FilePath
2226 , -- | Enable index links.
23− enableIndexUrl :: Bool
27+ enableIndexUrl :: Bool
2428 , -- | Delay between polls in preview mode.
25− previewPollDelay :: Int
29+ previewPollDelay :: Int
2630 }
2731
2832-- | Our custom monad stack.
@@ -39,3 +43,8 @@ type Hakyll = ReaderT HakyllConfiguration IO
3943--
4044askHakyll :: (HakyllConfiguration -> a) -> Hakyll a
4145askHakyll = flip liftM ask
46+
47+getAdditionalContext :: HakyllConfiguration -> Context
48+getAdditionalContext configuration =
49+ M.insert "absolute" (absoluteUrl configuration)
50+ (additionalContext configuration)
src/Text/Hakyll/Internal/Render.hs+1−1
@@ -33,7 +33,7 @@ pureRenderWith manipulation template context =
3333-- chains and such.
3434writePage :: RenderAction Context ()
3535writePage = createRenderAction $ \initialContext -> do
36− additionalContext' <- askHakyll additionalContext
36+ additionalContext' <- askHakyll getAdditionalContext
3737 let url = fromMaybe (error "No url defined at write time.")
3838 (M.lookup "url" initialContext)
3939 body = fromMaybe "" (M.lookup "body" initialContext)
src/Text/Hakyll/RenderAction.hs+2−1
@@ -56,7 +56,8 @@ createManipulationAction :: ContextManipulation -> RenderAction Context Context
5656createManipulationAction = createRenderAction . (return .)
5757
5858chain :: [RenderAction a a] -> RenderAction a a
59−chain = foldl1 (>>>)
59+chain [] = id
60+chain list@(_:_) = foldl1 (>>>) list
6061
6162runRenderAction :: RenderAction () a -> Hakyll a
6263runRenderAction action = actionFunction action ()
src/Text/Hakyll/Renderables.hs+1−1
@@ -38,7 +38,7 @@ createCustomPage url dependencies association = RenderAction
3838 mtuple (a, b) = b >>= \b' -> return (a, b')
3939 toHakyllString = second (either return runRenderAction)
4040 assoc' = mapM (mtuple . toHakyllString) $ ("url", Left url) : association
41− dataDependencies = (map snd association) >>= getDependencies
41+ dataDependencies = map snd association >>= getDependencies
4242 getDependencies (Left _) = []
4343 getDependencies (Right x) = actionDependencies x
4444
src/Text/Hakyll/Rss.hsnew file+57
@@ -0,0 +1,57 @@
1+-- | A Module that allows easy rendering of RSS feeds.
2+module Text.Hakyll.Rss
3+ ( RssConfiguration (..)
4+ , renderRss
5+ , renderRssWith
6+ ) where
7+
8+import Control.Arrow ((>>>), second)
9+import Control.Monad.Reader (liftIO)
10+
11+import Text.Hakyll.Context (ContextManipulation)
12+import Text.Hakyll.Hakyll (Hakyll)
13+import Text.Hakyll.Render (render, renderChain)
14+import Text.Hakyll.Renderables (createListingWith)
15+import Text.Hakyll.RenderAction (Renderable)
16+
17+import Paths_hakyll
18+
19+data RssConfiguration = RssConfiguration
20+ { -- | Url of the RSS feed (relative to site root). For example, @rss.xml@.
21+ rssUrl :: String
22+ , -- | Title of the RSS feed.
23+ rssTitle :: String
24+ , -- | Description of the RSS feed.
25+ rssDescription :: String
26+ }
27+
28+createRssWith :: ContextManipulation
29+ -> RssConfiguration
30+ -> [Renderable]
31+ -> FilePath
32+ -> FilePath
33+ -> Renderable
34+createRssWith manipulation configuration renderables template itemTemplate =
35+ listing >>> render template
36+ where
37+ listing = createListingWith manipulation (rssUrl configuration) itemTemplate
38+ renderables additional
39+
40+ additional = map (second $ Left . ($ configuration))
41+ [ ("title", rssTitle)
42+ , ("description", rssDescription)
43+ ]
44+
45+renderRss :: RssConfiguration -> [Renderable] -> Hakyll ()
46+renderRss = renderRssWith id
47+
48+renderRssWith :: ContextManipulation
49+ -> RssConfiguration
50+ -> [Renderable]
51+ -> Hakyll ()
52+renderRssWith manipulation configuration renderables = do
53+ template <- liftIO $ getDataFileName "templates/rss.xml"
54+ itemTemplate <- liftIO $ getDataFileName "templates/rss-item.xml"
55+ let renderRssWith' = createRssWith manipulation configuration
56+ renderables template itemTemplate
57+ renderChain [] renderRssWith'
src/Text/Hakyll/Tags.hs−2
@@ -18,8 +18,6 @@
1818-- is to place pages in subdirectories.
1919--
2020-- An example, the page @posts\/coding\/2010-01-28-hakyll-categories.markdown@
21−-- would be placed under the `coding` category.
22−--
2321-- Tags or categories are read using the @readTagMap@ and @readCategoryMap@
2422-- functions. Because categories are implemented using tags - categories can
2523-- be seen as tags, with the restriction that a page can only have one