INNER CODE UNIT · Python
generate_sitemap_xml
netkiller/netkiller.github.io · generate_sitemaps.py:49
def generate_sitemap_xml(html_files):
"""Generate sitemap.xml."""
lines = ['<?xml version="1.0" encoding="UTF-8"?>']
lines.append('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
for rel_path in html_files:
full_path = OUTPUT_DIR / rel_path
lastmod = get_lastmod(full_path)
url_path = url_encode_path(rel_path)
lines.append(' <url>')
lines.append(f' <loc>{BASE_URL}/{url_path}</loc>')
lines.append(f' <lastmod>{lastmod}</lastmod>')
lines.append(' </url>')
lines.append('</urlset>')
with open(OUTPUT_DIR / 'sitemap.xml', 'w', encoding='utf-8') as f: