Generate a sitemap XML file from SUMMARY.md structure.
(domain, output_path, summary_file_path, higher_priority_section)
| 26 | return "0.5" # All other pages |
| 27 | |
| 28 | def 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 | |
| 53 | DEFAULT_SUMMARY_MD_PATH = (Path(__file__).parent / "../component-model/src/SUMMARY.md").resolve() |
| 54 | DEFAULT_SITEMAP_XML_PATH = (Path(__file__).parent / "../component-model/book/html/sitemap.sml").resolve() |
no test coverage detected
searching dependent graphs…