From cad196833f41a6b19cc06c21d9da52b0b9d7dc99 Mon Sep 17 00:00:00 2001 From: Imran Siddique Date: Thu, 20 Aug 2026 21:36:07 -0700 Subject: [PATCH] fix(seo): social cards said "Home", not the page title MkDocs sets page.title from the nav entry when the nav gives one, so a landing page listed as "- Home: index.md" reports page.title == "Home". The tag was right, because Material reads the front matter for it, but og:title and twitter:title read page.title and shipped og:title = "Home - TRACE" to every link preview. My own change introduced this: the previous expression suppressed the homepage title entirely and fell back to the site name, so the regression turned a bare "TRACE" into "Home - TRACE". page.meta.title is the front-matter value. Prefer it, fall back to page.title for inner pages, then to the site name. Verified per site: the homepage og:title now matches its <title>, and inner pages keep their own. Builds clean under --strict. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013EQx4N5BzTQbY8kvXUsdkY --- overrides/main.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/overrides/main.html b/overrides/main.html index 162762f..34118f7 100644 --- a/overrides/main.html +++ b/overrides/main.html @@ -22,6 +22,8 @@ {% block extrahead %} {{ super() }} + {# page.title is the nav label ("Home"); page.meta.title is the front matter. #} + {% set page_name = (page.meta.title if page and page.meta and page.meta.title else (page.title if page else None)) %} {% set page_desc = page.meta.description if page and page.meta and page.meta.description else config.site_description %} {% set page_url = page.canonical_url if page and page.canonical_url else config.site_url %} {% set og_image = config.site_url ~ 'docs/assets/og.png' %} @@ -29,7 +31,7 @@ <meta property="og:type" content="website"> <meta property="og:site_name" content="{{ config.site_name }}"> - <meta property="og:title" content="{% if page and page.title %}{{ page.title }} - {{ config.site_name }}{% else %}{{ config.site_name }}: {{ social_title }}{% endif %}"> + <meta property="og:title" content="{% if page_name %}{{ page_name }} - {{ config.site_name }}{% else %}{{ config.site_name }}: {{ social_title }}{% endif %}"> <meta property="og:description" content="{{ page_desc }}"> <meta property="og:url" content="{{ page_url }}"> <meta property="og:image" content="{{ og_image }}"> @@ -39,7 +41,7 @@ <meta property="og:locale" content="en_US"> <meta name="twitter:card" content="summary_large_image"> - <meta name="twitter:title" content="{% if page and page.title %}{{ page.title }} - {{ config.site_name }}{% else %}{{ config.site_name }}: {{ social_title }}{% endif %}"> + <meta name="twitter:title" content="{% if page_name %}{{ page_name }} - {{ config.site_name }}{% else %}{{ config.site_name }}: {{ social_title }}{% endif %}"> <meta name="twitter:description" content="{{ page_desc }}"> <meta name="twitter:image" content="{{ og_image }}">