def save_sitemap(event, args, project, theme, generated): if not args.SITEMAP_PREFIX: return urlset = etree.Element("urlset") destination = Node(args.OUTPUT) NAME = 'sitemap.xml' for item in filter(lambda x: x.endswith('html'), generated): relative = destination.relative(item) url = etree.SubElement(urlset, "url") loc = etree.SubElement(url, "loc") loc.text = "{0}/{1}".format( args.SITEMAP_PREFIX.rstrip('/'), relative, ) with destination.open(NAME, 'w') as f: f.write(etree.tostring(urlset, pretty_print=True).decode('utf-8'))
def test_node_relative(exists): ("Node#relative() returns a path relative to the base") nd = Node("/foo/bar/") nd.relative('/foo/bar/yes.py').should.equal('yes.py')