Repository navigation
Server-render schema.org Dataset JSON-LD on dataset pages - #205
Merged
Merged
Conversation
Pure mapping from catalog row + metadata.json + landing payload to a schema.org Dataset object, plus a safe script-tag serializer. Every field degrades to omission on sparse/null data instead of throwing. Tests cover a fully-populated nm* dataset, an OpenNeuro-derived on* dataset, a sparse real dataset with nulls throughout, a synthetic missing-DOI case, and </script> escaping. Fixtures are real captures from api.nemar.org / data.nemar.org (2026-07-29).
Base.astro grows an optional jsonLdScript prop that drops pre-escaped JSON-LD into a <script type="application/ld+json"> tag; the layout stays generic and carries no mapping logic. The dataset detail page builds the script via datasetJsonLdScript with the catalog row, metadata, provenance, and resolved version it already fetched.
Deploying nemar-website with
|
| Latest commit: |
4a46d6a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c166a8e3.nemar-website.pages.dev |
| Branch Preview URL: | https://feature-issue-156-dataset-js.nemar-website.pages.dev |
This was referenced Jul 29, 2026
Contributor
Author
|
Thanks — the end-to-end injection probe is the check that mattered, and building a real Astro page against The live-catalog sweep is also useful beyond this PR: confirming zero No changes made here. The two observations are filed rather than carried forward, per the no-deferred-findings rule:
|
This was referenced Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #156.
Scope
The issue was written against the legacy nemar.org ("client-rendered single-page app"); that premise is stale on this redesigned, server-rendered Astro build.
src/pages/dataset/[id].astroalready does the SSR fetch fan-out (catalog row + metadata.json + landing payload) -- this PR only adds the JSON-LD emission from data the page already has.In scope / done:
DatasetJSON-LD in the server-rendered HTML (src/lib/jsonld.ts, wired throughBase.astro's newjsonLdScriptprop).license,conditionsOfAccess, required citations, and thedata.nemar.orgdownload path are present and correct (see field notes below).name,description,identifier(concept DOI),license/conditionsOfAccess,creator,citation,measurementTechnique,keywords,includedInDataCatalog, and adistribution(DataDownload) withcontentUrl/contentSize/the nemar-cli access note.Explicitly out of scope (issue stays open for these):
dataset.jsonld/summary.jsontodata.nemar.org/<id>/latest/. That's backend work in nemar-cli/nemar-tools, not this repo -- AGENTS.md is explicit about not reimplementing the backend here.llms.txt, an AI-awarerobots.txt, a siteAGENTS.mdfor nemar.org -- called out as follow-ups in the issue itself.What's new
src/lib/jsonld.ts-- pure builder (buildDatasetJsonLd) + safe serializer (datasetJsonLdScript). No network calls; takes exactly what the page already fetched.src/lib/jsonld.test.ts+test/fixtures/jsonld-*.json-- 36 tests against three real captures (nm000103, on007753, nm000154) plus synthetic edge cases for missing-DOI and</script>escaping.Base.astrogrows an optionaljsonLdScriptprop (pre-escaped string in,set:htmlinto a<script type="application/ld+json">tag). Layout stays generic; all mapping logic lives insrc/lib/jsonld.ts.dataset/[id].astrobuilds the script from the catalog row, metadata, provenance, and resolved version it already has in scope, then passes it to<Base>.Escaping (the actual security consideration)
escapeJsonLdForScriptreplaces<,>,&, U+2028, and U+2029 with\uXXXXJSON string escapes before the payload goes intoset:html. Since\uXXXXis a valid JSON string escape, this round-trips throughJSON.parseunchanged -- it only changes what the HTML parser sees, so a dataset name/description containing</script>cannot break out. Tested directly (escapeJsonLdForScriptunit tests) and end-to-end (a hostileEvil</script><script>alert(1)</script>Datasetname embedded in a real<script>...</script>wrapper, asserting exactly one</script>substring survives -- the real closing tag).Field mapping notes / discrepancies found
identifier(concept DOI): the OSCAR reference (dataset-nm000103.jsonld) uses the Zenodo DOI (10.5281/zenodo.17306881) asidentifier. Real NEMAR data mints its own concept DOI via EZID at dataset creation (10.82901/nemar.<id>, exposed ascatalogRow.concept_doi/metadata.external_links.dataset_doi) -- that's what the site already uses everywhere else (citations, ProvenanceToggle), so it's what we use asidentifierhere too. The Zenodo DOI is real (nm000103 does have one, via arelated_identifiersentry withrelation_type: "IsIdenticalTo") and is surfaced assameAsinstead.isBasedOn: the OSCAR reference hardcodes"https://openneuro.org"for every dataset. Real data distinguishes NEMAR-native (nm*) from OpenNeuro-derived (on*) datasets, and for derived ones the site already resolves the specific source dataset id viadetectProvenance()(reused, not duplicated). We emithttps://openneuro.org/datasets/ds007753-style links, and omitisBasedOnentirely for native datasets.citation: reusesdatasetCitation()fromcite.ts(per AGENTS.md, don't duplicate citation formatting) for the dataset's own APA self-citation, plus any DOIs the metadata marksrelation_type: "References". Deliberately excludes"IsReferencedBy"DOIs -- on007753's related_identifiers are allIsReferencedBy(papers that cite the dataset, not papers to cite when using it); including them ascitationwould misrepresent the relationship. Covered by a dedicated test.metadata.json'skeywordsships as{term: string}[]objects, butneuroschema.tsdeclareskeywords: string[]. Already known/handled defensively inDetailRail.astro(comment + runtime check) and mirrored the same way here.Funding.funderinneuroschema.tsdoesn't match the real API'sfunder_namefield -- confirmed this actually breaks production today (empty Funding chips on nm000103's live page). Filed as Funding.funder type doesn't match API: empty funder chips on dataset pages #204; not touched in this PR (JSON-LD doesn't surfacefunding).Verification
bun run test-- 976/976 green (36 new).bun run typecheck-- 0 errors.bun run lint-- clean.bun run dev+ plaincurl(no JS) against/dataset/nm000103,/dataset/on007753,/dataset/nm000154-- JSON-LD present in the raw server-rendered HTML in all three, parses cleanly, degrades correctly on the sparse case (nolicense,description,creator,keywords, orsameAskeys -- omitted, nevernull)./dataset/ds007753still 301s to/dataset/on007753before reaching this code, unchanged -- confirms every legacy OpenNeuro pointer currently in the catalog already has anon*mirror (100% migrated), so there is no liveds*-only page to test against right now. Usednm000154(real, captured 2026-07-29) as the closest real analogue of the sparse null-heavy contract AGENTS.md describes fords*/unsyncedon*rows.<-escaped) through validator.schema.org's "Code snippet" tester for both nm000103 (fully populated) and nm000154 (sparse) -- both report 0 errors, 0 warnings, and every field decodes back to the correct unescaped value (verified the ampersand in the citation string and the<files>placeholder in the distribution description both round-trip correctly).Datasets tested
nm000103-- NEMAR-native, fully populated (8 authors with ORCID, 8 keywords, CC-BY-NC-SA, Data Descriptor citations, Zenodo sameAs).on007753-- OpenNeuro-derived, CC0,isBasedOnresolves to the specificds007753source.nm000154-- sparse real dataset: null description, null license, empty authors/keywords/related_identifiers. Covers "missing license" from real data; see theds*note above for why this stands in for the sparse/no-mirror case.