I would like to add paginated results to a sitemap. Let's say /blog, /blog?page=1, ...
My route definition looks like this:
/blog BlogR GET
The page parameter is optional. How can I add /blog?page=1 to a sitemap. The sitemap module expects Route App. So I am only able to link BlogR but can not figure out how to create the route with a parameter. For redirecting this is easy by just using
redirect (BlogR, [("page", 1)]) // /blog?page=1
There is interpolation for templates as well. But I can not figure out how to create a Route App inside a handler.
getPage :: Int -> Route App
getPage number = ???
Thanks a lot!
As far as I know, you can't really define
getPage
with that signature without a lot of work. Assuming you're usingmkYesod
to generate your boilerplate, it's already generated aRoute App
data type (and associatedrenderRoutes
function) with no provision for supplying query parameters.Your best bet may be to switch from using query parameters to more Yesod-friendly URLs like
/blog/page/1
. Better yet, instead of using a page-based system, base your URLs on a blog post ID number to start the page, so that/blog/start/15
shows your blog starting with posting number 15. If you go this route (pun intended), you automatically get a permanent URL (so that/blog/start/15
is always going to start with the same blog entry), and you can arrange things so that you "usually" page to predictable starting numbers to facilitate caching and so on.But, if you really want to trick
yesod-sitemap
into generating routes with query parameters, the following standalone example may help. Here,getSitemapR
is a reimplementation ofYesod.Sitemap.sitemapList
that usesgetUrlRenderParams
in place ofgetUrlRender
which allows processing of query parameters.I don't really know anything about conduits, so I don't know if my implementation of
getSitemapR
is particularly smart -- I just copied and massaged code fromyesod-sitemap
until it type-checked.