Skip to content

Commit

Permalink
Restructure Modules For Easier Route Customization
Browse files Browse the repository at this point in the history
  • Loading branch information
s0kil committed Apr 6, 2022
1 parent f5635bf commit 48095fd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
module IHP.SEO.Sitemap.Controller where
module IHP.SEO.Sitemap.ControllerFunctions where

import IHP.Prelude
import IHP.RouterPrelude (string, endOfInput, CanRoute(..), HasPath(..))
import IHP.ControllerPrelude
import IHP.SEO.Sitemap.Types
import qualified Text.Blaze as Markup
import qualified Text.Blaze.Internal as Markup
import qualified Text.Blaze.Renderer.Utf8 as Markup

data SitemapController
= SitemapAction
deriving (Eq, Show, Data)

instance HasPath SitemapController where
pathTo SitemapAction = "/sitemap.xml"

instance CanRoute SitemapController where
parseRoute' = do
string "/sitemap.xml"
endOfInput
pure SitemapAction

renderXmlSitemap :: (?context::ControllerContext) => Sitemap -> IO ()
renderXmlSitemap Sitemap { links } = do
let sitemap = Markup.toMarkup [xmlDocument, sitemapLinks]
Expand Down
14 changes: 14 additions & 0 deletions IHP/SEO/Sitemap/Routes.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module IHP.SEO.Sitemap.Routes where

import IHP.Prelude
import IHP.RouterPrelude
import IHP.SEO.Sitemap.Types

instance HasPath SitemapController where
pathTo SitemapAction = "/sitemap.xml"

instance CanRoute SitemapController where
parseRoute' = do
string "/sitemap.xml"
endOfInput
pure SitemapAction
7 changes: 6 additions & 1 deletion IHP/SEO/Sitemap/Types.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module IHP.SEO.Sitemap.Types
( Sitemap(..)
( SitemapController(..)
, Sitemap(..)
, SitemapLink(..)
, SitemapChangeFrequency(..)
)
Expand All @@ -8,6 +9,10 @@ where
import IHP.Prelude
import Prelude (Show(..))

data SitemapController
= SitemapAction
deriving (Eq, Show, Data)

data Sitemap
= Sitemap { links :: [SitemapLink] }
deriving (Eq, Show, Data)
Expand Down
3 changes: 2 additions & 1 deletion ihp.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ library
, IHP.GraphQL.ToText
, IHP.GraphQL.Types
, IHP.SEO.Sitemap.Types
, IHP.SEO.Sitemap.Controller
, IHP.SEO.Sitemap.ControllerFunctions
, IHP.SEO.Sitemap.Routes

executable RunDevServer
import: shared-properties
Expand Down

0 comments on commit 48095fd

Please sign in to comment.