Put category listings back into the sitemap.xml

This commit is contained in:
Danielle McLean 2017-10-16 14:56:01 +11:00
parent 1364a2e36b
commit a880e66c31
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5

View file

@ -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
}