Skip to content

Commit

Permalink
time format
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMartel committed May 5, 2024
1 parent 5068458 commit 28b15c9
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from glob import glob
from os import path, mkdir
from datetime import date

main_layout = open("src/main_layout.html").read()
math_head = open("src/math_head.html").read()
Expand All @@ -9,7 +10,7 @@ def build_page(page_meta):
page, meta = page_meta
title = meta.get("title", "[[Add a title in meta.json]]")
description = meta.get("description", "[[Add a description in meta.json]]")
date = meta.get("date", [0, 0, 0])
published_time = date(*meta.get("date", [2020, 1, 1]))
ishome = meta.get("ishome", False)
needsmath = meta.get("needsmath", False)

Expand All @@ -25,7 +26,7 @@ def build_page(page_meta):
page_out = main_layout
page_out = page_out.replace("[[TITLE]]", title)
page_out = page_out.replace("[[DESCRIPTION]]", description)
page_out = page_out.replace("[[DATE]]", f"{date[0]}-{date[1]}-{date[2]}")
page_out = page_out.replace("[[DATE]]", f"{published_time}")
page_out = page_out.replace("[[URL]]", f"https://blog.lixtelnis.com/{page_name}")
page_out = page_out.replace("[[SITEINDEX]]", site_index)
page_out = page_out.replace("[[BODY]]", body)
Expand Down Expand Up @@ -53,43 +54,45 @@ def build_rss(page_metas):
page_metas = filter(lambda page_meta: not page_meta[1].get("ishome", False), page_metas)

with open(f"build/rss.xml","w") as f:
f.write('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel>')
f.write('<title>blog.lixtelnis.com</title>')
f.write('<link>https://blog.lixtelnis.com/</link>')
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
f.write('<rss version="2.0">\n<channel>\n')
f.write('<title>blog.lixtelnis.com</title>\n')
f.write('<link>https://blog.lixtelnis.com/</link>\n')

for page, meta in page_metas:
title = meta.get("title", "[[Add a title in meta.json]]")
description = meta.get("description", "[[Add a description in meta.json]]")
date = meta.get("date", [0, 0, 0])
pub_date = date(*meta.get("date", [0, 0, 0]))

page_dir = path.dirname(page)
page_name = path.basename(page_dir)

f.write('<item>')
f.write(f'<title>{title}</title>')
f.write(f'<description>{description}</description>')
f.write(f'<pubDate>{date[0]}-{date[1]}-{date[2]}</pubDate>')
f.write(f'<link>https://blog.lixtelnis.com/{page_name}</link>')
f.write('</item>')
f.write('<item>\n')
f.write(f'<title>{title}</title>\n')
f.write(f'<description>{description}</description>\n')
f.write(f'<pubDate>{pub_date.strftime("%a, %d %b %Y %H:%M:%S %z")}</pubDate>\n')
f.write(f'<link>https://blog.lixtelnis.com/{page_name}</link>\n')
f.write('</item>\n')

f.write('</channel></rss>')
f.write('</channel>\n</rss>')

def build_sitemap(page_metas):
page_metas = filter(lambda page_meta: not page_meta[1].get("ishome", False), page_metas)

with open(f"build/sitemap.xml","w") as f:
f.write('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
f.write('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n')

for page, meta in page_metas:
date = meta.get("date", [0, 0, 0])
lastmod = date(*meta.get("date", [0, 0, 0]))

page_dir = path.dirname(page)
page_name = path.basename(page_dir)

f.write('<url>')
f.write(f'<lastmod>{date[0]}-{date[1]}-{date[2]}T12:00:00-05:00</lastmod>')
f.write(f'<loc>https://blog.lixtelnis.com/{page_name}</loc>')
f.write('</url>')
f.write('<url>\n')
f.write(f'<lastmod>{lastmod}</lastmod>\n')
f.write(f'<loc>https://blog.lixtelnis.com/{page_name}</loc>\n')
f.write('</url>\n')

f.write('</urlset>')

Expand Down

0 comments on commit 28b15c9

Please sign in to comment.