From 97b7ec5bfa46c1509b2ce704ab9bd07ae2087947 Mon Sep 17 00:00:00 2001 From: Test Date: Wed, 23 Sep 2026 20:33:29 +0000 Subject: [PATCH] fix(seo): clean json-ld serialization without html entity escaping - Introduces json_ld_script() helper replacing esc(json.dumps(ld)) - Fixes invalid JSON-LD parsing across home, categories, topics, and joke-of-the-day - Adds BreadcrumbList schema to topic pages alongside FAQPage - Rebuilds all affected static pages and verifies zero JSON parsing errors Closes #1ff07fdce451daa2fc023631f5ad25592637d4b162be29063dc1122043ad4fb9 --- build.py | 24 ++++++++++++++++++------ site/api/v1/random.json | 2 +- site/category/animals/index.html | 2 +- site/category/christmas/index.html | 2 +- site/category/family/index.html | 2 +- site/category/food/index.html | 2 +- site/category/halloween/index.html | 2 +- site/category/knock-knock/index.html | 2 +- site/category/one-liners/index.html | 2 +- site/category/school/index.html | 2 +- site/category/space/index.html | 2 +- site/category/sports/index.html | 2 +- site/category/tech/index.html | 2 +- site/category/travel/index.html | 2 +- site/category/weather/index.html | 2 +- site/category/work/index.html | 2 +- site/index.html | 2 +- site/joke-of-the-day/index.html | 2 +- site/rss.xml | 2 +- site/topic/birthday/index.html | 1 + site/topic/cars/index.html | 3 ++- site/topic/cats/index.html | 1 + site/topic/coffee/index.html | 1 + site/topic/cows/index.html | 3 ++- site/topic/dogs/index.html | 3 ++- site/topic/love/index.html | 3 ++- site/topic/money/index.html | 1 + site/topic/ocean/index.html | 3 ++- site/topic/school/index.html | 3 ++- site/topic/sleep/index.html | 1 + site/topic/winter/index.html | 1 + 31 files changed, 54 insertions(+), 30 deletions(-) diff --git a/build.py b/build.py index 09890b17..a9accc70 100644 --- a/build.py +++ b/build.py @@ -73,6 +73,11 @@ def joke_count(slug): return sum(1 for j in JOKES if j['cat'] == slug) +def json_ld_script(obj): + """Serialize structured data cleanly without HTML escaping quotes.""" + return '' % json.dumps(obj, ensure_ascii=False).replace('%s' % esc(json.dumps(ld))) + return layout(title, desc, body, '/', json_ld_script(ld)) def page_category(slug): @@ -297,8 +301,7 @@ def page_category(slug): ld = {"@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [ {"@type": "ListItem", "position": 1, "name": "Home", "item": SITE_URL + '/'}, {"@type": "ListItem", "position": 2, "name": c['name'], "item": SITE_URL + '/category/%s/' % slug}]} - return layout(title, desc, body, '/category/%s/' % slug, - '' % esc(json.dumps(ld))) + return layout(title, desc, body, '/category/%s/' % slug, json_ld_script(ld)) def topic_jokes(topic): @@ -341,9 +344,18 @@ def page_topic(slug): } for j in js ] } + crumbs_ld = { + "@context": "https://schema.org", + "@type": "BreadcrumbList", + "itemListElement": [ + {"@type": "ListItem", "position": 1, "name": "Home", "item": SITE_URL + '/'}, + {"@type": "ListItem", "position": 2, "name": "Topics", "item": SITE_URL + '/#topics'}, + {"@type": "ListItem", "position": 3, "name": t['name'], "item": SITE_URL + '/topic/%s/' % slug} + ] + } return layout(title, desc, body, '/topic/%s/' % slug, - '' % json.dumps(faq_ld).replace('' % SITE_URL + - '' % esc(json.dumps(ld))) + json_ld_script(ld)) def page_search(): diff --git a/site/api/v1/random.json b/site/api/v1/random.json index bb1629c7..be1d6b6d 100644 --- a/site/api/v1/random.json +++ b/site/api/v1/random.json @@ -1 +1 @@ -{"setup": "What do astronauts use to keep their pants up?", "punchline": "An asteroid belt.", "type": "qa", "category": "space", "source": "https://bestdadjokes.lol/category/space/#joke-164"} \ No newline at end of file +{"setup": "What did the baby cookie's parents do when it cried?", "punchline": "They felt crumby.", "type": "qa", "category": "food", "source": "https://bestdadjokes.lol/category/food/#joke-53"} \ No newline at end of file diff --git a/site/category/animals/index.html b/site/category/animals/index.html index 04d0b0d5..b92ed7d6 100644 --- a/site/category/animals/index.html +++ b/site/category/animals/index.html @@ -31,7 +31,7 @@ - +