diff --git a/test/e2e/test_json.py b/test/e2e/test_json.py index 08db8e510..00dec5858 100644 --- a/test/e2e/test_json.py +++ b/test/e2e/test_json.py @@ -71,7 +71,7 @@ def get_json(api: APIRequestContext, path: str) -> dict: def json_twin(url: str) -> str: """ - Path of a page's JSON twin: its URL with .json for the trailing slash (refs carry no json_url) + Path of a page's JSON twin: its URL with .json for the trailing slash (only episodes.json entries carry json_url) """ return urlparse(url).path.rstrip("/") + ".json" @@ -245,8 +245,9 @@ def test_show_json_links_resolve(api_request_context: APIRequestContext, show: S """ latest = get_json(api_request_context, f"/show/{show.slug}/show.json")["latest_episode"] oldest = get_json(api_request_context, f"/show/{show.slug}/episodes.json")["episodes"][-1] + assert "json_url" not in latest, "a ref outside episodes.json carries no json_url" + assert urlparse(oldest["json_url"]).path == json_twin(oldest["url"]), "episodes.json entries link their JSON twin" for ref in (latest, oldest): - assert "json_url" not in ref, "an episode's JSON is its url with .json" episode = get_json(api_request_context, json_twin(ref["url"])) assert episode["type"] == "episode" assert episode["episode"] == ref["episode"] @@ -261,7 +262,7 @@ def test_every_episode_json_is_valid(api_request_context: APIRequestContext, sho entries = get_json(api_request_context, f"/show/{show.slug}/episodes.json")["episodes"] problems = [] for entry in entries: - path = json_twin(entry["url"]) + path = urlparse(entry["json_url"]).path response = api_request_context.get(path) content_type = response.headers.get("content-type", "") if response.status != 200 or not content_type.startswith("application/json"): diff --git a/test/e2e/test_llms.py b/test/e2e/test_llms.py index f6b137a27..d6baf7dc4 100644 --- a/test/e2e/test_llms.py +++ b/test/e2e/test_llms.py @@ -333,7 +333,8 @@ def test_show_episodes_json(api_request_context: APIRequestContext, show: Show): for ep in data["episodes"]: slug = ep["url"].rstrip("/").rsplit("/", 1)[-1] - assert set(ep) == {"episode", "title", "date", "url", "markdown_url"}, f"{slug}: {sorted(ep)} (no json_url: it is the url with .json)" + assert set(ep) == {"episode", "title", "date", "url", "json_url", "markdown_url"}, f"{slug}: {sorted(ep)}" + assert re.fullmatch(rf"{HOST}/show/{show.slug}/{re.escape(slug)}\.json", ep["json_url"]), ep["json_url"] assert ep["title"], f"{slug}: empty title" assert re.fullmatch(rf"{HOST}/show/{show.slug}/{re.escape(slug)}/", ep["url"]), ep["url"] assert re.fullmatch(rf"{HOST}/show/{show.slug}/{re.escape(slug)}\.md", ep["markdown_url"]), ep["markdown_url"] diff --git a/themes/jb/layouts/show/list.episodes.json b/themes/jb/layouts/show/list.episodes.json index 170214da9..1ae0568f6 100644 --- a/themes/jb/layouts/show/list.episodes.json +++ b/themes/jb/layouts/show/list.episodes.json @@ -7,6 +7,6 @@ "count": {{ len $eps }}, "episodes": [ {{ range $i, $p := $eps.ByDate.Reverse }}{{ if $i }}, -{{ end }} {{ partial "json-episode-ref.html" $p | jsonify (dict "noHTMLEscape" true) }}{{ end }} +{{ end }} {{ $ref := partial "json-episode-ref.html" $p }}{{ with $p.OutputFormats.Get "json" }}{{ $ref = merge $ref (dict "json_url" .Permalink) }}{{ end }}{{ $ref | jsonify (dict "noHTMLEscape" true) }}{{ end }} ] }