# HG changeset patch # User Ludovic Chabant # Date 1435467036 25200 # Node ID 62274d805a6e9abeeb2eba5d05801d2530ab702f # Parent 2aa879d63133c45c06e661cf8923c89d1fe07391 bake: Tweaks to the `sitemap` processor. Add tests. * Now using a `PageIterator` to get the expected behaviour from a given page source, such as skipping taxonomy pages and such. * Fix formatting of priority. * Use the bake time for `lastmod` attribute. diff -r 2aa879d63133 -r 62274d805a6e piecrust/processing/sitemap.py --- a/piecrust/processing/sitemap.py Sat Jun 27 21:48:26 2015 -0700 +++ b/piecrust/processing/sitemap.py Sat Jun 27 21:50:36 2015 -0700 @@ -1,6 +1,7 @@ import time import logging import yaml +from piecrust.data.iterators import PageIterator from piecrust.processing.base import SimpleFileProcessor from piecrust.routing import create_route_metadata @@ -10,8 +11,7 @@ SITEMAP_HEADER = \ """ - + """ SITEMAP_FOOTER = "\n" @@ -19,7 +19,7 @@ SITEURL_LOC = " %s\n" SITEURL_LASTMOD = " %s\n" SITEURL_CHANGEFREQ = " %s\n" -SITEURL_PRIORITY = " %f\n" +SITEURL_PRIORITY = " %0.1f\n" SITEURL_FOOTER = " \n" @@ -59,6 +59,7 @@ if not source_names: return + cur_time = strftime_iso8601(time.time()) for name in source_names: logger.debug("Generating automatic sitemap entries for '%s'." % name) @@ -66,15 +67,12 @@ if source is None: raise Exception("No such source: %s" % name) - for page in source.getPages(): - route_metadata = create_route_metadata(page) - route = self.app.getRoute(source.name, route_metadata) - uri = route.getUri(route_metadata) + it = PageIterator(source) + for page in it: + uri = page['url'] + sm_cfg = page.get('sitemap') - t = page.datetime.timestamp() - sm_cfg = page.config.get('sitemap') - - args = {'url': uri, 'lastmod': strftime_iso8601(t)} + args = {'url': uri, 'lastmod': cur_time} if sm_cfg: args.update(sm_cfg) diff -r 2aa879d63133 -r 62274d805a6e tests/procs/test_sitemap.yaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/procs/test_sitemap.yaml Sat Jun 27 21:50:36 2015 -0700 @@ -0,0 +1,40 @@ +--- +in: + assets/sitemap.sitemap: | + autogen: [pages, theme_pages] + pages/foo.md: This is a foo +outfiles: + sitemap.xml: | + + + + /foo.html + %test_time_iso8601% + + + / + %test_time_iso8601% + + +--- +in: + assets/sitemap.sitemap: | + autogen: [pages] + pages/foo.md: | + --- + sitemap: + changefreq: monthly + priority: 0.8 + --- + This is a foo +outfiles: + sitemap.xml: | + + + + /foo.html + %test_time_iso8601% + monthly + 0.8 + +