コード例 #1
0
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'))
コード例 #2
0
ファイル: test_node.py プロジェクト: methane/markment
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')