Skip to content

Commit

Permalink
added sitemap support
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumbagel committed Feb 29, 2024
1 parent fdab6a5 commit 265f9cc
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
1 change: 1 addition & 0 deletions PyAerial/generate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ favicon: "/assets/images/quantumbagel_favicon.webp"
name: "PyAerial"
username: "quantumbagel"
meta_description: "PyAerial - simple and intuitive plane tracking by @quantumbagel"
path: "PyAerial"

starting_page_index: 0
analytics:
Expand Down
38 changes: 37 additions & 1 deletion generate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import markdown
import datetime

INFO_TEMPLATE = """
<li class="contact-item">
Expand Down Expand Up @@ -241,6 +242,21 @@
<button data-filter-btn>CATEGORY</button>
</li>
"""
tz = datetime.timezone.utc
ft = "%Y-%m-%dT%H:%M:%S%z"
t = datetime.datetime.now(tz=tz).strftime(ft)
SITEMAP_ITEM_TEMPLATE = f"""<url>
<loc>PAGE</loc>
<lastmod>{t}</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
"""

SITEMAP_TEMPLATE = """<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
SITEMAP
</urlset>"""


def markdown_text_parsing(txt):
o = markdown.markdown(txt)[3:][:-4]
Expand Down Expand Up @@ -379,17 +395,37 @@ def generate_html(variables):
variables["analytics"]["tag_manager_id"]))
return html

def generate_sitemap(links):
sitemap = ''
for link in links:
sitemap += SITEMAP_ITEM_TEMPLATE.replace("PAGE", link)
return SITEMAP_TEMPLATE.replace("SITEMAP", sitemap)




import ruamel.yaml

y = ruamel.yaml.YAML()

jobs = y.load(open("generate_execute.yaml"))["jobs"]
links = []
for job_key in jobs.keys():
job = jobs[job_key]
data = y.load(open(job["in"]))
for lk in data["pages"]:
url = f"https://{data['username']}.github.io/{data['path']}/{lk}"
url = url.replace("//", "/")
links.append(url)
url = f"https://{data['username']}.github.io/{data['path']}"
links.append(url)
f = open(job["out"], "w")
f.truncate(0)
f.write(generate_html(data))
f.close()

print(f"Regenerated {len(jobs)} jobs.")

f = open("sitemap.xml", "w")
f.truncate(0)
f.write(generate_sitemap(links))
f.close()
1 change: 1 addition & 0 deletions generate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ name: "Julian Reder"
username: "quantumbagel"
starting_page_index: 0
meta_description: "Hi! I'm Julian Reder (@quantumbagel), a dually-enrolled programmer at Wake Tech"
path: ""
analytics:
tag_manager_id: "G-FQY8Y114PS"

Expand Down
45 changes: 45 additions & 0 deletions sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https:/quantumbagel.github.io/about</loc>
<lastmod>2024-02-29T20:19:18+0000</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https:/quantumbagel.github.io/experience</loc>
<lastmod>2024-02-29T20:19:18+0000</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https:/quantumbagel.github.io/projects</loc>
<lastmod>2024-02-29T20:19:18+0000</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https:/quantumbagel.github.io/contact</loc>
<lastmod>2024-02-29T20:19:18+0000</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://quantumbagel.github.io/</loc>
<lastmod>2024-02-29T20:19:18+0000</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https:/quantumbagel.github.io/PyAerial/about</loc>
<lastmod>2024-02-29T20:19:18+0000</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://quantumbagel.github.io/PyAerial</loc>
<lastmod>2024-02-29T20:19:18+0000</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>

</urlset>

0 comments on commit 265f9cc

Please sign in to comment.