Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

isolate the sitemap creation in its own function

  • Loading branch information...
commit 71cad6a56d020664d74902f9c2a98982684786c1 1 parent 31303b8
@Geal authored
Showing with 14 additions and 20 deletions.
  1. +14 −19 site.hs
  2. +0 −1  templates/sitemap_element.xml
View
33 site.hs
@@ -1,6 +1,6 @@
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
-import Control.Applicative ((<$>))
+import Control.Applicative ((<$>), (<*>))
import Data.Monoid (mappend)
import Data.Time.Clock
import Data.Time.Clock.POSIX
@@ -90,13 +90,8 @@ main = hakyllWith myConfiguration $ do
match "templates/*" $ compile templateCompiler
- create ["sitemap.xml"] $ do
- route idRoute
- compile $ do
- let urlCtx = field "urls" (\_ -> urlList) `mappend` defaultContext
- makeItem ""
- >>= loadAndApplyTemplate "templates/sitemap.xml" urlCtx
+ createSitemap $ (++) <$> (loadAll "blog/*.markdown") <*> (loadAll "script/*")
--------------------------------------------------------------------------------
postCtx :: Context String
@@ -124,32 +119,32 @@ removeHtmlPrefix x = case (reverse . take 5 . reverse) $ x of
".html" -> reverse . snd . splitAt 5 . reverse $ x
_ -> x
-------------------------------------------------------------------------------
-urlList :: Compiler String
-urlList = do
- --posts <- loadAll "blog/*.markdown"
- posts <- loadAll "script/*"
- --itemTpl <- loadBody "templates/sitemap_element.xml"
- --list <- applyTemplateList itemTpl urlCtx posts
- --return list
+createSitemap :: Compiler [Item String] -> Rules ()
+createSitemap pages =
+ create ["sitemap.xml"] $ do
+ route idRoute
+ compile $ do
+ let urlCtx = field "urls" (\_ -> urlList pages) `mappend` defaultContext
+ makeItem ""
+ >>= loadAndApplyTemplate "templates/sitemap.xml" urlCtx
+
+urlList :: Compiler [Item String] -> Compiler String
+urlList compPosts = do
+ posts <- compPosts
applyUrlTemplateList posts
applyUrlTemplateList :: [Item String] -> Compiler String
applyUrlTemplateList posts = do
- --posts' <- posts
items <- mapM applyUrlTemplate posts
return $ concat $ intersperse "" $ map itemBody items
- --return $ concat $ intersperse "" $ map itemBody items
-
applyUrlTemplate :: Item String -> Compiler (Item String)
applyUrlTemplate item = do
- --item <- compItem
tpl <- urlTemplate item
applyTemplate tpl urlCtx item
urlTemplate :: Item a -> Compiler Template
urlTemplate item = do
- --item <- compItem
metadata <- getMetadata . itemIdentifier $ item
case (M.lookup "image" metadata) of
Nothing -> loadBody "templates/sitemap_element.xml"
View
1  templates/sitemap_element.xml
@@ -1,5 +1,4 @@
<url>
<loc>$url$</loc>
<lastmod>$last_modified$</lastmod>
- <!--$image_element-->
</url>
Please sign in to comment.
Something went wrong with that request. Please try again.