Added RSS module.
This commit is contained in:
parent
f47fd1a967
commit
1736710b9e
10 changed files with 158 additions and 68 deletions
5
data/templates/rss-item.xml
Normal file
5
data/templates/rss-item.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<item>
|
||||
<title>$title</title>
|
||||
<link>$absolute/$url</link>
|
||||
<description>$description</description>
|
||||
</item>
|
9
data/templates/rss.xml
Normal file
9
data/templates/rss.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>$title</title>
|
||||
<link>$absolute</link>
|
||||
<description>$description</description>
|
||||
$body
|
||||
</channel>
|
||||
</rss>
|
104
hakyll.cabal
104
hakyll.cabal
|
@ -1,56 +1,60 @@
|
|||
Name: hakyll
|
||||
Version: 1.4
|
||||
Name: hakyll
|
||||
Version: 1.4
|
||||
|
||||
Synopsis: A simple static site generator library.
|
||||
Description:
|
||||
A simple static site generator library, mainly aimed at
|
||||
creating blogs and brochure sites.
|
||||
Author: Jasper Van der Jeugt
|
||||
Maintainer: jaspervdj@gmail.com
|
||||
Homepage: http://jaspervdj.be/hakyll
|
||||
Bug-Reports: http://github.com/jaspervdj/Hakyll/issues
|
||||
License: BSD3
|
||||
License-File: LICENSE
|
||||
Category: Text
|
||||
Cabal-Version: >= 1.6
|
||||
Synopsis: A simple static site generator library.
|
||||
Description: A simple static site generator library, mainly aimed at
|
||||
creating blogs and brochure sites.
|
||||
Author: Jasper Van der Jeugt
|
||||
Maintainer: jaspervdj@gmail.com
|
||||
Homepage: http://jaspervdj.be/hakyll
|
||||
Bug-Reports: http://github.com/jaspervdj/Hakyll/issues
|
||||
License: BSD3
|
||||
License-File: LICENSE
|
||||
Category: Text
|
||||
Cabal-Version: >= 1.6
|
||||
Data-Dir: data
|
||||
Data-Files: templates/rss.xml
|
||||
templates/rss-item.xml
|
||||
|
||||
build-type: Simple
|
||||
build-type: Simple
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
location: git://github.com/jaspervdj/Hakyll.git
|
||||
type: git
|
||||
location: git://github.com/jaspervdj/Hakyll.git
|
||||
|
||||
library
|
||||
ghc-options: -Wall
|
||||
hs-source-dirs: src/
|
||||
build-depends: base >= 4 && < 5,
|
||||
filepath >= 1.1,
|
||||
directory >= 1,
|
||||
containers >= 0.1,
|
||||
pandoc >= 1,
|
||||
regex-base >= 0.83,
|
||||
regex-tdfa >= 0.92,
|
||||
network >= 2,
|
||||
mtl >= 1.1,
|
||||
old-locale >= 1,
|
||||
old-time >= 1,
|
||||
time >= 1,
|
||||
binary >= 0.5,
|
||||
QuickCheck >= 2
|
||||
exposed-modules: Network.Hakyll.SimpleServer
|
||||
Text.Hakyll
|
||||
Text.Hakyll.Context
|
||||
Text.Hakyll.File
|
||||
Text.Hakyll.Hakyll
|
||||
Text.Hakyll.Regex
|
||||
Text.Hakyll.Render
|
||||
Text.Hakyll.RenderAction
|
||||
Text.Hakyll.Renderables
|
||||
Text.Hakyll.Paginate
|
||||
Text.Hakyll.Util
|
||||
Text.Hakyll.Tags
|
||||
Text.Hakyll.Internal.Cache
|
||||
Text.Hakyll.Internal.CompressCss
|
||||
Text.Hakyll.Internal.Page
|
||||
Text.Hakyll.Internal.Render
|
||||
Text.Hakyll.Internal.Template
|
||||
ghc-options: -Wall
|
||||
hs-source-dirs: src
|
||||
build-depends: base >= 4 && < 5,
|
||||
filepath >= 1.1,
|
||||
directory >= 1,
|
||||
containers >= 0.1,
|
||||
pandoc >= 1,
|
||||
regex-base >= 0.83,
|
||||
regex-tdfa >= 0.92,
|
||||
network >= 2,
|
||||
mtl >= 1.1,
|
||||
old-locale >= 1,
|
||||
old-time >= 1,
|
||||
time >= 1,
|
||||
binary >= 0.5,
|
||||
QuickCheck >= 2
|
||||
exposed-modules: Network.Hakyll.SimpleServer
|
||||
Text.Hakyll
|
||||
Text.Hakyll.Context
|
||||
Text.Hakyll.File
|
||||
Text.Hakyll.Hakyll
|
||||
Text.Hakyll.Regex
|
||||
Text.Hakyll.Render
|
||||
Text.Hakyll.RenderAction
|
||||
Text.Hakyll.Renderables
|
||||
Text.Hakyll.Paginate
|
||||
Text.Hakyll.Util
|
||||
Text.Hakyll.Tags
|
||||
Text.Hakyll.Rss
|
||||
Text.Hakyll.Internal.Cache
|
||||
Text.Hakyll.Internal.CompressCss
|
||||
Text.Hakyll.Internal.Page
|
||||
Text.Hakyll.Internal.Render
|
||||
Text.Hakyll.Internal.Template
|
||||
other-modules: Paths_hakyll
|
||||
|
|
|
@ -28,16 +28,23 @@ import Text.Hakyll.File
|
|||
-- | The default hakyll configuration.
|
||||
defaultHakyllConfiguration :: HakyllConfiguration
|
||||
defaultHakyllConfiguration = HakyllConfiguration
|
||||
{ additionalContext = M.empty
|
||||
, siteDirectory = "_site"
|
||||
, cacheDirectory = "_cache"
|
||||
, enableIndexUrl = False
|
||||
, previewPollDelay = 1000000
|
||||
{ absoluteUrl = ""
|
||||
, additionalContext = M.empty
|
||||
, siteDirectory = "_site"
|
||||
, cacheDirectory = "_cache"
|
||||
, enableIndexUrl = False
|
||||
, previewPollDelay = 1000000
|
||||
}
|
||||
|
||||
-- | Main function to run Hakyll with the default configuration.
|
||||
hakyll :: Hakyll () -> IO ()
|
||||
hakyll = hakyllWithConfiguration defaultHakyllConfiguration
|
||||
-- | Main function to run Hakyll with the default configuration. The
|
||||
-- absolute URL is only used in certain cases, for example RSS feeds et
|
||||
-- cetera.
|
||||
hakyll :: String -- ^ Absolute URL of your site. Used in certain cases.
|
||||
-> Hakyll () -- ^ You code.
|
||||
-> IO ()
|
||||
hakyll absolute = hakyllWithConfiguration configuration
|
||||
where
|
||||
configuration = defaultHakyllConfiguration { absoluteUrl = absolute }
|
||||
|
||||
-- | Main function to run hakyll with a custom configuration.
|
||||
hakyllWithConfiguration :: HakyllConfiguration -> Hakyll () -> IO ()
|
||||
|
|
|
@ -3,26 +3,30 @@ module Text.Hakyll.Hakyll
|
|||
( HakyllConfiguration (..)
|
||||
, Hakyll
|
||||
, askHakyll
|
||||
, getAdditionalContext
|
||||
) where
|
||||
|
||||
import Control.Monad.Reader (ReaderT, ask)
|
||||
import Control.Monad (liftM)
|
||||
import qualified Data.Map as M
|
||||
|
||||
import Text.Hakyll.Context (Context)
|
||||
|
||||
-- | Hakyll global configuration type.
|
||||
data HakyllConfiguration = HakyllConfiguration
|
||||
{ -- | An additional context to use when rendering. This additional context
|
||||
{ -- | Absolute URL of the site.
|
||||
absoluteUrl :: String
|
||||
, -- | An additional context to use when rendering. This additional context
|
||||
-- is used globally.
|
||||
additionalContext :: Context
|
||||
, -- | Directory where the site is placed.
|
||||
siteDirectory :: FilePath
|
||||
siteDirectory :: FilePath
|
||||
, -- | Directory for cache files.
|
||||
cacheDirectory :: FilePath
|
||||
cacheDirectory :: FilePath
|
||||
, -- | Enable index links.
|
||||
enableIndexUrl :: Bool
|
||||
enableIndexUrl :: Bool
|
||||
, -- | Delay between polls in preview mode.
|
||||
previewPollDelay :: Int
|
||||
previewPollDelay :: Int
|
||||
}
|
||||
|
||||
-- | Our custom monad stack.
|
||||
|
@ -39,3 +43,8 @@ type Hakyll = ReaderT HakyllConfiguration IO
|
|||
--
|
||||
askHakyll :: (HakyllConfiguration -> a) -> Hakyll a
|
||||
askHakyll = flip liftM ask
|
||||
|
||||
getAdditionalContext :: HakyllConfiguration -> Context
|
||||
getAdditionalContext configuration =
|
||||
M.insert "absolute" (absoluteUrl configuration)
|
||||
(additionalContext configuration)
|
||||
|
|
|
@ -33,7 +33,7 @@ pureRenderWith manipulation template context =
|
|||
-- chains and such.
|
||||
writePage :: RenderAction Context ()
|
||||
writePage = createRenderAction $ \initialContext -> do
|
||||
additionalContext' <- askHakyll additionalContext
|
||||
additionalContext' <- askHakyll getAdditionalContext
|
||||
let url = fromMaybe (error "No url defined at write time.")
|
||||
(M.lookup "url" initialContext)
|
||||
body = fromMaybe "" (M.lookup "body" initialContext)
|
||||
|
|
|
@ -56,7 +56,8 @@ createManipulationAction :: ContextManipulation -> RenderAction Context Context
|
|||
createManipulationAction = createRenderAction . (return .)
|
||||
|
||||
chain :: [RenderAction a a] -> RenderAction a a
|
||||
chain = foldl1 (>>>)
|
||||
chain [] = id
|
||||
chain list@(_:_) = foldl1 (>>>) list
|
||||
|
||||
runRenderAction :: RenderAction () a -> Hakyll a
|
||||
runRenderAction action = actionFunction action ()
|
||||
|
|
|
@ -38,7 +38,7 @@ createCustomPage url dependencies association = RenderAction
|
|||
mtuple (a, b) = b >>= \b' -> return (a, b')
|
||||
toHakyllString = second (either return runRenderAction)
|
||||
assoc' = mapM (mtuple . toHakyllString) $ ("url", Left url) : association
|
||||
dataDependencies = (map snd association) >>= getDependencies
|
||||
dataDependencies = map snd association >>= getDependencies
|
||||
getDependencies (Left _) = []
|
||||
getDependencies (Right x) = actionDependencies x
|
||||
|
||||
|
|
57
src/Text/Hakyll/Rss.hs
Normal file
57
src/Text/Hakyll/Rss.hs
Normal file
|
@ -0,0 +1,57 @@
|
|||
-- | A Module that allows easy rendering of RSS feeds.
|
||||
module Text.Hakyll.Rss
|
||||
( RssConfiguration (..)
|
||||
, renderRss
|
||||
, renderRssWith
|
||||
) where
|
||||
|
||||
import Control.Arrow ((>>>), second)
|
||||
import Control.Monad.Reader (liftIO)
|
||||
|
||||
import Text.Hakyll.Context (ContextManipulation)
|
||||
import Text.Hakyll.Hakyll (Hakyll)
|
||||
import Text.Hakyll.Render (render, renderChain)
|
||||
import Text.Hakyll.Renderables (createListingWith)
|
||||
import Text.Hakyll.RenderAction (Renderable)
|
||||
|
||||
import Paths_hakyll
|
||||
|
||||
data RssConfiguration = RssConfiguration
|
||||
{ -- | Url of the RSS feed (relative to site root). For example, @rss.xml@.
|
||||
rssUrl :: String
|
||||
, -- | Title of the RSS feed.
|
||||
rssTitle :: String
|
||||
, -- | Description of the RSS feed.
|
||||
rssDescription :: String
|
||||
}
|
||||
|
||||
createRssWith :: ContextManipulation
|
||||
-> RssConfiguration
|
||||
-> [Renderable]
|
||||
-> FilePath
|
||||
-> FilePath
|
||||
-> Renderable
|
||||
createRssWith manipulation configuration renderables template itemTemplate =
|
||||
listing >>> render template
|
||||
where
|
||||
listing = createListingWith manipulation (rssUrl configuration) itemTemplate
|
||||
renderables additional
|
||||
|
||||
additional = map (second $ Left . ($ configuration))
|
||||
[ ("title", rssTitle)
|
||||
, ("description", rssDescription)
|
||||
]
|
||||
|
||||
renderRss :: RssConfiguration -> [Renderable] -> Hakyll ()
|
||||
renderRss = renderRssWith id
|
||||
|
||||
renderRssWith :: ContextManipulation
|
||||
-> RssConfiguration
|
||||
-> [Renderable]
|
||||
-> Hakyll ()
|
||||
renderRssWith manipulation configuration renderables = do
|
||||
template <- liftIO $ getDataFileName "templates/rss.xml"
|
||||
itemTemplate <- liftIO $ getDataFileName "templates/rss-item.xml"
|
||||
let renderRssWith' = createRssWith manipulation configuration
|
||||
renderables template itemTemplate
|
||||
renderChain [] renderRssWith'
|
|
@ -18,8 +18,6 @@
|
|||
-- is to place pages in subdirectories.
|
||||
--
|
||||
-- An example, the page @posts\/coding\/2010-01-28-hakyll-categories.markdown@
|
||||
-- would be placed under the `coding` category.
|
||||
--
|
||||
-- Tags or categories are read using the @readTagMap@ and @readCategoryMap@
|
||||
-- functions. Because categories are implemented using tags - categories can
|
||||
-- be seen as tags, with the restriction that a page can only have one
|
||||
|
|
Loading…
Reference in a new issue