Add HTML validation utility

This commit is contained in:
Ben Edgington
2022-10-12 11:03:28 +01:00
parent 72a2508726
commit a22dd7ec51
3 changed files with 26 additions and 3 deletions

View File

@@ -66,7 +66,7 @@ Instead of building and serving, you can run `gatsby develop` and point your bro
The entire text for the book is in the _src/book.md_ file. Everything under _src/md/pages_ is auto-generated and any changes there will be lost.
There are various npm script commands to help with building:
There are various npm script commands to help with building and testing:
- `npm run clean` runs `gatsby clean`.
- Do this after adding new graphics or if anything weird happens.
@@ -79,6 +79,8 @@ There are various npm script commands to help with building:
- Visit http://localhost:9000/bellatrix/ to see the result.
- `npm run links` checks external links.
- Checking links to GitHub it will fail due to rate-limiting unless you supply GitHub credentials.
- `npm run spell` can be used to maintain the list of spellings.
- `npm run valid` submits a page to the [W3C markup validation service](https://validator.w3.org/) and lists any issues above `info` level.
## How to

20
bin/util/validate.js Normal file
View File

@@ -0,0 +1,20 @@
const axios = require('axios')
const fs=require('fs')
module.exports.validateHtml = (fileName) => {
const file = fs.readFileSync(fileName)
axios({
method: 'post',
url: 'https://validator.w3.org/nu/?out=json',
data: file,
headers: {
'Content-Type': 'text/html'
},
maxContentLength: Infinity,
maxBodyLength: Infinity
}).then(function (response) {
console.log(response.data.messages.filter(m => m.type !== 'info'));
})
}

View File

@@ -6,14 +6,15 @@
"author": "Ben Edgington",
"keywords": [],
"scripts": {
"develop": "gatsby develop",
"devel": "gatsby develop",
"start": "gatsby develop",
"build": "gatsby build --prefix-paths",
"serve": "gatsby serve --prefix-paths",
"clean": "gatsby clean",
"check": "node -e 'require(\"./bin/build/prebuild\").runChecks()'",
"links": "bin/util/urlcheck.sh src/book.md",
"spell": "bin/util/check_spellings_list.sh"
"spell": "bin/util/check_spellings_list.sh",
"valid": "node -e 'require(\"./bin/util/validate\").validateHtml(\"public/index.html\")'"
},
"dependencies": {
"gatsby": "^4.24.4",