From 269980ea28e82fc1119ee271fe9205e9bb1cd33a Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 19 May 2026 08:27:53 +0000 Subject: [PATCH 1/2] Set page title from config.sitename instead of hardcoded MD-CMS The static element previously showed "MD-CMS" before JavaScript loaded. The JS already sets document.title from config.sitename on boot, so clearing the initial value ensures the browser tab never displays the hardcoded string. --- app/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/index.html b/app/index.html index d811dc9..2987482 100644 --- a/app/index.html +++ b/app/index.html @@ -21,7 +21,7 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> -<title>MD-CMS + From ee3d4872a0680c16c0ded74203f8990bead93a93 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 19 May 2026 08:31:47 +0000 Subject: [PATCH 2/2] Patch 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). --- docs/unreleased.md | 10 ++++++++++ mdcms.py | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 docs/unreleased.md diff --git a/docs/unreleased.md b/docs/unreleased.md new file mode 100644 index 0000000..ecafdfd --- /dev/null +++ b/docs/unreleased.md @@ -0,0 +1,10 @@ +# Unreleased changes + +Changes on `development` not yet merged to `main`. + +## Fixes + +- **`mdcms build` now patches `<title>` in `index.html` with `sitename` from `config.yml`.** + Previously the HTML `<title>` tag was a hardcoded blank (or "MD-CMS" in older templates), + so link previews in apps like WhatsApp showed the wrong name. After each build the tag + reflects the configured site name, which crawlers and preview scrapers read directly. diff --git a/mdcms.py b/mdcms.py index 7050c9e..6ca43cd 100644 --- a/mdcms.py +++ b/mdcms.py @@ -412,6 +412,19 @@ def validate_assets(site_path: Path, cfg: dict) -> list: # ─── Core build logic ───────────────────────────────────────── +_TITLE_RE = re.compile(r"<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"{sitename}", html, count=1) + if new_html != html: + index.write_text(new_html, encoding="utf-8") + + def run_build(site_path: Path): """Scan pages/ and posts/, write nav.yml and search.json. Raises ClickException on failure.""" if not site_path.is_dir(): @@ -491,6 +504,8 @@ def run_build(site_path: Path): ) 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") if pwa_enabled: generate_pwa(site_path, cfg)