@liascript/exporter 2.6.2--0.10.31 → 2.6.3--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.2--0.10.31",
3
+ "version": "2.6.3--0.10.31",
4
4
  "description": "A generic exporter for LiaScript",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -4,6 +4,7 @@ import * as IMS from './ims'
4
4
  import * as SCORM12 from './scorm12'
5
5
  import * as SCORM2004 from './scorm2004'
6
6
  import * as ANDROID from './android'
7
+ import * as RDF from './rdf'
7
8
 
8
9
  const fs = require('fs-extra')
9
10
  const path = require('path')
@@ -61,6 +62,36 @@ export function storeNext(collection: any, data: any) {
61
62
  return
62
63
  }
63
64
 
65
+ export function help() {
66
+ console.log('\nProject settings:')
67
+ console.log('')
68
+ console.log(
69
+ '--project-no-meta Disable the generation of meta information for OpenGraph and Twitter-cards.'
70
+ )
71
+ console.log('--project-no-rdf Disable the generation of json-ld.')
72
+ console.log(
73
+ '--project-no-categories Disable the filter for categories/tags.'
74
+ )
75
+ console.log(
76
+ '--project-category-blur Enable this and the categories will be blurred instead of deleted.'
77
+ )
78
+ console.log(
79
+ '--project-generate-scrom12 SCORM12 and pass additional scrom settings.'
80
+ )
81
+ console.log(
82
+ '--project-generate-scrom2004 SCORM2004 and pass additional scrom settings.'
83
+ )
84
+ console.log(
85
+ '--project-generate-ims IMS resources with additional config settings.'
86
+ )
87
+ console.log(
88
+ '--project-generate-pdf PDFs are automatically generated and added to every card.'
89
+ )
90
+ console.log(
91
+ '--project-generate-cache Only generate new files, if they do not exist.'
92
+ )
93
+ }
94
+
64
95
  export async function exporter(
65
96
  argument: {
66
97
  input: string
@@ -84,21 +115,41 @@ export async function exporter(
84
115
 
85
116
  let cards = ''
86
117
  const output = argument.output
118
+ const itemList: any[] = []
87
119
 
88
120
  for (let i = 0; i < json.collection.length; i++) {
89
121
  let course = json.collection[i]
90
122
 
91
123
  if (course.collection) {
92
124
  let subCards = ''
125
+ let subItemList: any[] = []
93
126
 
94
127
  for (let j = 0; j < course.collection.length; j++) {
128
+ let { html, json } = await toCard(argument, course.collection[j], true)
95
129
  subCards += `<div class='col-sm-6 col-md-4 col-lg-3 ${
96
130
  course.grid ? 'mb-3' : ''
97
131
  }'>
98
- ${await toCard(argument, course.collection[j], true)}
132
+ ${html}
99
133
  </div>`
134
+
135
+ subItemList.push(json)
136
+ }
137
+
138
+ const itemListElement = {
139
+ '@context': 'http://schema.org',
140
+ '@type': 'ItemList',
141
+ itemListElement: subItemList,
142
+ }
143
+
144
+ if (course.title) {
145
+ itemListElement['name'] = course.title
146
+ }
147
+ if (course.comment) {
148
+ itemListElement['description'] = course.comment
100
149
  }
101
150
 
151
+ itemList.push(itemListElement)
152
+
102
153
  cards += `
103
154
  <div class="col-12">
104
155
  <div class="card">
@@ -120,7 +171,10 @@ export async function exporter(
120
171
  } else if (course.html) {
121
172
  cards += "<div class='col-12'>" + course.html + '</div>'
122
173
  } else {
123
- cards += "<div class='col'>" + (await toCard(argument, course)) + '</div>'
174
+ let { html, json } = await toCard(argument, course)
175
+ cards += "<div class='col'>" + html + '</div>'
176
+
177
+ itemList.push(json)
124
178
  }
125
179
  }
126
180
 
@@ -144,10 +198,21 @@ export async function exporter(
144
198
  '</select>'
145
199
  }
146
200
 
201
+ const jsonLD = {
202
+ '@context': 'http://schema.org',
203
+ '@type': 'ItemList',
204
+ itemList: itemList,
205
+ }
206
+
147
207
  let title = json.title || 'LiaScript Course Index'
148
208
 
149
209
  if (json.title) {
150
- title = title.replace(/<[^>]+>/g, '')
210
+ title = cleanHTML(title).replace(/\s+/g, ' ').trim()
211
+ jsonLD['name'] = title
212
+ }
213
+
214
+ if (json.comment) {
215
+ jsonLD['description'] = cleanHTML(json.comment).replace(/\s+/g, ' ').trim()
151
216
  }
152
217
 
153
218
  const html = `<!DOCTYPE html>
@@ -155,6 +220,10 @@ export async function exporter(
155
220
  <head>
156
221
  <title>${title}</title>
157
222
 
223
+ <script type="application/ld+json">
224
+ ${JSON.stringify(jsonLD, null, 2)}
225
+ </script>
226
+
158
227
  ${
159
228
  json.icon
160
229
  ? '<link rel="icon" type="image/x-icon" href="' + json.icon + '">'
@@ -233,7 +302,7 @@ export async function exporter(
233
302
  </html>
234
303
  `
235
304
 
236
- helper.writeFile(output + '.html', helper.prettify(html))
305
+ helper.writeFile(output + '.html', helper.prettify(helper.prettify(html)))
237
306
  }
238
307
 
239
308
  async function moveFile(oldPath, newPath) {
@@ -282,7 +351,11 @@ function hash(url: string) {
282
351
  return value.startsWith('-') ? '0' + value.slice(1) : value
283
352
  }
284
353
 
285
- async function toCard(argument: any, course: any, small: boolean = false) {
354
+ async function toCard(
355
+ argument: any,
356
+ course: any,
357
+ small: boolean = false
358
+ ): Promise<{ html: string; json: any }> {
286
359
  // if other parameters are defined for a specific course
287
360
  // then they are treated
288
361
 
@@ -438,15 +511,20 @@ async function toCard(argument: any, course: any, small: boolean = false) {
438
511
  execSync('rm -rf tmp')
439
512
  }
440
513
 
441
- return card(
442
- small,
443
- course.data.lia.readme,
444
- overwrite(course.title, course.data.lia.str_title),
445
- overwrite(course.comment, course.data.lia.comment),
446
- tagList,
447
- downloads,
448
- overwrite(course.logo, course.data.lia.definition.logo)
449
- )
514
+ argument['rdf-url'] = course.data.lia.readme
515
+
516
+ return {
517
+ html: card(
518
+ small,
519
+ course.data.lia.readme,
520
+ overwrite(course.title, course.data.lia.str_title),
521
+ overwrite(course.comment, course.data.lia.comment),
522
+ tagList,
523
+ downloads,
524
+ overwrite(course.logo, course.data.lia.definition.logo)
525
+ ),
526
+ json: await RDF.parse(argument, course.data),
527
+ }
450
528
  }
451
529
 
452
530
  function card(
@@ -463,7 +541,7 @@ function card(
463
541
  apk?: string
464
542
  },
465
543
  img_url?: string
466
- ) {
544
+ ): string {
467
545
  let image = ''
468
546
 
469
547
  if (img_url) {
@@ -544,10 +622,6 @@ function card(
544
622
  '">Android APK</a></li>'
545
623
  : ''
546
624
  }
547
-
548
-
549
-
550
-
551
625
  </ul>
552
626
  </div>
553
627
  </div>
@@ -566,8 +640,7 @@ function card(
566
640
  ${tag_list}
567
641
  </div>
568
642
  ${footer}
569
- </div>
570
- `
643
+ </div>`
571
644
  }
572
645
 
573
646
  function stringToColor(str: string) {
package/src/export/rdf.ts CHANGED
@@ -170,7 +170,7 @@ export async function parse(
170
170
  doc = await licenseInformation(doc, argument, baseURL)
171
171
  doc = await jsonld.compact(doc, 'http://schema.org')
172
172
 
173
- return doc
173
+ return clean(doc)
174
174
  }
175
175
 
176
176
  /**
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.0--0.10.31')
25
+ console.log('version: 2.6.3--0.10.31')
26
26
  } else if (argv.h || argv.help) {
27
27
  help()
28
28
  } else if (argv.i || argv.input) {
@@ -309,37 +309,7 @@ function help() {
309
309
  '--pdf-omitBackground Hides default white background and allows capturing screenshots with transparency. Defaults to true. '
310
310
  )
311
311
 
312
- console.log('\nProject settings:')
313
- console.log('')
314
- console.log(
315
- '--project-no-meta Disable the generation of meta information for OpenGraph and Twitter-cards.'
316
- )
317
- console.log(
318
- '--project-no-categories Disable the filter for categories/tags.'
319
- )
320
- console.log(
321
- '--project-category-blur Enable this and the categories will be blurred instead of deleted.'
322
- )
323
-
324
- console.log(
325
- '--project-generate-scrom12 SCORM12 and pass additional scrom settings.'
326
- )
327
-
328
- console.log(
329
- '--project-generate-scrom2004 SCORM2004 and pass additional scrom settings.'
330
- )
331
-
332
- console.log(
333
- '--project-generate-ims IMS resources with additional config settings.'
334
- )
335
-
336
- console.log(
337
- '--project-generate-pdf PDFs are automatically generated and added to every card.'
338
- )
339
-
340
- console.log(
341
- '--project-generate-cache Only generate new files, if they do not exist.'
342
- )
312
+ PROJECT.help()
343
313
 
344
314
  RDF.help()
345
315
  }
@@ -408,6 +378,7 @@ function parseArguments() {
408
378
 
409
379
  // project settings
410
380
  'project-no-meta': argv['project-no-meta'],
381
+ 'project-no-rdf': argv['project-no-rdf'],
411
382
  'project-no-categories': argv['project-no-categories'],
412
383
  'project-category-blur': argv['project-category-blur'],
413
384
  'project-generate-pdf': argv['project-generate-pdf'],
package/index.html DELETED
@@ -1,73 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>OER - Kurssammlung</title>
5
- <link rel="icon" type="image/x-icon" href="https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Logo_TU_Bergakademie_Freiberg.svg/242px-Logo_TU_Bergakademie_Freiberg.svg.png">
6
- <meta property="og:type" content="website">
7
- <meta property="og:title" content="OER-Kurssammlung">
8
- <meta property="og:description" content="Sammlung der OER Inhalte der Arbeitsgruppe Softwareentwicklung und Robotik (TU Freiberg)">
9
- <meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Universitaetsbibliothek_Freiberg_Fassade.jpg/1024px-Universitaetsbibliothek_Freiberg_Fassade.jpg">
10
- <meta name="twitter:title" content="OER-Kurssammlung">
11
- <meta name="twitter:description" content="Sammlung der OER Inhalte der Arbeitsgruppe Softwareentwicklung und Robotik (TU Freiberg)">
12
- <meta name="twitter:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Universitaetsbibliothek_Freiberg_Fassade.jpg/1024px-Universitaetsbibliothek_Freiberg_Fassade.jpg">
13
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
14
- </head>
15
- <body>
16
- <main>
17
- <div class="container-fluid" style="background-size: cover; background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Universitaetsbibliothek_Freiberg_Fassade.jpg/1024px-Universitaetsbibliothek_Freiberg_Fassade.jpg'); background-position: center center; background-repeat: no-repeat;">
18
- <section class="py-5 text-center container">
19
- <div class="row py-lg-5">
20
- <div class="col-lg-6 col-md-8 mx-auto">
21
- <h1 class="fw-light">
22
- <span style="background-color: rgba(0,106,179,0.75); padding: 5px; color: white">OER - Kurssammlung</span>
23
- </h1>
24
- <p class="lead text-muted">
25
- <span style="color: rgb(0,106,179); background-color: rgba(255,255,255,0.75)">Sammlung der OER Inhalte der Arbeitsgruppe Softwareentwicklung und Robotik (TU Freiberg)</span>
26
- </p>
27
- </div>
28
- </div>
29
- </section>
30
- </div>
31
- <div class="album py-5 bg-light">
32
- <div class="container">
33
- <div class="row row-cols-1 row-cols-sm-1 row-cols-md-2 row-cols-xl-3 g-3">
34
- <div class="col-12">
35
- <div class="card">
36
- <div class="card-header">Prozedurale Programmierung</div>
37
- <div class="card-body">
38
- <p class="card-text">todo</p>
39
- <div class="row">
40
- <div class="col-sm-6 col-md-4 col-lg-3 mb-3">
41
- <div class="card shadow-sm m-1" style="height: 100%" data-category="">
42
- <div class="card-img-top" style="background-size: cover; height: 175px; background-image: url('https://raw.githubusercontent.com/TUBAF-IfI-LiaScript/VL_ProzeduraleProgrammierung/master/img/LogoCodeExample.png'); background-position: center center; background-repeat: no-repeat;"></div>
43
- <div class="card-body" style="transform: rotate(0);">
44
- <a href="https://liascript.github.io/course/?https://raw.githubusercontent.com/TUBAF-IfI-LiaScript/VL_ProzeduraleProgrammierung/master/00_Einfuehrung.md" class="link-dark stretched-link"><h6 class="card-title">Einführung</h6></a>
45
- <p class="card-text">
46
- <small>Einführung in die Programmierung für Nicht-Informatiker</small>
47
- </p>
48
- </div>
49
- </div>
50
- </div>
51
- </div>
52
- </div>
53
- </div>
54
- </div>
55
- </div>
56
- </div>
57
- </div>
58
- </main>
59
- <footer class="text-muted py-3">
60
- <div class="container">
61
- <p class="float-end">
62
- <a href="#">Back to top</a>
63
- </p>
64
- <p>
65
- Kontakt - Prof. Dr.-Ing. Sebastian Zug -
66
- <a href="https://tu-freiberg.de/fakult1/inf/professuren/softwaretechnologie-und-robotik">Lehrstuhl für Softwaretechnologie und Robotik</a>
67
- -
68
- <a href="mailto:Sebastian.Zug@informatik.tu-freiberg.de">Sebastian.Zug@informatik.tu-freiberg.de</a>
69
- </p>
70
- </div>
71
- </footer>
72
- </body>
73
- </html>