fix(website): preserve template-owned HTML formatting

This commit is contained in:
N0zoM1z0
2026-10-10 20:27:01 +08:00
committed by Ysopwnable
parent 5aa30b8b86
commit e964a06b83
27 changed files with 574 additions and 588 deletions
+1 -1
View File
@@ -142,7 +142,7 @@ class WebsiteMaintenanceChecks(unittest.TestCase):
page = root / "website/public/blog/touhou-reconstruction/index.html"
original = page.read_text()
body = original.split('<main id="main"', 1)[1].split("</main>", 1)[0]
template = root / "website/templates/header.html"
template = root / "website/templates/header.html.tmpl"
template.write_text(template.read_text().replace("Reverse Engineer Anything", "REA test navigation"))
with self.assertRaisesRegex(ValueError, "Shared HTML is stale"):
WEBSITE.sync_pages(root, check=True)
+4 -3
View File
@@ -9,6 +9,7 @@ from pathlib import Path, PurePosixPath
from string import Template
import subprocess
import sys
from textwrap import indent
from urllib.parse import quote, urlsplit
@@ -101,10 +102,10 @@ def shared_blocks(root, path, source):
attributes = ' class="nav-start"' if destination == "get-started/" else ""
if route.startswith(destination):
attributes += ' aria-current="page"'
links.append(f' <a href="{base}{destination}"{attributes}>{label}</a>')
links.append(f' <a href="{base}{destination}"{attributes}>{label}</a>')
values = {
"base": base,
"navigation": "\n".join(links),
"navigation": "\n" + "\n".join(links) + "\n ",
"canonical": escape(page_url(site, path), quote=True),
"origin": SITE_ORIGIN,
"title": escape(metadata.titles[0].strip(), quote=True),
@@ -112,7 +113,7 @@ def shared_blocks(root, path, source):
}
templates = root / "website/templates"
return {
name: Template((templates / f"{name}.html").read_text(encoding="utf-8")).substitute(values)
name: indent(Template((templates / f"{name}.html.tmpl").read_text(encoding="utf-8")).substitute(values), " ")
for name in ("sharing", "header", "footer")
}