Skip to content

Translate non-JSON-LD RDF formats to JSON-LD for HTML data island embedding #344

Description

@melvincarvalho

Summary

When serving the HTML view of a stored resource, JSS embeds a JSON-LD data island
in the response. This works for resources stored as JSON-LD. For resources stored
in Turtle or N3, the data island is currently empty.

This issue tracks adding server-side format translation so all stored RDF formats
populate the data island uniformly.

Current Behavior

Stored content type Data island populated?
application/ld+json yes
text/turtle no
text/n3 no

Proposed Behavior

In the HTML path of src/handlers/resource.js:

  1. If stored content is JSON-LD → embed as-is (current behavior).
  2. If stored content is Turtle / N3 → parse (n3.js) and serialize to JSON-LD,
    then embed.
  3. If parse/serialize fails → omit the data island; existing fetch-based render
    continues to work.

Scope

  • src/handlers/resource.js: select translation path by content type.
  • Small helper, e.g. src/rdf/toJsonLd.js.
  • Tests:
    • JSON-LD passthrough unchanged
    • Turtle → JSON-LD embedded correctly
    • N3 → JSON-LD embedded correctly
    • Parse-failure falls back cleanly (no broken HTML)

Out of Scope

  • Client-side consumption of the data island.
  • application/rdf+xml (rare; fall back to network fetch).
  • Streaming for very large resources (already capped at 256 KB).

Acceptance

  • HTML view of a Turtle-stored resource emits a non-empty
    <script type="application/ld+json" id="dataisland">.
  • Same for N3.
  • JSON-LD passthrough behavior unchanged.
  • Existing tests remain green; new tests cover the three cases above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions