-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Structured interoperable export.
- Loading branch information
1 parent
97f8c8b
commit 6d68976
Showing
5 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { visit } from "unist-util-visit"; | ||
import { VFile } from "vfile"; | ||
import { TermDefinitionNode } from "./ast/with/term-definition.js"; | ||
|
||
const LD_CONTEXT = { | ||
"@context": { | ||
"@vocab": "https://about-code.github.io/vocab/glossarify-md/2021/10/#" | ||
,"skos": "http://www.w3.org/2004/02/skos/core#" | ||
,"dc": "http://purl.org/dc/terms/" | ||
,"uri": "@id" | ||
,"type": "@type" | ||
,"title": "dc:title" | ||
,"terms": { | ||
"@container": "@index" | ||
,"@reverse": "skos:inScheme" | ||
} | ||
,"Glossary": "skos:ConceptScheme" | ||
,"Term": { | ||
"@id": "skos:Concept" | ||
,"@context": { | ||
"label": "skos:prefLabel" | ||
,"definition": "skos:definition" | ||
,"aliases": { | ||
"@id": "skos:altLabel" | ||
,"@container": "@set" | ||
} | ||
,"abstract": "dc:abstract" | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export function exporter(context) { | ||
const { i18n } = context.conf; | ||
return (tree, vFile) => { | ||
if (vFile.isGlossary !== true) { | ||
return; | ||
} | ||
if (! vFile.export) { | ||
return; | ||
} | ||
const output = { | ||
...LD_CONTEXT | ||
,type: "Glossary" | ||
,uri: vFile.uri | ||
,title: vFile.title | ||
,language: i18n.locale | ||
,terms: {} | ||
}; | ||
output["@context"]["@language"] = i18n.locale; | ||
visit(tree, TermDefinitionNode.type, (node) => { | ||
output.terms[node.uri] = { | ||
type: "Term" | ||
,uri: node.uri | ||
,label: node.value | ||
,definition: node.longDesc | ||
,abstract: node.shortDesc | ||
,aliases: [... node.aliases ] | ||
}; | ||
}); | ||
context.vFiles.push(new VFile({ | ||
path: vFile.export | ||
,value: JSON.stringify(output, null, 2) | ||
})); | ||
}; | ||
} |
This file contains 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
This file contains 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