-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml-validate.js
More file actions
executable file
·38 lines (35 loc) · 1.15 KB
/
html-validate.js
File metadata and controls
executable file
·38 lines (35 loc) · 1.15 KB
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
35
36
37
38
const { readFile } = require('fs/promises')
const klaw = require('klaw')
const path = require('path')
const skipFiles = [
'public/policies/index.html'
]
const validate = function (file) {
return readFile(file, { encoding: 'utf8' }).then(data => {
const validateUrl = 'https://validator.w3.org/nu/?out=json'
return fetch(validateUrl, {
method: 'POST',
body: data,
headers: {
'Content-Type': 'text/html; charset=utf-8'
}
}).then(response => response.json())
}).then(results => {
console.log('Validation results:', file)
results.messages.map(entry => {
return console.log(`${entry.type.toUpperCase()}: ${entry.message} (line: ${entry.lastLine})`)
})
console.log()
}).catch((err) => {
console.log('Failed to validate', file, err)
})
}
new Promise((resolve, reject) => {
const files = []
klaw('./public').on('data', (file) => {
const skipFile = skipFiles.some(s => s === path.relative(process.cwd(), file.path))
return file.path.endsWith('.html') && !skipFile ? files.push(file.path) : null
}).on('end', () => resolve(files))
}).then((files) => {
Promise.all(files.map(validate))
})