From a880e66c31cebca129ffc0f9953d75de703b587a Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Mon, 16 Oct 2017 14:56:01 +1100 Subject: [PATCH] Put category listings back into the sitemap.xml --- src/Handler/Common.hs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Handler/Common.hs b/src/Handler/Common.hs index 31f62a6..ecf5e8c 100644 --- a/src/Handler/Common.hs +++ b/src/Handler/Common.hs @@ -7,6 +7,8 @@ module Handler.Common where import Data.FileEmbed (embedFile) +import Database.Esqueleto ( (^.) ) +import qualified Database.Esqueleto as E import Yesod.Sitemap import Import @@ -31,6 +33,9 @@ getRobotsR = robots SitemapR getSitemapR :: Handler TypedContent getSitemapR = do + categories <- runDB . E.select . E.distinct . E.from $ \ec -> do + E.orderBy [E.asc $ ec ^. EntryCategoryCategory] + return $ ec ^. EntryCategoryCategory entries <- runDB $ selectList [] [Desc EntryPublished] sitemap $ do yield SitemapUrl @@ -39,20 +44,19 @@ getSitemapR = do , sitemapChangeFreq = Just Daily , sitemapPriority = Nothing } - yieldMany $ kindToSitemapUrl <$> allEntryKinds + yieldMany $ sitemapUrl . CategoryR . E.unValue <$> categories + yieldMany $ sitemapUrl . EntriesR <$> allEntryKinds yieldMany $ entryToSitemapUrl <$> entries -kindToSitemapUrl :: EntryKind -> SitemapUrl (Route App) -kindToSitemapUrl kind = SitemapUrl - { sitemapLoc = EntriesR kind +sitemapUrl :: a -> SitemapUrl a +sitemapUrl loc = SitemapUrl + { sitemapLoc = loc , sitemapLastMod = Nothing , sitemapChangeFreq = Nothing , sitemapPriority = Nothing } + entryToSitemapUrl :: Entity Entry -> SitemapUrl (Route App) -entryToSitemapUrl entry = SitemapUrl - { sitemapLoc = entryR entry - , sitemapLastMod = Just . entryUpdated . entityVal $ entry - , sitemapChangeFreq = Nothing - , sitemapPriority = Nothing +entryToSitemapUrl entry = (sitemapUrl $ entryR entry) + { sitemapLastMod = Just . entryUpdated . entityVal $ entry }