@liascript/exporter 2.6.3--0.10.31 → 2.6.5--0.10.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liascript/exporter",
3
- "version": "2.6.3--0.10.31",
3
+ "version": "2.6.5--0.10.31",
4
4
  "description": "A generic exporter for LiaScript",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -136,7 +136,6 @@ export async function exporter(
136
136
  }
137
137
 
138
138
  const itemListElement = {
139
- '@context': 'http://schema.org',
140
139
  '@type': 'ItemList',
141
140
  itemListElement: subItemList,
142
141
  }
@@ -199,9 +198,9 @@ export async function exporter(
199
198
  }
200
199
 
201
200
  const jsonLD = {
202
- '@context': 'http://schema.org',
201
+ '@context': 'http://schema.org/',
203
202
  '@type': 'ItemList',
204
- itemList: itemList,
203
+ itemListElement: removeContext(itemList),
205
204
  }
206
205
 
207
206
  let title = json.title || 'LiaScript Course Index'
@@ -305,6 +304,18 @@ export async function exporter(
305
304
  helper.writeFile(output + '.html', helper.prettify(helper.prettify(html)))
306
305
  }
307
306
 
307
+ function removeContext(obj) {
308
+ for (let key in obj) {
309
+ if (obj.hasOwnProperty(key)) {
310
+ if (key === '@context') {
311
+ delete obj[key]
312
+ } else if (typeof obj[key] === 'object') {
313
+ removeContext(obj[key])
314
+ }
315
+ }
316
+ }
317
+ return obj
318
+ }
308
319
  async function moveFile(oldPath, newPath) {
309
320
  // 1. Create the destination directory if it does not exist
310
321
  // Set the `recursive` option to `true` to create all the subdirectories
package/src/export/rdf.ts CHANGED
@@ -50,7 +50,7 @@ export async function exporter(
50
50
  },
51
51
  json
52
52
  ) {
53
- let doc = parse(argument, json)
53
+ let doc = await parse(argument, json)
54
54
 
55
55
  if (argument['rdf-format'] === 'n-quads') {
56
56
  const nquads = await jsonld.toRDF(doc, { format: 'application/n-quads' })
@@ -98,11 +98,19 @@ export async function script(
98
98
  },
99
99
  json
100
100
  ) {
101
+ let doc = await parse(argument, json)
102
+ doc = await jsonld.compact(doc, 'http://schema.org/')
103
+ doc = clean(doc)
104
+
101
105
  return `<script type="application/ld+json">
102
- ${JSON.stringify(await parse(argument, json), null, 2)}
106
+ ${JSON.stringify(doc, null, 2)}
103
107
  </script>`
104
108
  }
105
109
 
110
+ export async function compact(doc: any) {
111
+ return await jsonld.compact(doc, 'http://schema.org/')
112
+ }
113
+
106
114
  export async function parse(
107
115
  argument: {
108
116
  input: string
package/src/index.ts CHANGED
@@ -22,7 +22,7 @@ import fetch from 'node-fetch'
22
22
 
23
23
  // -------------------------------Main Execution-------------------------------
24
24
  if (argv.v || argv.version) {
25
- console.log('version: 2.6.3--0.10.31')
25
+ console.log('version: 2.6.5--0.10.31')
26
26
  } else if (argv.h || argv.help) {
27
27
  help()
28
28
  } else if (argv.i || argv.input) {