From cf113a59850862125b86ce1a58c117aa21341e07 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 5 Oct 2026 14:38:57 -0700 Subject: [PATCH] Show about metadata even without source or license, closes #512 The paragraph showing license, source and about links was only rendered if license or source were set, so "about" or "about_url" on their own were silently ignored. https://claude.ai/code/session_01StLUTmxEBqH1kExLLFri3c --- .../_description_source_license.html | 2 +- tests/test_html.py | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/datasette/templates/_description_source_license.html b/datasette/templates/_description_source_license.html index f852268f..bc93d279 100644 --- a/datasette/templates/_description_source_license.html +++ b/datasette/templates/_description_source_license.html @@ -7,7 +7,7 @@ {% endif %} {% endif %} -{% if metadata.license or metadata.license_url or metadata.source or metadata.source_url %} +{% if metadata.license or metadata.license_url or metadata.source or metadata.source_url or metadata.about or metadata.about_url %}

{% if metadata.license or metadata.license_url %}Data license: {% if metadata.license_url %} diff --git a/tests/test_html.py b/tests/test_html.py index 677ff8f4..4dbcf5cd 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -600,6 +600,52 @@ async def test_database_metadata_with_custom_sql(ds_client): # assert_footer_links(soup)TODO(alex) ensure +@pytest.mark.asyncio +@pytest.mark.parametrize( + "path,metadata,expected_text,expected_href", + ( + ("/", {"about": "Instance about"}, "About: Instance about", None), + ( + "/", + {"about_url": "https://example.com/"}, + "About: https://example.com/", + "https://example.com/", + ), + ( + "/data", + {"databases": {"data": {"about": "Database about"}}}, + "About: Database about", + None, + ), + ( + "/data/t", + {"databases": {"data": {"tables": {"t": {"about": "Table about"}}}}}, + "About: Table about", + None, + ), + ), +) +async def test_about_without_source_or_license( + path, metadata, expected_text, expected_href +): + # https://github.com/simonw/datasette/issues/512 + ds = Datasette(metadata=metadata) + db = ds.add_memory_database("test_about_without_source_or_license", name="data") + await db.execute_write("create table if not exists t (id integer primary key)") + response = await ds.client.get(path) + assert response.status_code == 200 + soup = Soup(response.text, "html.parser") + about_p = soup.select_one("section.content p:-soup-contains('About:')") + assert about_p is not None + # No leading separator, since there is no license or source before it + assert " ".join(about_p.text.split()) == expected_text + links = about_p.find_all("a") + if expected_href: + assert [a["href"] for a in links] == [expected_href] + else: + assert links == [] + + def test_database_download_for_immutable(): with make_app_client(is_immutable=True) as client: assert not client.ds.databases["fixtures"].is_mutable