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
This commit is contained in:
Simon Willison 2026-10-05 14:38:57 -07:00 • committed by GitHub
commit cf113a5985
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 1 deletions

View file

@ -7,7 +7,7 @@
{% endif %}
</div>
{% 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 %}
<p>
{% if metadata.license or metadata.license_url %}Data license:
{% if metadata.license_url %}

View file

@ -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