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('', r'<\/') + + def joke_card(j, reveal=False): """A single joke card. Punchline is in the DOM (SEO-safe); JS blurs until clicked.""" cls = 'joke-card' @@ -271,8 +276,7 @@ def page_index(): "query-input": "required name=search_term_string" } } - return layout(title, desc, body, '/', - '' % 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('', '<\/')) + json_ld_script(faq_ld) + '\n' + json_ld_script(crumbs_ld)) def page_generator(): @@ -401,7 +413,7 @@ def page_jotd(): "url": SITE_URL + '/joke-of-the-day/', "category": "https://schema.org/EntertainmentEvent"} return layout(title, desc, body, '/joke-of-the-day/', '' % 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 @@ - +