Merge main into the seasons work: keep the Google tag entry under the seasons entry

This commit is contained in:
swaits committed 2026-11-20 15:23:04 -07:00
commit 9a8aa49318
13 files changed
+135 -13

No files matched your search

+1 -1
View File
@@ -302,7 +302,7 @@ def maintainer_section(site):
<li>The records and the compiled index are public domain (CC0 1.0). Each track keeps the licence of its source.</li>
<li>Every fact in a record names the page it was read on, and each record keeps a history of what changed and why.</li>
<li>To correct a fact, suggest a trail or ask for a track or logo to be removed, {ask}. Every trail page has its own &ldquo;Report a problem&rdquo; link.</li>
<li>The site has no ads, no accounts, no tracking and no analytics. Your theme, units and saved trails stay in your own browser. Maps load their tiles from OpenFreeMap.</li>
<li>The site has no ads and no accounts. Your theme, units and saved trails stay in your own browser. Maps load their tiles from OpenFreeMap.</li>
</ul>
</section>
"""
+13
View File
@@ -216,6 +216,17 @@ def skip_links(body):
return out
# The owner's Google tag, as given; only the container id comes from site.toml (google_tag).
# The inline script's hash is in the Content-Security-Policy (web/static/_headers); a test keeps them equal.
GOOGLE_TAG_INLINE = """
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
"""
GOOGLE_TAG = ('<script async src="https://www.googletagmanager.com/gtm.js?id={id}"></script>\n'
'<script>' + GOOGLE_TAG_INLINE + '</script>')
def layout(title, body, *, path, description="", maps=False, outdoor=False, scripts=(), data=None, site=None,
jsonld=None, og_type="website", noindex=False, image="", image_alt="", alternates=()):
"""Return a complete HTML document.
@@ -262,6 +273,8 @@ def layout(title, body, *, path, description="", maps=False, outdoor=False, scri
f"<title>{esc(tag)}</title>",
f'<meta name="description" content="{esc(description)}">',
]
if site.google_tag:
head.append(GOOGLE_TAG.replace("{id}", esc(site.google_tag)))
if noindex:
head.append('<meta name="robots" content="noindex">')
if canonical:
+5 -2
View File
@@ -12,7 +12,7 @@ class Site:
"""The settings every page needs. Build one with load()."""
def __init__(self, name, tagline, base_url="", repo_url="", repo_branch="main",
contact_url="", name_lang=None, home_title="", maintainer_name="", maintainer_url=""):
contact_url="", name_lang=None, home_title="", maintainer_name="", maintainer_url="", google_tag=""):
if not name:
raise ValueError("site.toml: name must not be empty")
self.name = name
@@ -27,6 +27,8 @@ class Site:
# named in the structured data. Both are public by the owner's choice.
self.maintainer_name = maintainer_name.strip()
self.maintainer_url = maintainer_url.strip()
# Google tag container id (GTM-XXXXXXX): when set, every page loads the tag; empty: none.
self.google_tag = google_tag.strip()
# record id -> language tag of its name ("fr"), for names that are not English
self.name_lang = dict(name_lang or {})
@@ -123,7 +125,8 @@ def from_file(path):
repo_branch=data.get("repo_branch", "main"),
contact_url=data.get("contact_url", ""), name_lang=data.get("name_lang", {}),
home_title=data.get("home_title", ""),
maintainer_name=data.get("maintainer_name", ""), maintainer_url=data.get("maintainer_url", ""))
maintainer_name=data.get("maintainer_name", ""), maintainer_url=data.get("maintainer_url", ""),
google_tag=data.get("google_tag", ""))
@functools.cache