@saiballo/eleventy-plugin-validate-html 1.0.0 → 1.0.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/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  ## Installation
15
15
 
16
- Available on [npm](https://www.npmjs.com/package/eleventy-plugin-seo):
16
+ Available on [npm](https://www.npmjs.com/package/@saiballo/eleventy-plugin-validate-html):
17
17
 
18
18
  ```sh
19
19
  npm install @saiballo/eleventy-plugin-validate-html --save
@@ -24,7 +24,7 @@ Add the plugin to your `eleventy.config.js`:
24
24
  const pageValidation = require("@saiballo/eleventy-plugin-validate-html");
25
25
 
26
26
  module.exports = function(eleventyConfig) {
27
- eleventyConfig.addPlugin(pageValidation)
27
+ eleventyConfig.addPlugin(pageValidation)
28
28
  };
29
29
  ```
30
30
 
@@ -33,24 +33,32 @@ module.exports = function(eleventyConfig) {
33
33
  By default, the plugin checks all pages with the `.html` or `.htm` extensions. You can add or change extensions by providing a custom configuration. You can use "extensionList" parameter with a list of extensions (without the dot) separated by commas:
34
34
 
35
35
  ```js
36
- eleventyConfig.addPlugin(pageValidation, {
37
- "extensionList": "ext1,ext2"
38
- })
36
+ eleventyConfig.addPlugin(pageValidation, {
37
+ "extensionList": "ext1,ext2"
38
+ })
39
39
  ```
40
40
 
41
41
  This plugin relies on [html-validator](https://www.npmjs.com/package/html-validator). This allows you to use some configuration parameters from that package.
42
42
  The complete default configuration that you can override is:
43
43
 
44
44
  ```js
45
- eleventyConfig.addPlugin(pageValidation, {
46
- "validator": "WHATWG",
47
- "isLocal": false,
48
- "isFragment": false,
49
- "extensionList": "htm,html"
50
- })
45
+ eleventyConfig.addPlugin(pageValidation, {
46
+ "extensionList": "htm,html",
47
+ "validator": "WHATWG",
48
+ "isLocal": false,
49
+ "isFragment": false,
50
+ "ignore": [],
51
+ "whatwgConfig": {
52
+ "elements": [],
53
+ "rules": {}
54
+ }
55
+ })
51
56
  ```
52
57
  #### Parameters
53
58
  ```js
59
+ // as previously seen, it is a comma-separated list of extensions to check for validation
60
+ "extensionList": "htm,html"
61
+
54
62
  // Possible values: "WHATWG" | "https://html5.validator.nu"
55
63
  //"WHATWG" is recommended. it will validate against the WHATWG standards.
56
64
  "validator": "WHATWG"
@@ -59,15 +67,40 @@ The complete default configuration that you can override is:
59
67
  "isLocal": false
60
68
 
61
69
  // set this to true only if all your pages are not a complete document
62
- // if only certain pages are fragments, you can use "isFragment: true" in these pages as front matter data.
70
+ // if only certain pages are fragments, you can use "isFragment: true" in these pages as front matter data
63
71
  "isFragment": false
64
72
 
65
- // as previously seen, it is a comma-separated list of extensions to check for validation
66
- "extensionList": "htm,html"
73
+ // only for "WHATWG" validator. string or array of strings or rules (when using WHATWG) you want the checker to remove in the response. even partial text.
74
+ // e.g. "ignore": ["Mismatched close-tag, expected '</div>' but found '</body>'", "another partial error response text"]
75
+ "ignore": [],
76
+
77
+ // only for "WHATWG" validator. additional configuration for elements and rules
78
+ "whatwgConfig": {
79
+ "elements": [],
80
+ "rules": {}
81
+ }
82
+ ```
83
+ ## custom WHATWG configuration
84
+ ```js
85
+ // with this example, you add a custom tag called "customtag" to the valid tags in the validation. see https://html-validate.org/guide/metadata/simple-component.html
86
+ // additionally, you set the "heading-level" rule to "on" instead of "off". see https://html-validate.org/rules/index.html
87
+ "whatwgConfig": {
88
+ "elements": [
89
+ {
90
+ "customtag": {
91
+ "flow": true,
92
+ "phrasing": true
93
+ }
94
+ }
95
+ ],
96
+ "rules": {
97
+ "heading-level": "error"
98
+ }
99
+ }
67
100
  ```
68
101
  ## Front Matter Data
69
102
 
70
- Two parameters can be used as frontmatter data:
103
+ Two parameters can be used as front matter data:
71
104
 
72
105
  - `validateHtml: true|false` to enable or disable validation for individual pages.
73
106
  - `isFragment: true|false` to declare a document as a fragment.
package/main.js CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * @preserve
4
3
  * Filename: main.js
@@ -6,7 +5,7 @@
6
5
  * Created: 30/11/2024 (19:43:22)
7
6
  * Created by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
8
7
  *
9
- * Last update: 06/12/2024 (18:07:42)
8
+ * Last update: 12/12/2024 (10:47:22)
10
9
  * Updated by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
11
10
  *
12
11
  * Copyleft: 2024 - Tutti i diritti riservati
@@ -20,10 +19,15 @@ const pkg = require("./package.json");
20
19
  const toLog = require("./src/log.js");
21
20
 
22
21
  const defaultConfig = {
22
+ "extensionList": "htm,html",
23
23
  "validator": "WHATWG",
24
24
  "isLocal": false,
25
25
  "isFragment": false,
26
- "extensionList": "htm,html"
26
+ "ignore": [],
27
+ "whatwgConfig": {
28
+ "elements": [],
29
+ "rules": {}
30
+ }
27
31
  };
28
32
 
29
33
  module.exports = (eleventyconfig, config = {}) => {
package/package.json CHANGED
@@ -1,15 +1,25 @@
1
1
  {
2
2
  "name": "@saiballo/eleventy-plugin-validate-html",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "A plugin for 11ty which validates your site's pages after build.",
5
5
  "main": "main.js",
6
6
  "keywords": [
7
7
  "11ty",
8
8
  "eleventy",
9
9
  "eleventy-plugin",
10
- "html-validator"
10
+ "html-validator",
11
+ "@saiballo/html-validator-enhanced"
11
12
  ],
12
13
  "license": "MIT",
14
+ "author": {
15
+ "name": "Lorenzo \"Saibal\" Forti",
16
+ "email": "lorenzo.forti@gmail.com"
17
+ },
18
+ "homepage": "https://github.com/saiballo/eleventy-plugin-validate-html#readme",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/saiballo/eleventy-plugin-validate-html.git"
22
+ },
13
23
  "bugs": {
14
24
  "url": "https://github.com/saiballo/eleventy-plugin-validate-html"
15
25
  },
@@ -19,16 +29,13 @@
19
29
  "11ty": {
20
30
  "compatibility": ">=2.0.0"
21
31
  },
22
- "dependencies": {
23
- "html-validator": "^6.0.1",
24
- "front-matter": "^4.0.2"
32
+ "scripts": {
33
+ "refresh": "rm -rf node_modules && rm package-lock.json && npm install"
25
34
  },
26
- "author": {
27
- "name": "Lorenzo \"Saibal\" Forti",
28
- "email": "lorenzo.forti@gmail.com"
29
- },
30
- "repository": {
31
- "type": "git",
32
- "url": "https://github.com/saiballo/eleventy-plugin-validate-html.git"
35
+ "dependencies": {
36
+ "deep-extend": "^0.6.0",
37
+ "front-matter": "^4.0.2",
38
+ "@saiballo/html-validator-enhanced": "^1.0.0"
39
+
33
40
  }
34
- }
41
+ }
package/src/log.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * Created: 30/11/2024 (18:44:22)
6
6
  * Created by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
7
7
  *
8
- * Last update: 06/12/2024 (18:08:18)
8
+ * Last update: 07/12/2024 (21:02:39)
9
9
  * Updated by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
10
10
  *
11
11
  * Copyleft: 2024 - Tutti i diritti riservati
@@ -31,7 +31,7 @@ const toLog = (message = "OPS! An error has occured", type = "default") => {
31
31
  break;
32
32
  }
33
33
 
34
- const logLabel = `${logIcon} plugin-validate-html:`;
34
+ const logLabel = `${logIcon} plugin-validate-html -`;
35
35
 
36
36
  console.error(`${logLabel} ${message}`);
37
37
  };
package/src/validate.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * Created: 30/11/2024 (18:44:22)
6
6
  * Created by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
7
7
  *
8
- * Last update: 06/12/2024 (18:07:58)
8
+ * Last update: 12/12/2024 (11:03:09)
9
9
  * Updated by: Lorenzo Saibal Forti <lorenzo.forti@gmail.com>
10
10
  *
11
11
  * Copyleft: 2024 - Tutti i diritti riservati
@@ -15,8 +15,8 @@
15
15
 
16
16
  "use strict";
17
17
 
18
- const htmlValidator = require("html-validator");
19
- const fs = require("fs");
18
+ const htmlValidator = require("@saiballo/html-validator-enhanced");
19
+ const fs = require("node:fs");
20
20
  const fm = require("front-matter");
21
21
  const toLog = require("./log.js");
22
22
 
@@ -40,11 +40,29 @@ const getMatterData = (item) => {
40
40
  });
41
41
  };
42
42
 
43
+ // validator different from WHATWG and format "json" does not accept "ignore" option
44
+ const checkIgnoreOption = (pluginconfig) => {
45
+
46
+ const clonedConfig = {
47
+ ...pluginconfig
48
+ };
49
+
50
+ if (clonedConfig["validator"].toLowerCase() !== "whatwg") {
51
+
52
+ delete clonedConfig["ignore"];
53
+ }
54
+
55
+ return clonedConfig;
56
+ };
57
+
58
+
43
59
  const doValidation = async (pageList, pluginconfig) => {
44
60
 
45
61
  let checkedTotal = 0;
46
62
  let counterError = 0;
47
63
 
64
+ const pluginConfig = checkIgnoreOption(pluginconfig);
65
+
48
66
  /* eslint-disable no-await-in-loop */
49
67
  // avoid to send to validator an excessive amount of requests in parallel using await in loop
50
68
  for (const page of pageList) {
@@ -63,11 +81,11 @@ const doValidation = async (pageList, pluginconfig) => {
63
81
 
64
82
  if (typeof frontMatter["isFragment"] !== "undefined") {
65
83
 
66
- pluginconfig["isFragment"] = frontMatter["isFragment"];
84
+ pluginConfig["isFragment"] = frontMatter["isFragment"];
67
85
  }
68
86
 
69
87
  const validateConfig = {
70
- ...pluginconfig,
88
+ ...pluginConfig,
71
89
  // not want user can overwrites format option. must be json
72
90
  "format": "json",
73
91
  "data": fs.readFileSync(page["output"], "utf8")
@@ -77,7 +95,7 @@ const doValidation = async (pageList, pluginconfig) => {
77
95
  const result = await htmlValidator(validateConfig);
78
96
 
79
97
  // validator WHATWG
80
- if (pluginconfig["validator"] === "WHATWG" && result["isValid"] === false) {
98
+ if (pluginConfig["validator"].toLowerCase() === "whatwg" && result["isValid"] === false) {
81
99
 
82
100
  result["errors"].forEach((item, index) => {
83
101
 
@@ -88,7 +106,7 @@ const doValidation = async (pageList, pluginconfig) => {
88
106
  }
89
107
 
90
108
  // validator web url
91
- if (pluginconfig["validator"] !== "WHATWG" && result["messages"].length > 0) {
109
+ if (pluginConfig["validator"].toLowerCase() !== "whatwg" && result["messages"].length > 0) {
92
110
 
93
111
  result["messages"].forEach((item, index) => {
94
112
 
@@ -118,6 +136,8 @@ const doValidation = async (pageList, pluginconfig) => {
118
136
 
119
137
  } catch (err) {
120
138
 
139
+ counterError += 1;
140
+
121
141
  toLog(err, "error");
122
142
  }
123
143
  }