From 8c3a562c7dfa8b849de62931f2bab9972d824215 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Thu, 5 Oct 2017 09:16:26 +1100 Subject: [PATCH] Add support for generating an XML sitemap --- config/routes | 1 + package.yaml | 1 + src/Foundation.hs | 1 + src/Handler/Common.hs | 16 +++++++++++++--- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/config/routes b/config/routes index c0114b8..def52b9 100644 --- a/config/routes +++ b/config/routes @@ -4,5 +4,6 @@ /favicon.ico FaviconR GET /keybase.txt KeybaseR GET /robots.txt RobotsR GET +/sitemap.xml SitemapR GET / HomeR GET diff --git a/package.yaml b/package.yaml index 9020ecd..6242801 100644 --- a/package.yaml +++ b/package.yaml @@ -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. diff --git a/src/Foundation.hs b/src/Foundation.hs index 728e759..03f2793 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -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 diff --git a/src/Handler/Common.hs b/src/Handler/Common.hs index cfbbbb7..fb31414 100644 --- a/src/Handler/Common.hs +++ b/src/Handler/Common.hs @@ -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 + }