This makes XML for sitemaps. I wrote it because sitemapgen4j doesn't give you any good way to do anything with the sitemaps it generates other than save to a file, and the sitemap plugin for Play works by adding annotations to controller actions, which won't work for CMS. This can just be used in a controller responding to a route for "/sitemap.xml", and you can iterate through a site's pages from the database and return the xml from there.
It doesn't do sitemap indexes yet, so it's limited to listing 50,000 pages. Hopefully we can live with that for now.
More info about sitemaps in general: http://www.sitemaps.org/protocol.html
Hosted in Banno's Bintray (for 2.10 and 2.11):
"com.banno" %% "scala-sitemap" % "0.10.3"
Start a new sitemap:
val mySitemap = Sitemap("http://example.com")
Adding pages to a sitemap produces a new sitemap. The only required data is the page's URL. All these work:
mySitemap.add("/section/page") mySitemap.add("/section/page/") mySitemap.add("http://example.com/section/page", Some(modified)) mySitemap.add("//example.com/section/page", None, Some(ChangeFreq.Monthly))
add is just a convenient shortcut to the SitemapEntry case class, whose attributes are named like the XML tags' labels in a sitemap:
locfor the URL (
Uribut scala-uri will implicitly convert from String)
lastmodfor last-modified (
changefreqfor change frequency (using an enumeration called
ChangeFreq) for the valid values of this field:
Option[Double]between 0.0 and 1.0 inclusive)
So in practice, you'll likely make sitemap something like this:
val sitemap = Sitemap( "http://example.com", allMyPages.map(page => SitemapEntry(page.path, Some(page.modified), Some(ChangeFreq.Weekly))))
And then of course, just ask it for its XML.
Go for it. (with tests.)