-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlistMissingFiles.js
34 lines (30 loc) · 1.06 KB
/
listMissingFiles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const glob = require('glob')
const cheerio = require('cheerio')
const fs = require('fs')
const path = require('path')
const htmlFiles = glob.sync("**/*.html")
const seenPaths = {}
for (const file of htmlFiles) {
const html = fs.readFileSync(file, { encoding: 'utf8' })
const $ = cheerio.load(html)
for (const a of $("a").toArray()) {
const href = a.attribs.href
if (href && href.length > 1 && !href.match(/^http/)) {
const relPath = path.join(path.dirname(file), a.attribs.href.replace(/#.+/, ''))
if (!fs.existsSync(relPath) && !seenPaths[relPath]) {
console.log(relPath)
seenPaths[relPath] = true
}
}
}
for (const img of $("img").toArray()) {
const src = img.attribs.src
if (!src.match(/^http/)) {
const relPath = path.join(path.dirname(file), img.attribs.src)
if (!fs.existsSync(relPath) && !seenPaths[relPath]) {
console.log(relPath)
seenPaths[relPath] = true
}
}
}
}