diff --git a/src/Handler/Common.hs b/src/Handler/Common.hs index fb31414..1153b95 100644 --- a/src/Handler/Common.hs +++ b/src/Handler/Common.hs @@ -11,6 +11,9 @@ import Yesod.Sitemap import Import +import Entry.Kind ( EntryKind, allEntryKinds ) +import Widget.Entry ( entryR ) + -- These handlers embed files in the executable at compile time to avoid a -- runtime dependency, and for efficiency. @@ -27,10 +30,29 @@ getRobotsR :: Handler Text getRobotsR = robots SitemapR getSitemapR :: Handler TypedContent -getSitemapR = sitemap $ do - yield SitemapUrl - { sitemapLoc = HomeR - , sitemapLastMod = Nothing - , sitemapChangeFreq = Just Daily - , sitemapPriority = Nothing - } +getSitemapR = do + entries <- runDB $ selectList [] [Desc EntryPublished] + sitemap $ do + yield SitemapUrl + { sitemapLoc = HomeR + , sitemapLastMod = Nothing + , sitemapChangeFreq = Just Daily + , sitemapPriority = Nothing + } + yieldMany $ kindToSitemapUrl <$> allEntryKinds + yieldMany $ entryToSitemapUrl <$> entries + +kindToSitemapUrl :: EntryKind -> SitemapUrl (Route App) +kindToSitemapUrl kind = SitemapUrl + { sitemapLoc = EntriesR kind + , 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 + }