Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit fbcfd41

Browse files
committed
make a simple sitemap for google
1 parent a7b576c commit fbcfd41

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

scripts/make_sitemap.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from pathlib import Path
2+
3+
# /Users/bmiller/Runestone/RunestoneServer/books/csawesome/published/csawesome/MixedFreeResponse/RandomStringChooserParsonsB.html
4+
# becomes /ns/books/published/
5+
def path_to_url(p):
6+
parts = p.split("published")
7+
return "https://runestone.academy/ns/books/published" + parts[-1]
8+
9+
10+
with open("sitemap.xml", "w") as sm:
11+
sm.write(
12+
"""
13+
<?xml version="1.0" encoding="utf-8"?>
14+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
15+
<url><loc>https://runestone.academy</loc></url>
16+
"""
17+
)
18+
p = Path("/Users/bmiller/Runestone/RunestoneServer/books")
19+
for i in p.rglob("*.html"):
20+
if "build" in str(i) or "knowl" in str(i):
21+
continue
22+
elif "published" in str(i):
23+
sm.write("<url><loc>" + path_to_url(str(i)) + "</loc></url>\n")
24+
sm.write("</urlset>")

0 commit comments

Comments
 (0)