Add support for generating an XML sitemap

This commit is contained in:
Danielle McLean 2017-10-05 09:16:26 +11:00
parent 1c5939d863
commit 8c3a562c7d
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
4 changed files with 16 additions and 3 deletions

View file

@ -4,5 +4,6 @@
/favicon.ico FaviconR GET
/keybase.txt KeybaseR GET
/robots.txt RobotsR GET
/sitemap.xml SitemapR GET
/ HomeR GET

View file

@ -47,6 +47,7 @@ dependencies:
- case-insensitive
- wai
- libravatar >=0.4 && <0.5
- yesod-sitemap >=1.4 && <1.5
# The library contains all of our application code. The executable
# defined below is just a thin wrapper.

View file

@ -128,6 +128,7 @@ instance Yesod App where
isAuthorized FaviconR _ = return Authorized
isAuthorized KeybaseR _ = return Authorized
isAuthorized RobotsR _ = return Authorized
isAuthorized SitemapR _ = return Authorized
isAuthorized (StaticR _) _ = return Authorized
-- This function creates static content files in the static folder

View file

@ -7,6 +7,8 @@
module Handler.Common where
import Data.FileEmbed (embedFile)
import Yesod.Sitemap
import Import
-- These handlers embed files in the executable at compile time to avoid a
@ -21,6 +23,14 @@ getKeybaseR :: Handler TypedContent
getKeybaseR = return $ TypedContent typePlain
$ toContent $(embedFile "config/keybase.txt")
getRobotsR :: Handler TypedContent
getRobotsR = return $ TypedContent typePlain
$ toContent $(embedFile "config/robots.txt")
getRobotsR :: Handler Text
getRobotsR = robots SitemapR
getSitemapR :: Handler TypedContent
getSitemapR = sitemap $ do
yield SitemapUrl
{ sitemapLoc = HomeR
, sitemapLastMod = Nothing
, sitemapChangeFreq = Just Daily
, sitemapPriority = Nothing
}