Skip to content

feat(pages): serve resource pages as RDF by content negotiation and embedded JSON-LD - #712

Merged
tkuhn merged 1 commit into
masterfrom
feat/710-rdf-conneg-jsonld
Sep 14, 2026
Merged

tkuhn merged 1 commit into
masterfrom
feat/710-rdf-conneg-jsonld

Conversation

@tkuhn

@tkuhn tkuhn commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Closes #710.

Space, user, maintained-resource and part pages now offer their RDF three ways:

  • Content negotiation: an Accept header that prefers an RDF media type gets a 303 to /download-rdf in the matching format. TriG, N-Quads, JSON-LD and TriX carry the full nanopublications; Turtle, N-Triples and RDF/XML carry the assertions only. Wildcard and browser headers keep getting HTML. Both answers carry Vary: Accept.
  • Embedded JSON-LD: the page head has a <script type="application/ld+json"> block with the resource's declaring assertion(s), @id = the resource IRI, plus a void:dataDump link to the full TriG download. < is escaped so a text value cannot close the block.
  • Alternate links: one <link rel="alternate" type="..."> per download format.

Implementation: RdfNegotiation (media type → download variant), RdfSource (download URLs + JSON-LD serialization), a getRdfSource() hook and redirectIfRdfRequested() helper on NanodashPage, and a few lines in each of the four pages. Microdata/RDFa attributes are deliberately not used.

Tested with unit tests for the negotiation and the serialization, WicketTester tests for the redirect, headers and head markup, and end to end on a local instance with curl and the Comunica command-line client.

Note: Comunica asks for N-Quads, so the triples arrive inside the nanopub graphs; a plain ?s ?p ?o pattern matches nothing there, a GRAPH ?g { } pattern does.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EHzVZYfuW9yuZrjYvG1rnh

…mbedded JSON-LD

Space, user, maintained-resource and part pages answer an Accept header
that prefers an RDF media type with a 303 to the download page in the
matching format: graph-aware formats carry the full nanopublications,
triple-only formats the assertions. Both the redirect and the HTML
response vary on Accept.

The HTML head links every download format as an alternate and embeds
the resource's declaring assertions as a JSON-LD block, identified by
the resource IRI and pointing at the full download via void:dataDump,
so that HTML-reading Linked Data tools and search engines find the RDF.

Closes #710

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EHzVZYfuW9yuZrjYvG1rnh
@tkuhn
tkuhn merged commit eec37bb into master Sep 14, 2026
8 checks passed
@tkuhn
tkuhn deleted the feat/710-rdf-conneg-jsonld branch September 14, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serve RDF for resource pages: content negotiation and embedded JSON-LD

1 participant