MCPcopy Create free account
hub / github.com/bytecodealliance/component-docs / generate_sitemap

Function generate_sitemap

scripts/generate_sitemap.py:28–51  ·  view source on GitHub ↗

Generate a sitemap XML file from SUMMARY.md structure.

(domain, output_path, summary_file_path, higher_priority_section)

Source from the content-addressed store, hash-verified

26 return "0.5" # All other pages
27
28def generate_sitemap(domain, output_path, summary_file_path, higher_priority_section):
29 """Generate a sitemap XML file from SUMMARY.md structure."""
30 domain = "https://" + domain
31 urls = parse_summary(summary_file_path) # Add base URL to the list of URLs
32 urls = [""] + list(urls)
33
34 sitemap = '<?xml version="1.0" encoding="UTF-8"?>\n'
35 sitemap += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'
36
37 for url in urls:
38 full_url = urljoin(domain, url)
39 priority = determine_priority(url, higher_priority_section)
40
41 sitemap += " <url>\n"
42 sitemap += f" <loc>{full_url}</loc>\n"
43 sitemap += " <changefreq>weekly</changefreq>\n"
44 sitemap += f" <priority>{priority}</priority>\n"
45 sitemap += " </url>\n"
46
47 sitemap += "</urlset>"
48
49 # Write the sitemap to the specified output path
50 with open(output_path, "w") as file:
51 file.write(sitemap)
52
53DEFAULT_SUMMARY_MD_PATH = (Path(__file__).parent / "../component-model/src/SUMMARY.md").resolve()
54DEFAULT_SITEMAP_XML_PATH = (Path(__file__).parent / "../component-model/book/html/sitemap.sml").resolve()

Callers 1

Calls 2

parse_summaryFunction · 0.85
determine_priorityFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…