@@ 29,6 29,7 @@ codeStyle = zenburn
main :: IO ()
main = do
hasPosts <- doesDirectoryExist "posts"
+
maybeFeedConfiguration <-
doesFileExist "feed-configuration.json" >>= \case
False -> pure Nothing
@@ 39,6 40,8 @@ main = do
exitFailure
Right config -> pure . Just $ config
+ hasSitemapTemplate <- doesFileExist "templates/sitemap.xml"
+
withUtf8 $ hakyllWith (defaultConfiguration {destinationDirectory = "docs"}) $ do
match "CNAME" $ do
route idRoute
@@ 118,6 121,19 @@ main = do
=<< loadAllSnapshots "posts/*" "content"
renderRss feedConfiguration feedCtx posts
+ when hasSitemapTemplate $ do
+ create ["sitemap.xml"] $ do
+ route idRoute
+ compile $ do
+ posts <- recentFirst =<< loadAll "posts/*"
+ pages <- loadAll "pages/*"
+ index <- load "index.html"
+ let sitemapCtx =
+ listField "pages" defaultContext (return (index : pages))
+ <> listField "posts" postCtx (return posts)
+ makeItem ("" :: String)
+ >>= loadAndApplyTemplate "templates/sitemap.xml" sitemapCtx
+
--------------------------------------------------------------------------------
postCtx :: Context String
postCtx =