feat: move the pages to Markdown and the news to the dated layout
Pages are Markdown files in content/<lang>/ with a Key: value header, the news carry Title, Author, Date, Categories and Description and are published as /news/YYYY/MM/name.html, with a page for every category. The templates, the language files and site.json shrink to the chrome and the shared strings, and the footer credits motorino. The output matches the one of build.py page by page, checked with tools/compare.py and the Nu HTML Checker.
This commit is contained in:
parent
e0607bbda3
commit
d2f9bba46b
4 changed files with 1518 additions and 896 deletions
|
|
@ -69,7 +69,7 @@ def compare_pages(old, new, post=False):
|
|||
def remap(html, mapping):
|
||||
"""Replace old addresses by new ones."""
|
||||
for old, new in sorted(mapping.items(), key=lambda kv: -len(kv[0])):
|
||||
html = html.replace(old, new)
|
||||
html = html.replace(old, new).replace(old.replace("/", "%2F"), new.replace("/", "%2F"))
|
||||
return html
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -110,13 +110,17 @@ def page_file(path, default_lang, lang):
|
|||
return path.lstrip("/")[: -len(".html")] + ".md"
|
||||
|
||||
|
||||
def page_header(title, page_id, description, layout, note="", switch=None):
|
||||
def page_header(title, page_id, description, layout, note="", switch=None, manifesto_version="", manifesto_date=""):
|
||||
"""The header of a page file."""
|
||||
lines = [f"Title: {title}", f"ID: {page_id}", f"Description: {description}", f"Layout: {layout}"]
|
||||
if note:
|
||||
lines.append(f"Note: {note}")
|
||||
if switch:
|
||||
lines.append("Switch: " + ", ".join(f"{k}={v}" for k, v in switch.items()))
|
||||
if manifesto_version:
|
||||
lines.append(f"ManifestoVersion: {manifesto_version}")
|
||||
if manifesto_date:
|
||||
lines.append(f"ManifestoDate: {manifesto_date}")
|
||||
return "\n".join(lines) + "\n-\n"
|
||||
|
||||
|
||||
|
|
@ -181,7 +185,8 @@ def migrate_pages(root, old_out, site, langs):
|
|||
body = restore(html_to_md(html), values)
|
||||
layout, note = "bare", ""
|
||||
write(os.path.join(root, "content", lang, page_file(path, default, lang)),
|
||||
page_header(data["title"], pid, data["description"], layout, note, switch) + body)
|
||||
page_header(data["title"], pid, data["description"], layout, note, switch,
|
||||
data.get("manifesto_version", ""), data.get("manifesto_date", "")) + body)
|
||||
|
||||
|
||||
def migrate_news(root):
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@ class ComparePages(unittest.TestCase):
|
|||
|
||||
|
||||
class PostPaths(unittest.TestCase):
|
||||
def test_percent_encoded_addresses_are_moved_too(self):
|
||||
mapping = {"/news/shop.html": "/news/2026/11/shop.html"}
|
||||
html = "uri=https%3A%2F%2Fkmalloc.org%2Fnews%2Fshop.html"
|
||||
self.assertEqual(compare.remap(html, mapping), "uri=https%3A%2F%2Fkmalloc.org%2Fnews%2F2026%2F11%2Fshop.html")
|
||||
|
||||
def test_old_post_links_are_moved_to_the_new_paths(self):
|
||||
mapping = {"/news/shop.html": "/news/2026/11/shop.html"}
|
||||
html = '<a href="/news/shop.html">shop</a> and https://kmalloc.org/news/shop.html'
|
||||
|
|
|
|||
|
|
@ -78,6 +78,11 @@ class Content(unittest.TestCase):
|
|||
header = migrate.page_header("kmalloc.org: News", "news", "Updates.", "bare", note="", switch={"en": "/?lang=en"})
|
||||
self.assertEqual(header, "Title: kmalloc.org: News\nID: news\nDescription: Updates.\nLayout: bare\nSwitch: en=/?lang=en\n-\n")
|
||||
|
||||
def test_page_header_with_manifesto_version(self):
|
||||
header = migrate.page_header("M", "manifesto", "d", "manifesto", note="N", manifesto_version="1.0", manifesto_date="2026-11-12")
|
||||
self.assertEqual(header, "Title: M\nID: manifesto\nDescription: d\nLayout: manifesto\nNote: N\n"
|
||||
"ManifestoVersion: 1.0\nManifestoDate: 2026-11-12\n-\n")
|
||||
|
||||
def test_post_conversion(self):
|
||||
old = "---\ntitle: A shop\nsummary: About the shop.\n---\n\nThere is a shop.\n"
|
||||
name, text = migrate.convert_post("2026-11-14-shop.md", old)
|
||||
|
|
|
|||
Loading…
Reference in a new issue