Skip to content

Commit

Permalink
fix(JSON-LD): Use versioned URL for context
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Jan 17, 2020
1 parent 13f69c3 commit 8b0e153
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions ts/bindings/jsonld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ import fromEntries from 'object.fromentries'
import path from 'path'
import { readSchemas } from '../helpers'

/**
* Get the Schema major version for use in generated URLs
*/
const VERSION_MAJOR = fs
.readJSONSync(path.join(__dirname, '..', '..', 'package.json'))
.version.split('.')[0]

/**
* The base URL for the Stencila JSON-LD context.
*
* This gets prefixed to all keys during JSON-LD expansion
* so the trailing slash is important so that for e.g.
* `CodeChunk` gets expanded to `http://schema.stenci.la/v0/jsonld/CodeChunk`
* (which in gets redirected to `https://unpkg.com/@stencila/schema@0.32.1/dist/CodeChunk.jsonld`)
*/
const STENCILA_CONTEXT_URL = `http://schema.stenci.la/v${VERSION_MAJOR}/jsonld/`

/**
* The destination directory for generated JSON-LD files
*/
const DEST_DIR = path.join(__dirname, '..', '..', 'public')

export const build = async (): Promise<void> => {
Expand Down Expand Up @@ -102,11 +122,11 @@ export const build = async (): Promise<void> => {
schema: 'http://schema.org/',
bioschemas: 'http://bioschemas.org',
codemeta: 'http://doi.org/10.5063/schema/codemeta-2.0',
stencila: 'http://schema.stenci.la/',
stencila: STENCILA_CONTEXT_URL,

// Define that in this context all terms derive from this vocabulary
// (and so do not need prefixing)
'@vocab': 'http://schema.stenci.la/',
'@vocab': STENCILA_CONTEXT_URL,

// Types and properties added in alphabetical order after this e.g
// "schema:AudioObject": {"@id": "schema:AudioObject"},
Expand Down Expand Up @@ -140,7 +160,7 @@ export const build = async (): Promise<void> => {
{
'@context': {
schema: 'http://schema.org/',
stencila: 'http://schema.stenci.la/'
stencila: STENCILA_CONTEXT_URL
},
...entry
},
Expand Down

0 comments on commit 8b0e153

Please sign in to comment.