mirror of
https://github.com/kbenestad/mdcms.git
synced 2026-06-18 07:24:31 +00:00
Patch <title> in index.html with sitename during build
mdcms build now writes the sitename from config.yml into the <title> tag of index.html. WhatsApp, Slack, and other link-preview crawlers read the static HTML without executing JavaScript, so the title must be correct in the raw file. Previously it was blank (or "MD-CMS" in older templates).
This commit is contained in:
parent
a8fcc79ba9
commit
28b248735f
2 changed files with 21 additions and 0 deletions
|
|
@ -4,6 +4,12 @@ Changes merged into `development` that have not yet been released to `main`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## `mdcms build` patches `<title>` with sitename
|
||||||
|
|
||||||
|
`mdcms build` now rewrites the `<title>` tag in `index.html` with the value of `sitename` from `config.yml`. Previously the tag was hardcoded (`MD-CMS`) in older templates, or blank in the starter template, so link previews in WhatsApp, Slack, and other crawlers that read static HTML showed the wrong name.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Untranslated posts now visible in all categories
|
## Untranslated posts now visible in all categories
|
||||||
|
|
||||||
**Status:** On `development`, pending release.
|
**Status:** On `development`, pending release.
|
||||||
|
|
|
||||||
15
mdcms.py
15
mdcms.py
|
|
@ -428,6 +428,19 @@ def validate_assets(site_path: Path, cfg: dict) -> list:
|
||||||
|
|
||||||
# ─── Core build logic ─────────────────────────────────────────
|
# ─── Core build logic ─────────────────────────────────────────
|
||||||
|
|
||||||
|
_TITLE_RE = re.compile(r"<title>[^<]*</title>")
|
||||||
|
|
||||||
|
|
||||||
|
def _patch_html_title(site_path: Path, sitename: str) -> None:
|
||||||
|
index = site_path / "index.html"
|
||||||
|
if not index.exists():
|
||||||
|
return
|
||||||
|
html = index.read_text(encoding="utf-8")
|
||||||
|
new_html = _TITLE_RE.sub(f"<title>{sitename}</title>", html, count=1)
|
||||||
|
if new_html != html:
|
||||||
|
index.write_text(new_html, encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
def run_build(site_path: Path):
|
def run_build(site_path: Path):
|
||||||
"""Scan pages/ and posts/, write nav.yml and search.json. Raises ClickException on failure."""
|
"""Scan pages/ and posts/, write nav.yml and search.json. Raises ClickException on failure."""
|
||||||
if not site_path.is_dir():
|
if not site_path.is_dir():
|
||||||
|
|
@ -507,6 +520,8 @@ def run_build(site_path: Path):
|
||||||
)
|
)
|
||||||
click.echo(f" Wrote search.json ({len(live_pages) + len(post_records)} entries)")
|
click.echo(f" Wrote search.json ({len(live_pages) + len(post_records)} entries)")
|
||||||
|
|
||||||
|
_patch_html_title(site_path, cfg.get("sitename", ""))
|
||||||
|
|
||||||
pwa_enabled = str(cfg.get("pwa", "no")).lower() in ("yes", "true")
|
pwa_enabled = str(cfg.get("pwa", "no")).lower() in ("yes", "true")
|
||||||
if pwa_enabled:
|
if pwa_enabled:
|
||||||
generate_pwa(site_path, cfg)
|
generate_pwa(site_path, cfg)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue