~marijan/website-builder

1157e1d8cbda3e03fb426f8e6eefd015915191b1 — Marijan Petričević 5 months ago 6e2ec8c
website-builder: create sitemap if template is present
1 files changed, 16 insertions(+), 0 deletions(-)

M app/Main.hs
M app/Main.hs => app/Main.hs +16 -0
@@ 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 =