@dukebot/astro-html-validator 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dukebot
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # astro-html-validator
2
+
3
+ Validate Astro-generated HTML output (`dist`) to catch common technical SEO issues:
4
+
5
+ - broken internal links,
6
+ - missing or invalid JSON-LD blocks,
7
+ - missing SEO metadata (`title`, `description`, `og:*`, etc.).
8
+
9
+ You can use it as:
10
+
11
+ 1. a **CLI** (great for CI/CD),
12
+ 2. a **reusable Node library** shared across projects.
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install -D @dukebot/astro-html-validator
20
+ ```
21
+
22
+ ---
23
+
24
+ ## CLI usage
25
+
26
+ ### Default command
27
+
28
+ ```bash
29
+ npx astro-html-validator
30
+ ```
31
+
32
+ By default it validates `./dist` and runs all validators.
33
+
34
+ ### Run specific validators
35
+
36
+ ```bash
37
+ npx astro-html-validator meta
38
+ npx astro-html-validator links
39
+ npx astro-html-validator jsonld,meta
40
+ ```
41
+
42
+ ### CLI options
43
+
44
+ ```bash
45
+ astro-html-validator [selector] [options]
46
+
47
+ Options:
48
+ --dir <path> Path to the dist directory (default: <cwd>/dist)
49
+ --quiet Disable summary output
50
+ --help Show help
51
+ ```
52
+
53
+ ---
54
+
55
+ ## Programmatic usage (Node)
56
+
57
+ ```js
58
+ import path from 'node:path';
59
+ import { Validator } from '@dukebot/astro-html-validator';
60
+
61
+ const validator = new Validator({
62
+ dirPath: path.resolve(process.cwd(), 'dist'),
63
+ config: {
64
+ jsonld: {},
65
+ links: {},
66
+ meta: {
67
+ metaTitleMinLength: 30,
68
+ metaTitleMaxLength: 60,
69
+ metaDescriptionMinLength: 70,
70
+ metaDescriptionMaxLength: 140,
71
+ },
72
+ },
73
+ print: true,
74
+ });
75
+
76
+ const results = await validator.run({ selector: 'all' });
77
+ console.log(results);
78
+ ```
79
+
80
+ ---
81
+
82
+ ## Suggested scripts for your Astro project
83
+
84
+ ```json
85
+ {
86
+ "scripts": {
87
+ "build": "astro build",
88
+ "validate:dist": "astro-html-validator",
89
+ "ci:seo": "npm run build && npm run validate:dist"
90
+ }
91
+ }
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Publish to npm
97
+
98
+ Quick steps:
99
+
100
+ 1. Update `name`, `author`, and `version` in `package.json`.
101
+ 2. Sign in:
102
+
103
+ ```bash
104
+ npm login
105
+ ```
106
+
107
+ 3. Publish:
108
+
109
+ ```bash
110
+ npm publish --access public
111
+ ```
112
+
113
+
114
+
115
+
116
+
package/bin/cli.mjs ADDED
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from 'node:path';
4
+ import { Validator } from '../src/index.mjs';
5
+
6
+ /**
7
+ * Prints CLI usage information.
8
+ */
9
+ function printHelp() {
10
+ console.log(`
11
+ astro-html-validator
12
+
13
+ Usage:
14
+ astro-html-validator [selector] [options]
15
+
16
+ Selector:
17
+ all | jsonld | links | meta | jsonld,links,meta
18
+
19
+ Options:
20
+ --dir <path> Path to the dist directory (default: ./dist)
21
+ --quiet Disable printed summary output
22
+ --help Show help
23
+
24
+ Examples:
25
+ astro-html-validator
26
+ astro-html-validator meta
27
+ astro-html-validator links --dir ./dist
28
+ astro-html-validator jsonld,meta
29
+ `);
30
+ }
31
+
32
+ /**
33
+ * Parses CLI arguments into validator runtime options.
34
+ */
35
+ function parseArgs(argv = process.argv.slice(2)) {
36
+ const options = {
37
+ selector: 'all',
38
+ dirPath: path.resolve(process.cwd(), 'dist'),
39
+ print: true,
40
+ help: false,
41
+ };
42
+
43
+ for (let index = 0; index < argv.length; index += 1) {
44
+ const arg = argv[index];
45
+ if (!arg) continue;
46
+
47
+ if (!arg.startsWith('-') && options.selector === 'all') {
48
+ options.selector = arg;
49
+ continue;
50
+ }
51
+
52
+ if (arg === '--help' || arg === '-h') {
53
+ options.help = true;
54
+ continue;
55
+ }
56
+
57
+ if (arg === '--quiet') {
58
+ options.print = false;
59
+ continue;
60
+ }
61
+
62
+ if (arg === '--dir') {
63
+ const next = argv[index + 1];
64
+ if (!next) throw new Error('Missing value for --dir');
65
+ options.dirPath = path.resolve(process.cwd(), next);
66
+ index += 1;
67
+ continue;
68
+ }
69
+
70
+ throw new Error(`Unknown argument: ${arg}`);
71
+ }
72
+
73
+ return options;
74
+ }
75
+
76
+ /**
77
+ * CLI entry point.
78
+ */
79
+ async function main() {
80
+ const parsed = parseArgs();
81
+
82
+ if (parsed.help) {
83
+ printHelp();
84
+ process.exit(0);
85
+ }
86
+
87
+ console.log('\n=== Dist validation started ===');
88
+
89
+ const validator = new Validator({
90
+ dirPath: parsed.dirPath,
91
+ config: {},
92
+ print: parsed.print,
93
+ });
94
+
95
+ await validator.run({ selector: parsed.selector });
96
+
97
+ console.log('\n=== Dist validation completed ===');
98
+ process.exit(0);
99
+ }
100
+
101
+ main().catch((error) => {
102
+ console.error('[ERROR] Dist validation failed:', error.message ?? error);
103
+ process.exit(1);
104
+ });
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@dukebot/astro-html-validator",
3
+ "version": "1.0.0",
4
+ "description": "Validate Astro-generated HTML output for SEO metadata, JSON-LD, and internal links.",
5
+ "type": "module",
6
+ "main": "./src/index.mjs",
7
+ "exports": {
8
+ ".": "./src/index.mjs",
9
+ "./validator": "./src/validator.mjs"
10
+ },
11
+ "bin": {
12
+ "astro-html-validator": "bin/cli.mjs"
13
+ },
14
+ "files": [
15
+ "src/**/*.mjs",
16
+ "bin/cli.mjs",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "check": "node ./bin/cli.mjs --help",
22
+ "validate:dist": "node ./bin/cli.mjs"
23
+ },
24
+ "keywords": [
25
+ "astro",
26
+ "seo",
27
+ "validator",
28
+ "html",
29
+ "jsonld"
30
+ ],
31
+ "author": "Dukebot",
32
+ "license": "MIT",
33
+ "engines": {
34
+ "node": ">=18"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ }
39
+ }
package/src/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import { Validator } from './validator.mjs';
2
+
3
+ export { Validator };
4
+ export default Validator;
package/src/utils.mjs ADDED
@@ -0,0 +1,92 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ /**
5
+ * Throws if the given directory cannot be accessed.
6
+ */
7
+ export async function ensureDirExists(dirPath) {
8
+ try {
9
+ await fs.access(dirPath);
10
+ } catch {
11
+ throw new Error(`Directory does not exist: ${dirPath}`);
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Returns whether a file or directory exists.
17
+ */
18
+ export async function pathExists(filePath) {
19
+ try {
20
+ await fs.access(filePath);
21
+ return true;
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Converts an HTML file path into a route-like URL.
29
+ */
30
+ export function toRoute(filePath, rootDir) {
31
+ const rel = path.relative(rootDir, filePath).replace(/\\/g, '/');
32
+ if (rel === 'index.html') return '/';
33
+ if (rel.endsWith('/index.html')) return '/' + rel.replace(/\/index\.html$/, '');
34
+ return '/' + rel.replace(/\.html$/, '');
35
+ }
36
+
37
+ /**
38
+ * Normalized warning message format used by all validators.
39
+ */
40
+ export function formatWarning(route, message) {
41
+ return `[WARN] ${route} -> ${message}`;
42
+ }
43
+
44
+ /**
45
+ * Reads an attribute value from an HTML tag string.
46
+ */
47
+ export function getAttr(tag, attrName) {
48
+ const match = tag.match(new RegExp(`${attrName}=["']([^"']+)["']`, 'i'));
49
+ return match?.[1]?.trim();
50
+ }
51
+
52
+ /**
53
+ * Recursively collects all HTML files from a directory.
54
+ */
55
+ export async function walkHtmlFiles(dirPath) {
56
+ const entries = await fs.readdir(dirPath, { withFileTypes: true });
57
+ const files = [];
58
+
59
+ for (const entry of entries) {
60
+ const fullPath = path.join(dirPath, entry.name);
61
+ if (entry.isDirectory()) files.push(...(await walkHtmlFiles(fullPath)));
62
+ if (entry.isFile() && entry.name.endsWith('.html')) files.push(fullPath);
63
+ }
64
+
65
+ return files;
66
+ }
67
+
68
+ /**
69
+ * Shared runner for validators that operate page-by-page over HTML files.
70
+ */
71
+ export async function runHtmlValidation({ dirPath, validatePage }) {
72
+ await ensureDirExists(dirPath);
73
+ const htmlFiles = await walkHtmlFiles(dirPath);
74
+ const warnings = [];
75
+
76
+ for (const filePath of htmlFiles) {
77
+ const route = toRoute(filePath, dirPath);
78
+ if (route.startsWith('/decapcms')) continue;
79
+
80
+ const html = await fs.readFile(filePath, 'utf8');
81
+ const pageWarnings = (await validatePage({ html, route, filePath })) ?? [];
82
+
83
+ for (const warning of pageWarnings) {
84
+ warnings.push(formatWarning(route, warning));
85
+ }
86
+ }
87
+
88
+ return {
89
+ checkedPages: htmlFiles.length,
90
+ warnings,
91
+ };
92
+ }
@@ -0,0 +1,98 @@
1
+ import { validateJsonld } from './validators/jsonld.mjs';
2
+ import { validateLinks } from './validators/links.mjs';
3
+ import { validateMeta } from './validators/meta.mjs';
4
+
5
+ /**
6
+ * Coordinates all available validators and prints optional summaries.
7
+ */
8
+ export class Validator {
9
+ constructor({ dirPath, config = {}, print = true } = {}) {
10
+ this.dirPath = dirPath;
11
+
12
+ this.validators = {
13
+ jsonld: {
14
+ label: 'JSON-LD',
15
+ run: validateJsonld,
16
+ config: config.jsonld,
17
+ },
18
+ links: {
19
+ label: 'Internal links',
20
+ run: validateLinks,
21
+ config: config.links,
22
+ },
23
+ meta: {
24
+ label: 'SEO metadata',
25
+ run: validateMeta,
26
+ config: config.meta,
27
+ },
28
+ };
29
+
30
+ this.print = print;
31
+ }
32
+
33
+ /**
34
+ * Resolves a selector string into a unique list of validator names.
35
+ */
36
+ selectValidators(selector = 'all') {
37
+ const clean = selector.trim().toLowerCase();
38
+
39
+ if (clean === 'all') return Object.keys(this.validators);
40
+
41
+ const selected = clean
42
+ .split(',')
43
+ .map((item) => item.trim())
44
+ .filter(Boolean);
45
+
46
+ const invalid = selected.filter((name) => !this.validators[name]);
47
+ if (invalid.length > 0) {
48
+ throw new Error(
49
+ `Unknown validators: ${invalid.join(', ')}. ` +
50
+ `Valid options: all, ${Object.keys(this.validators).join(', ')}`
51
+ );
52
+ }
53
+
54
+ return [...new Set(selected)];
55
+ }
56
+
57
+ /**
58
+ * Prints a consistent summary for one validator result.
59
+ */
60
+ printResultSummary(result) {
61
+ console.log(`\n=== ${result.label} ===`);
62
+ console.log(`Checked ${result.checkedPages} HTML pages.`);
63
+
64
+ if (result.warnings.length === 0) {
65
+ console.log('✅ No warnings.');
66
+ return;
67
+ }
68
+
69
+ console.log(`⚠️ Warnings found: ${result.warnings.length}`);
70
+ for (const warning of result.warnings) console.log(warning);
71
+ }
72
+
73
+ /**
74
+ * Runs one validator by name.
75
+ */
76
+ async runValidator(name) {
77
+ const validator = this.validators[name];
78
+ const result = await validator.run(this.dirPath, validator.config);
79
+ result.label = validator.label;
80
+ if (this.print) this.printResultSummary(result);
81
+ return result;
82
+ }
83
+
84
+ /**
85
+ * Runs selected validators sequentially.
86
+ */
87
+ async run({ selector = 'all' } = {}) {
88
+ const results = [];
89
+ const selectedNames = this.selectValidators(selector);
90
+
91
+ for (const name of selectedNames) {
92
+ const result = await this.runValidator(name);
93
+ results.push(result);
94
+ }
95
+
96
+ return results;
97
+ }
98
+ }
@@ -0,0 +1,74 @@
1
+ import { runHtmlValidation } from '../utils.mjs';
2
+
3
+ /**
4
+ * Extracts and parses JSON-LD script blocks from a page.
5
+ */
6
+ function getJsonLdBlocks(html) {
7
+ const regex = /<script[^>]*type=["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi;
8
+ const blocks = [];
9
+ let match;
10
+
11
+ while ((match = regex.exec(html)) !== null) {
12
+ const raw = match[1]?.trim();
13
+ if (!raw) continue;
14
+ try {
15
+ blocks.push(JSON.parse(raw));
16
+ } catch {
17
+ blocks.push({ __parseError: true, __raw: raw });
18
+ }
19
+ }
20
+
21
+ return blocks;
22
+ }
23
+
24
+ /**
25
+ * Flattens top-level JSON-LD nodes and @graph nodes into one list.
26
+ */
27
+ function getGraphNodes(blocks) {
28
+ const nodes = [];
29
+ for (const block of blocks) {
30
+ if (block.__parseError) continue;
31
+ if (Array.isArray(block['@graph'])) nodes.push(...block['@graph']);
32
+ else nodes.push(block);
33
+ }
34
+ return nodes;
35
+ }
36
+
37
+ /**
38
+ * Validates JSON-LD presence/basic parseability for each HTML page.
39
+ */
40
+ export async function validateJsonld(dirPath) {
41
+ const { checkedPages, warnings } = await runHtmlValidation({
42
+ dirPath,
43
+ validatePage: ({ html }) => {
44
+ const pageWarnings = [];
45
+ const blocks = getJsonLdBlocks(html);
46
+
47
+ if (blocks.length === 0) {
48
+ pageWarnings.push('No JSON-LD block was found.');
49
+ return pageWarnings;
50
+ }
51
+
52
+ if (blocks.some((b) => b.__parseError)) {
53
+ pageWarnings.push('At least one JSON-LD block has invalid JSON.');
54
+ return pageWarnings;
55
+ }
56
+
57
+ const nodes = getGraphNodes(blocks);
58
+
59
+ if (nodes.length === 0) {
60
+ pageWarnings.push('JSON-LD exists but has no nodes in @graph.');
61
+ return pageWarnings;
62
+ }
63
+
64
+ return pageWarnings;
65
+ },
66
+ });
67
+
68
+ return {
69
+ name: 'jsonld',
70
+ label: 'JSON-LD',
71
+ checkedPages,
72
+ warnings,
73
+ };
74
+ }
@@ -0,0 +1,81 @@
1
+ import path from 'node:path';
2
+ import { pathExists, runHtmlValidation } from '../utils.mjs';
3
+
4
+ /**
5
+ * Extracts local (root-relative) URLs from href/src attributes.
6
+ */
7
+ function extractInternalUrls(html) {
8
+ const urls = new Set();
9
+ const regex = /(?:href|src)=["']([^"']+)["']/gi;
10
+
11
+ let match;
12
+ while ((match = regex.exec(html)) !== null) {
13
+ const raw = match[1]?.trim();
14
+ if (!raw) continue;
15
+
16
+ if (
17
+ raw.startsWith('http://') ||
18
+ raw.startsWith('https://') ||
19
+ raw.startsWith('//') ||
20
+ raw.startsWith('#') ||
21
+ raw.startsWith('mailto:') ||
22
+ raw.startsWith('tel:') ||
23
+ raw.startsWith('javascript:') ||
24
+ raw.startsWith('data:')
25
+ ) {
26
+ continue;
27
+ }
28
+
29
+ if (raw.startsWith('/')) {
30
+ const clean = raw.split('#')[0].split('?')[0];
31
+ if (clean) urls.add(clean);
32
+ }
33
+ }
34
+
35
+ return [...urls];
36
+ }
37
+
38
+ /**
39
+ * Checks whether an internal URL resolves to an HTML file in dist.
40
+ */
41
+ async function internalUrlExists(dirPath, urlPath) {
42
+ if (urlPath === '/') return pathExists(path.join(dirPath, 'index.html'));
43
+
44
+ const asFile = path.join(dirPath, urlPath.replace(/^\//, ''));
45
+ if (await pathExists(asFile)) return true;
46
+
47
+ const asIndex = path.join(dirPath, urlPath.replace(/^\//, ''), 'index.html');
48
+ if (await pathExists(asIndex)) return true;
49
+
50
+ const asHtml = path.join(dirPath, `${urlPath.replace(/^\//, '')}.html`);
51
+ if (await pathExists(asHtml)) return true;
52
+
53
+ return false;
54
+ }
55
+
56
+ /**
57
+ * Reports broken internal links for each generated HTML page.
58
+ */
59
+ export async function validateLinks(dirPath) {
60
+ const { checkedPages, warnings } = await runHtmlValidation({
61
+ dirPath,
62
+ validatePage: async ({ html }) => {
63
+ const pageWarnings = [];
64
+ const urls = extractInternalUrls(html);
65
+
66
+ for (const url of urls) {
67
+ const exists = await internalUrlExists(dirPath, url);
68
+ if (!exists) pageWarnings.push(`Internal link not found: ${url}`);
69
+ }
70
+
71
+ return pageWarnings;
72
+ },
73
+ });
74
+
75
+ return {
76
+ name: 'links',
77
+ label: 'Internal links',
78
+ checkedPages,
79
+ warnings,
80
+ };
81
+ }
@@ -0,0 +1,130 @@
1
+ import { getAttr, runHtmlValidation } from '../utils.mjs';
2
+
3
+ // Core metadata tags expected on every page.
4
+ const REQUIRED_META_CHECKS = [
5
+ { label: 'meta title', check: getTitleContent },
6
+ { label: 'meta description', check: (html) => hasMeta(html, 'description') },
7
+ { label: 'canonical', check: hasCanonical },
8
+ { label: 'meta robots', check: (html) => hasMeta(html, 'robots') },
9
+ { label: 'og:title', check: (html) => hasMeta(html, 'og:title', true) },
10
+ { label: 'og:description', check: (html) => hasMeta(html, 'og:description', true) },
11
+ { label: 'og:url', check: (html) => hasMeta(html, 'og:url', true) },
12
+ { label: 'og:type', check: (html) => hasMeta(html, 'og:type', true) },
13
+ ];
14
+
15
+ function hasMeta(html, name, isProperty = false) {
16
+ const tags = html.match(/<meta\b[^>]*>/gi) || [];
17
+ return tags.some((tag) => {
18
+ const key = isProperty ? getAttr(tag, 'property') : getAttr(tag, 'name');
19
+ if (!key || key !== name) return false;
20
+ const content = getAttr(tag, 'content');
21
+ return !!content;
22
+ });
23
+ }
24
+
25
+ /**
26
+ * Returns the `content` value for a meta tag by name/property.
27
+ */
28
+ function getMetaContent(html, name, isProperty = false) {
29
+ const tags = html.match(/<meta\b[^>]*>/gi) || [];
30
+ for (const tag of tags) {
31
+ const key = isProperty ? getAttr(tag, 'property') : getAttr(tag, 'name');
32
+ if (!key || key !== name) continue;
33
+ const content = getAttr(tag, 'content');
34
+ if (content) return content;
35
+ }
36
+ return '';
37
+ }
38
+
39
+ /**
40
+ * Checks that a canonical link tag exists with a non-empty href.
41
+ */
42
+ function hasCanonical(html) {
43
+ const links = html.match(/<link\b[^>]*>/gi) || [];
44
+ return links.some((tag) => {
45
+ const rel = getAttr(tag, 'rel');
46
+ if (!rel || rel.toLowerCase() !== 'canonical') return false;
47
+ const href = getAttr(tag, 'href');
48
+ return !!href;
49
+ });
50
+ }
51
+
52
+ function getTitleContent(html) {
53
+ const match = html.match(/<title>([^<]+)<\/title>/i);
54
+ return match?.[1]?.trim() ?? '';
55
+ }
56
+
57
+ /**
58
+ * Validates optional length ranges for title/description fields.
59
+ */
60
+ function validateLengthRange({ value, min = 1, max = Infinity, fieldLabel }) {
61
+ if (!value) return;
62
+ if (value.length >= min && value.length <= max) return;
63
+ return `Recommended ${fieldLabel} length is ${min}-${max}. Current: ${value.length}.`;
64
+ }
65
+
66
+ function validateRequiredMeta(html) {
67
+ const warnings = [];
68
+
69
+ for (const item of REQUIRED_META_CHECKS) {
70
+ if (!item.check(html)) {
71
+ warnings.push(`Missing ${item.label}.`);
72
+ }
73
+ }
74
+
75
+ return warnings;
76
+ }
77
+
78
+ /**
79
+ * Runs required and optional SEO metadata checks for one HTML string.
80
+ */
81
+ function validateHtmlMeta(
82
+ html,
83
+ {
84
+ metaTitleMinLength,
85
+ metaTitleMaxLength,
86
+ metaDescriptionMinLength,
87
+ metaDescriptionMaxLength,
88
+ } = {}
89
+ ) {
90
+ const warnings = [];
91
+
92
+ warnings.push(...validateRequiredMeta(html));
93
+
94
+ warnings.push(
95
+ validateLengthRange({
96
+ value: getTitleContent(html),
97
+ min: metaTitleMinLength,
98
+ max: metaTitleMaxLength,
99
+ fieldLabel: 'meta title',
100
+ })
101
+ );
102
+
103
+ warnings.push(
104
+ validateLengthRange({
105
+ value: getMetaContent(html, 'description'),
106
+ min: metaDescriptionMinLength,
107
+ max: metaDescriptionMaxLength,
108
+ fieldLabel: 'meta description',
109
+ })
110
+ );
111
+
112
+ return warnings.filter(Boolean);
113
+ }
114
+
115
+ /**
116
+ * Validates SEO metadata for every HTML page in dist.
117
+ */
118
+ export async function validateMeta(dirPath, options) {
119
+ const { checkedPages, warnings } = await runHtmlValidation({
120
+ dirPath,
121
+ validatePage: ({ html }) => validateHtmlMeta(html, options),
122
+ });
123
+
124
+ return {
125
+ name: 'meta',
126
+ label: 'SEO metadata',
127
+ checkedPages,
128
+ warnings,
129
+ };
130
+ }