astro-head-check 1.0.1

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.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Velohost
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,133 @@
1
+ # astro-head
2
+
3
+ **Build-time `<head>` validation for Astro projects.**
4
+
5
+ `astro-head-check` is a lightweight Astro integration that validates essential HTML `<head>` metadata at build time.
6
+ It helps catch SEO and indexing issues *before* deployment — without runtime code, tracking, or dashboards.
7
+
8
+ ---
9
+
10
+ ## What it does
11
+
12
+ At build time, `astro-head` scans generated HTML files and validates common head metadata:
13
+
14
+ - `<title>`
15
+ - `<meta name="description">`
16
+ - `<link rel="canonical">`
17
+ - `<meta name="robots">` (optional)
18
+
19
+ It supports:
20
+ - Redirect shim detection (meta refresh pages are skipped)
21
+ - Automatic skipping of 404 pages
22
+ - Configurable checks
23
+ - Warning-only or hard-fail build modes
24
+
25
+ ---
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install astro-head-check
31
+ ```
32
+
33
+ ---
34
+
35
+ ## Usage
36
+
37
+ Add the integration to your `astro.config.mjs`:
38
+
39
+ ```js
40
+ import { defineConfig } from "astro/config";
41
+ import astroHead from "astro-head";
42
+
43
+ export default defineConfig({
44
+ integrations: [
45
+ astroHead({
46
+ mode: "warn", // or "error"
47
+ checks: {
48
+ title: true,
49
+ metaDescription: true,
50
+ canonical: true,
51
+ robots: true,
52
+ },
53
+ }),
54
+ ],
55
+ });
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Options
61
+
62
+ ### `mode`
63
+
64
+ - `"error"` (default) — fails the build if issues are found
65
+ - `"warn"` — logs issues but allows the build to complete
66
+
67
+ ### `checks`
68
+
69
+ Enable or disable individual validations:
70
+
71
+ ```ts
72
+ checks: {
73
+ title?: boolean;
74
+ metaDescription?: boolean;
75
+ canonical?: boolean;
76
+ robots?: boolean;
77
+ }
78
+ ```
79
+
80
+ If **all checks are disabled**, the plugin does nothing.
81
+
82
+ ---
83
+
84
+ ## Output example
85
+
86
+ ```text
87
+ [astro-head] checks enabled:
88
+ ✓ title: enabled
89
+ ✓ metaDescription: enabled
90
+ ✓ canonical: enabled
91
+ ✓ robots: enabled
92
+
93
+ [astro-head] summary
94
+ [astro-head] HTML files scanned: 100
95
+ [astro-head] title checked: 75
96
+ [astro-head] metaDescription checked: 75
97
+ [astro-head] canonical checked: 75
98
+ [astro-head] robots checked: 75
99
+ [astro-head] pages with issues: 0
100
+ ```
101
+
102
+ ---
103
+
104
+ ## What it does *not* do
105
+
106
+ - ❌ No runtime JavaScript
107
+ - ❌ No Open Graph enforcement
108
+ - ❌ No structured data or rich results validation
109
+ - ❌ No analytics, telemetry, or tracking
110
+ - ❌ No mutation of HTML output
111
+
112
+ This tool is **pure validation only**.
113
+
114
+ ---
115
+
116
+ ## Compatibility
117
+
118
+ - Astro `^4.0.0` and `^5.0.0`
119
+ - Static and hybrid builds
120
+ - Works alongside other Astro integrations (canonical, robots, IndexNow, etc.)
121
+
122
+ ---
123
+
124
+ ## License
125
+
126
+ MIT © Velohost
127
+
128
+ ---
129
+
130
+ ## Author
131
+
132
+ **Velohost**
133
+ https://velohost.co.uk/
@@ -0,0 +1,12 @@
1
+ import type { AstroIntegration } from "astro";
2
+ type AstroHeadOptions = {
3
+ checks?: {
4
+ title?: boolean;
5
+ metaDescription?: boolean;
6
+ canonical?: boolean;
7
+ robots?: boolean;
8
+ };
9
+ mode?: "error" | "warn";
10
+ };
11
+ export default function astroHead(options?: AstroHeadOptions): AstroIntegration;
12
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,124 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ export default function astroHead(options = {}) {
4
+ const checks = {
5
+ title: options.checks?.title ?? true,
6
+ metaDescription: options.checks?.metaDescription ?? true,
7
+ canonical: options.checks?.canonical ?? true,
8
+ robots: options.checks?.robots ?? true,
9
+ };
10
+ const mode = options.mode ?? "error";
11
+ // If everything is disabled, do nothing
12
+ const anyCheckEnabled = Object.values(checks).some(Boolean);
13
+ return {
14
+ name: "astro-head",
15
+ hooks: {
16
+ "astro:build:done": async ({ dir }) => {
17
+ if (!anyCheckEnabled) {
18
+ return;
19
+ }
20
+ const distDir = new URL(dir).pathname;
21
+ const htmlFiles = [];
22
+ const issues = [];
23
+ const checkCounts = {
24
+ title: 0,
25
+ metaDescription: 0,
26
+ canonical: 0,
27
+ robots: 0,
28
+ };
29
+ async function walk(folder) {
30
+ const entries = await fs.readdir(folder, { withFileTypes: true });
31
+ for (const entry of entries) {
32
+ const fullPath = path.join(folder, entry.name);
33
+ if (entry.isDirectory()) {
34
+ await walk(fullPath);
35
+ }
36
+ else if (entry.isFile() && entry.name.endsWith(".html")) {
37
+ htmlFiles.push(fullPath);
38
+ }
39
+ }
40
+ }
41
+ await walk(distDir);
42
+ for (const file of htmlFiles) {
43
+ const relative = file.replace(distDir, "").replace(/\\/g, "/");
44
+ // Skip all 404 variants
45
+ if (relative === "/404.html" ||
46
+ relative === "404.html" ||
47
+ relative.endsWith("/404/index.html")) {
48
+ continue;
49
+ }
50
+ const html = await fs.readFile(file, "utf8");
51
+ // Skip redirect shim pages
52
+ const isRedirect = /http-equiv=["']refresh["']/i.test(html) &&
53
+ /content=["']\d+;\s*url=/i.test(html);
54
+ if (isRedirect) {
55
+ continue;
56
+ }
57
+ const problems = [];
58
+ // ===== TITLE =====
59
+ if (checks.title) {
60
+ checkCounts.title++;
61
+ const titleMatch = html.match(/<title>(.*?)<\/title>/i);
62
+ if (!titleMatch || titleMatch[1].trim() === "") {
63
+ problems.push("missing or empty <title>");
64
+ }
65
+ }
66
+ // ===== META DESCRIPTION =====
67
+ if (checks.metaDescription) {
68
+ checkCounts.metaDescription++;
69
+ const descMatch = html.match(/<meta\s+name=["']description["']\s+content=["']([^"']*)["'][^>]*>/i);
70
+ if (!descMatch || descMatch[1].trim() === "") {
71
+ problems.push("missing meta description");
72
+ }
73
+ }
74
+ // ===== CANONICAL =====
75
+ if (checks.canonical) {
76
+ checkCounts.canonical++;
77
+ const canonicalMatch = html.match(/<link\s+[^>]*rel=["']canonical["'][^>]*href=["']([^"']+)["'][^>]*>/i);
78
+ if (!canonicalMatch || canonicalMatch[1].trim() === "") {
79
+ problems.push("missing canonical link");
80
+ }
81
+ }
82
+ // ===== ROBOTS =====
83
+ if (checks.robots) {
84
+ checkCounts.robots++;
85
+ const robotsMatch = html.match(/<meta\s+name=["']robots["']\s+content=["']([^"']*)["'][^>]*>/i);
86
+ if (robotsMatch && robotsMatch[1].trim() === "") {
87
+ problems.push("empty robots meta tag");
88
+ }
89
+ }
90
+ if (problems.length > 0) {
91
+ issues.push({ file: relative, problems });
92
+ }
93
+ }
94
+ // ===== CHECK CONFIG SUMMARY =====
95
+ console.log("\n[astro-head] checks enabled:");
96
+ for (const [key, enabled] of Object.entries(checks)) {
97
+ console.log(` ${enabled ? "✓" : "–"} ${key}: ${enabled ? "enabled" : "disabled"}`);
98
+ }
99
+ // ===== RUN SUMMARY =====
100
+ console.log(`\n[astro-head] summary`);
101
+ console.log(`[astro-head] HTML files scanned: ${htmlFiles.length}`);
102
+ for (const [key, count] of Object.entries(checkCounts)) {
103
+ if (checks[key]) {
104
+ console.log(`[astro-head] ${key} checked: ${count}`);
105
+ }
106
+ }
107
+ console.log(`[astro-head] pages with issues: ${issues.length}`);
108
+ // ===== REPORT ISSUES =====
109
+ if (issues.length > 0) {
110
+ console.error(`\n[astro-head] head validation issues:`);
111
+ for (const issue of issues) {
112
+ console.error(`\n• ${issue.file}`);
113
+ for (const problem of issue.problems) {
114
+ console.error(` - ${problem}`);
115
+ }
116
+ }
117
+ if (mode === "error") {
118
+ throw new Error("[astro-head] build failed due to invalid <head> metadata");
119
+ }
120
+ }
121
+ },
122
+ },
123
+ };
124
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "astro-head-check",
3
+ "version": "1.0.1",
4
+ "description": "Build-time head and meta validation for Astro projects.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "author": {
8
+ "name": "Velohost",
9
+ "url": "https://velohost.co.uk"
10
+ },
11
+ "homepage": "https://github.com/velohost/astro-head",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/velohost/astro-head.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/velohost/astro-head/issues"
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "LICENSE.md"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc",
32
+ "prepublishOnly": "npm run build"
33
+ },
34
+ "keywords": [
35
+ "astro",
36
+ "withastro",
37
+ "astro-integration",
38
+ "seo",
39
+ "meta",
40
+ "head",
41
+ "validation",
42
+ "build-time"
43
+ ],
44
+ "peerDependencies": {
45
+ "astro": "^4.0.0 || ^5.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "astro": "^5.16.6",
49
+ "typescript": "^5.9.3"
50
+ }
51
+ }