wiki-server 0.26.0-rc.1 → 0.26.0-rc.3
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/lib/page.js +35 -34
- package/lib/search.js +6 -2
- package/lib/server.js +44 -42
- package/package.json +1 -2
package/lib/page.js
CHANGED
|
@@ -14,8 +14,6 @@ const fs = require('fs')
|
|
|
14
14
|
const path = require('path')
|
|
15
15
|
const events = require('events')
|
|
16
16
|
|
|
17
|
-
const async = require('async')
|
|
18
|
-
|
|
19
17
|
const random_id = require('./random_id')
|
|
20
18
|
const synopsis = require('wiki-client/lib/synopsis')
|
|
21
19
|
|
|
@@ -379,43 +377,46 @@ module.exports = exports = argv => {
|
|
|
379
377
|
}
|
|
380
378
|
return collaborativeLinks
|
|
381
379
|
}
|
|
380
|
+
|
|
382
381
|
fs.readdir(argv.db, (e, files) => {
|
|
383
382
|
if (e) return cb(e)
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
383
|
+
const doSitemap = async file => {
|
|
384
|
+
return new Promise(resolve => {
|
|
385
|
+
itself.get(file, (e, page, status) => {
|
|
386
|
+
if (file.match(/^\./)) return resolve(null)
|
|
387
|
+
if (e || status === 404) {
|
|
388
|
+
console.log('Problem building sitemap:', file, 'e: ', e, 'status:', status)
|
|
389
|
+
return resolve(null) // Ignore errors in the pagehandler get.
|
|
390
|
+
}
|
|
391
|
+
let pageLinksMap
|
|
392
|
+
try {
|
|
393
|
+
pageLinksMap = page.story.reduce(extractPageLinks, new Map())
|
|
394
|
+
} catch (err) {
|
|
395
|
+
console.log(`METADATA *** ${wikiName} reduce to extract links on ${file} failed`, err.message)
|
|
396
|
+
pageLinksMap = []
|
|
397
|
+
}
|
|
398
|
+
//
|
|
399
|
+
const pageLinks = pageLinksMap.size > 0 ? Object.fromEntries(pageLinksMap) : undefined
|
|
400
|
+
|
|
401
|
+
resolve({
|
|
402
|
+
slug: file,
|
|
403
|
+
title: page.title,
|
|
404
|
+
date: editDate(page.journal),
|
|
405
|
+
synopsis: synopsis(page),
|
|
406
|
+
links: pageLinks,
|
|
407
|
+
})
|
|
409
408
|
})
|
|
410
409
|
})
|
|
411
410
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
411
|
+
|
|
412
|
+
Promise.all(files.map(doSitemap))
|
|
413
|
+
.then(sitemap => {
|
|
414
|
+
cb(
|
|
415
|
+
null,
|
|
416
|
+
sitemap.filter(item => item != null),
|
|
417
|
+
)
|
|
418
|
+
})
|
|
419
|
+
.catch(e => cb(e))
|
|
419
420
|
})
|
|
420
421
|
}
|
|
421
422
|
|
package/lib/search.js
CHANGED
|
@@ -169,8 +169,12 @@ module.exports = exports = argv => {
|
|
|
169
169
|
.replace(/<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g, ' ')
|
|
170
170
|
.replace(/<(?:[^>])+>/g, ' ')
|
|
171
171
|
.replace(/(https?:.*?)(?=\p{White_Space}|\p{Quotation_Mark}|$)/gu, match => {
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
try {
|
|
173
|
+
const myUrl = new URL(match)
|
|
174
|
+
return myUrl.hostname
|
|
175
|
+
} catch {
|
|
176
|
+
return ' '
|
|
177
|
+
}
|
|
174
178
|
})
|
|
175
179
|
.replace(/[\p{P}\p{Emoji}\p{Symbol}}]+/gu, ' ')
|
|
176
180
|
.replace(/[\p{White_Space}\n\t]+/gu, ' ')
|
package/lib/server.js
CHANGED
|
@@ -28,7 +28,6 @@ const { pipeline } = require('node:stream/promises')
|
|
|
28
28
|
// From npm
|
|
29
29
|
const express = require('express')
|
|
30
30
|
const hbs = require('express-hbs')
|
|
31
|
-
const async = require('async')
|
|
32
31
|
const f = require('flates')
|
|
33
32
|
|
|
34
33
|
const createDOMPurify = require('dompurify')
|
|
@@ -511,32 +510,34 @@ module.exports = exports = argv => {
|
|
|
511
510
|
// Send an array of pages currently in the recycler via json
|
|
512
511
|
app.get('/recycler/system/slugs.json', authorized, (req, res) => {
|
|
513
512
|
fs.readdir(argv.recycler, (e, files) => {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
513
|
+
if (e) {
|
|
514
|
+
return res.e(e)
|
|
515
|
+
}
|
|
516
|
+
const doRecyclermap = async file => {
|
|
517
|
+
return new Promise(resolve => {
|
|
518
|
+
const recycleFile = 'recycler/' + file
|
|
519
|
+
pagehandler.get(recycleFile, (e, page, status) => {
|
|
520
|
+
if (e || status === 404) {
|
|
521
|
+
console.log('Problem building recycler map:', file, 'e: ', e)
|
|
522
|
+
// this will leave an undefined/empty item in the array, which we will filter out later
|
|
523
|
+
return resolve(null)
|
|
524
|
+
}
|
|
525
|
+
resolve({
|
|
526
|
+
slug: file,
|
|
527
|
+
title: page.title,
|
|
528
|
+
})
|
|
525
529
|
})
|
|
526
530
|
})
|
|
527
531
|
}
|
|
528
532
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
recyclermap = recyclermap.filter(el => !!el)
|
|
538
|
-
res.send(recyclermap)
|
|
539
|
-
})
|
|
533
|
+
Promise.all(files.map(doRecyclermap))
|
|
534
|
+
.then(recyclermap => {
|
|
535
|
+
recyclermap = recyclermap.filter(el => !!el)
|
|
536
|
+
res.send(recyclermap)
|
|
537
|
+
})
|
|
538
|
+
.catch(error => {
|
|
539
|
+
res.e(error)
|
|
540
|
+
})
|
|
540
541
|
})
|
|
541
542
|
})
|
|
542
543
|
|
|
@@ -642,28 +643,29 @@ module.exports = exports = argv => {
|
|
|
642
643
|
if (e) {
|
|
643
644
|
return res.e(e)
|
|
644
645
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
(stub, done) => {
|
|
646
|
+
const pagePromises = sitemap.map(stub => {
|
|
647
|
+
return new Promise((resolve, reject) => {
|
|
648
648
|
pagehandler.get(stub.slug, (error, page) => {
|
|
649
|
-
if (
|
|
650
|
-
return
|
|
649
|
+
if (error) {
|
|
650
|
+
return reject(error)
|
|
651
651
|
}
|
|
652
|
-
|
|
652
|
+
resolve({ slug: stub.slug, page })
|
|
653
653
|
})
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
)
|
|
665
|
-
}
|
|
666
|
-
|
|
654
|
+
})
|
|
655
|
+
})
|
|
656
|
+
|
|
657
|
+
Promise.all(pagePromises)
|
|
658
|
+
.then(pages => {
|
|
659
|
+
const pageExport = pages.reduce((dict, combined) => {
|
|
660
|
+
dict[combined.slug] = combined.page
|
|
661
|
+
return dict
|
|
662
|
+
}, {})
|
|
663
|
+
// TODO: this fails for a very large site
|
|
664
|
+
res.json(pageExport)
|
|
665
|
+
})
|
|
666
|
+
.catch(error => {
|
|
667
|
+
res.e(error)
|
|
668
|
+
})
|
|
667
669
|
})
|
|
668
670
|
})
|
|
669
671
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wiki-server",
|
|
3
3
|
"description": "A Federated Wiki Server",
|
|
4
|
-
"version": "0.26.0-rc.
|
|
4
|
+
"version": "0.26.0-rc.3",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ward Cunningham",
|
|
7
7
|
"email": "ward@c2.com",
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"jon r <jon@allmende.io>"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"async": "^3.2.4",
|
|
34
33
|
"body-parser": "^2.2.0",
|
|
35
34
|
"client-sessions": "^0.8.0",
|
|
36
35
|
"coffeescript": "^2.5.0",
|