@agentmarkup/astro 0.2.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 +21 -0
- package/README.md +99 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +162 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sebastian Cochinescu and Anima Felix
|
|
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,99 @@
|
|
|
1
|
+
# @agentmarkup/astro
|
|
2
|
+
|
|
3
|
+
Build-time `llms.txt`, JSON-LD, AI crawler `robots.txt`, and validation for Astro websites.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @agentmarkup/astro
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from 'astro/config';
|
|
15
|
+
import { agentmarkup } from '@agentmarkup/astro';
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
integrations: [
|
|
19
|
+
agentmarkup({
|
|
20
|
+
site: 'https://example.com',
|
|
21
|
+
name: 'Example',
|
|
22
|
+
description: 'Machine-readable metadata for an Astro site.',
|
|
23
|
+
llmsTxt: {
|
|
24
|
+
sections: [
|
|
25
|
+
{
|
|
26
|
+
title: 'Documentation',
|
|
27
|
+
entries: [
|
|
28
|
+
{
|
|
29
|
+
title: 'Getting Started',
|
|
30
|
+
url: '/docs/getting-started',
|
|
31
|
+
description: 'Setup guide and first steps',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
globalSchemas: [
|
|
38
|
+
{
|
|
39
|
+
preset: 'webSite',
|
|
40
|
+
name: 'Example',
|
|
41
|
+
url: 'https://example.com',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
preset: 'organization',
|
|
45
|
+
name: 'Example Inc.',
|
|
46
|
+
url: 'https://example.com',
|
|
47
|
+
logo: 'https://example.com/logo.png',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
pages: [
|
|
51
|
+
{
|
|
52
|
+
path: '/faq',
|
|
53
|
+
schemas: [
|
|
54
|
+
{
|
|
55
|
+
preset: 'faqPage',
|
|
56
|
+
url: 'https://example.com/faq',
|
|
57
|
+
questions: [
|
|
58
|
+
{
|
|
59
|
+
question: 'Do you ship internationally?',
|
|
60
|
+
answer: 'Yes.',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
aiCrawlers: {
|
|
68
|
+
GPTBot: 'allow',
|
|
69
|
+
ClaudeBot: 'allow',
|
|
70
|
+
PerplexityBot: 'allow',
|
|
71
|
+
'Google-Extended': 'allow',
|
|
72
|
+
},
|
|
73
|
+
validation: {
|
|
74
|
+
warnOnMissingSchema: true,
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## What It Does
|
|
82
|
+
|
|
83
|
+
- Injects JSON-LD into built HTML pages during the Astro build
|
|
84
|
+
- Generates `/llms.txt` from config
|
|
85
|
+
- Patches or creates `robots.txt` with AI crawler directives
|
|
86
|
+
- Validates common schema and crawler mistakes at build time
|
|
87
|
+
- Re-exports `@agentmarkup/core` helpers for custom pipelines
|
|
88
|
+
|
|
89
|
+
By default, the Astro adapter coexists with existing machine-readable assets. If a page already contains JSON-LD for a schema type, or the site already ships a curated `llms.txt` or matching crawler rules, those are preserved unless you opt into replacement.
|
|
90
|
+
|
|
91
|
+
## Maintainer
|
|
92
|
+
|
|
93
|
+
Copyright (c) 2026 [Sebastian Cochinescu](https://www.cochinescu.com). MIT License.
|
|
94
|
+
|
|
95
|
+
Used in production on [Anima Felix](https://animafelix.com).
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { readdir, readFile, writeFile } from "fs/promises";
|
|
4
|
+
import { join, relative } from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import {
|
|
7
|
+
collectSchemasForPage,
|
|
8
|
+
filterJsonLdByExistingTypes,
|
|
9
|
+
generateJsonLdTags,
|
|
10
|
+
generateLlmsTxt,
|
|
11
|
+
hasExistingJsonLdScripts,
|
|
12
|
+
injectJsonLdTags,
|
|
13
|
+
normalizePagePath,
|
|
14
|
+
patchRobotsTxt,
|
|
15
|
+
presetToJsonLd,
|
|
16
|
+
printReport,
|
|
17
|
+
validateLlmsTxt,
|
|
18
|
+
validateRobotsTxt,
|
|
19
|
+
validateSchema
|
|
20
|
+
} from "@agentmarkup/core";
|
|
21
|
+
export * from "@agentmarkup/core";
|
|
22
|
+
function agentmarkup(config) {
|
|
23
|
+
const validationResults = [];
|
|
24
|
+
let llmsTxtEntries = 0;
|
|
25
|
+
let llmsTxtSections = 0;
|
|
26
|
+
let llmsTxtStatus = "none";
|
|
27
|
+
let jsonLdPages = 0;
|
|
28
|
+
let crawlersConfigured = 0;
|
|
29
|
+
let robotsTxtStatus = "none";
|
|
30
|
+
let publicDir;
|
|
31
|
+
return {
|
|
32
|
+
name: "agentmarkup",
|
|
33
|
+
hooks: {
|
|
34
|
+
"astro:config:done": ({ config: resolvedConfig }) => {
|
|
35
|
+
publicDir = fileURLToPath(resolvedConfig.publicDir);
|
|
36
|
+
},
|
|
37
|
+
"astro:build:done": async ({ dir }) => {
|
|
38
|
+
const outDir = fileURLToPath(dir);
|
|
39
|
+
const htmlFiles = await findHtmlFiles(outDir);
|
|
40
|
+
for (const htmlFile of htmlFiles) {
|
|
41
|
+
const pagePath = pagePathFromOutputFile(outDir, htmlFile);
|
|
42
|
+
const html = await readFile(htmlFile, "utf8");
|
|
43
|
+
const schemas = collectSchemasForPage(config, pagePath);
|
|
44
|
+
const hasExistingJsonLd = hasExistingJsonLdScripts(html);
|
|
45
|
+
if (schemas.length === 0) {
|
|
46
|
+
if (pagePath && config.validation?.warnOnMissingSchema && !config.validation.disabled && !hasExistingJsonLd) {
|
|
47
|
+
validationResults.push({
|
|
48
|
+
severity: "warning",
|
|
49
|
+
message: "No structured data configured for this page",
|
|
50
|
+
path: pagePath
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const jsonLdObjects = schemas.map(presetToJsonLd);
|
|
56
|
+
const injectables = config.jsonLd?.replaceExistingTypes ? jsonLdObjects : filterJsonLdByExistingTypes(jsonLdObjects, html);
|
|
57
|
+
if (!config.validation?.disabled) {
|
|
58
|
+
for (const schema of schemas) {
|
|
59
|
+
validationResults.push(...validateSchema(schema, pagePath));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (injectables.length === 0) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const tags = generateJsonLdTags(injectables);
|
|
66
|
+
await writeFile(htmlFile, injectJsonLdTags(html, tags), "utf8");
|
|
67
|
+
jsonLdPages += 1;
|
|
68
|
+
}
|
|
69
|
+
const llmsTxtContent = generateLlmsTxt(config);
|
|
70
|
+
if (llmsTxtContent) {
|
|
71
|
+
const outputLlmsPath = join(outDir, "llms.txt");
|
|
72
|
+
const existingOutputLlms = await readTextFileIfExists(outputLlmsPath);
|
|
73
|
+
const existingLlms = existingOutputLlms ?? (publicDir ? await readTextFileIfExists(join(publicDir, "llms.txt")) : null);
|
|
74
|
+
if (existingLlms && !config.llmsTxt?.replaceExisting) {
|
|
75
|
+
llmsTxtStatus = "preserved";
|
|
76
|
+
if (!existingOutputLlms) {
|
|
77
|
+
await writeFile(outputLlmsPath, existingLlms, "utf8");
|
|
78
|
+
}
|
|
79
|
+
if (!config.validation?.disabled) {
|
|
80
|
+
validationResults.push(...validateLlmsTxt(existingLlms));
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
llmsTxtStatus = "generated";
|
|
84
|
+
llmsTxtSections = config.llmsTxt?.sections.length ?? 0;
|
|
85
|
+
llmsTxtEntries = config.llmsTxt?.sections.reduce(
|
|
86
|
+
(sum, section) => sum + section.entries.length,
|
|
87
|
+
0
|
|
88
|
+
) ?? 0;
|
|
89
|
+
await writeFile(outputLlmsPath, llmsTxtContent, "utf8");
|
|
90
|
+
if (!config.validation?.disabled) {
|
|
91
|
+
validationResults.push(...validateLlmsTxt(llmsTxtContent));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (config.aiCrawlers) {
|
|
96
|
+
const crawlerEntries = Object.entries(config.aiCrawlers).filter(
|
|
97
|
+
([, value]) => value !== void 0
|
|
98
|
+
);
|
|
99
|
+
crawlersConfigured = crawlerEntries.length;
|
|
100
|
+
let existingRobots = await readTextFileIfExists(join(outDir, "robots.txt"));
|
|
101
|
+
if (!existingRobots && publicDir) {
|
|
102
|
+
existingRobots = await readTextFileIfExists(join(publicDir, "robots.txt"));
|
|
103
|
+
}
|
|
104
|
+
if (existingRobots && !config.validation?.disabled) {
|
|
105
|
+
validationResults.push(
|
|
106
|
+
...validateRobotsTxt(existingRobots, config.aiCrawlers)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const patched = patchRobotsTxt(existingRobots, config.aiCrawlers);
|
|
110
|
+
const preserved = existingRobots !== null && patched === existingRobots;
|
|
111
|
+
robotsTxtStatus = preserved ? "preserved" : "patched";
|
|
112
|
+
const outputRobotsPath = join(outDir, "robots.txt");
|
|
113
|
+
if (!preserved || !existingOutputFileExists(outputRobotsPath)) {
|
|
114
|
+
await writeFile(outputRobotsPath, patched, "utf8");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
printReport({
|
|
118
|
+
label: "@agentmarkup/astro",
|
|
119
|
+
llmsTxtEntries,
|
|
120
|
+
llmsTxtSections,
|
|
121
|
+
llmsTxtStatus,
|
|
122
|
+
jsonLdPages,
|
|
123
|
+
crawlersConfigured,
|
|
124
|
+
robotsTxtStatus,
|
|
125
|
+
validationResults
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
async function readTextFileIfExists(filePath) {
|
|
132
|
+
if (!existsSync(filePath)) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
return readFile(filePath, "utf8");
|
|
136
|
+
}
|
|
137
|
+
async function findHtmlFiles(rootDir) {
|
|
138
|
+
const entries = await readdir(rootDir, { withFileTypes: true });
|
|
139
|
+
const htmlFiles = [];
|
|
140
|
+
for (const entry of entries) {
|
|
141
|
+
const entryPath = join(rootDir, entry.name);
|
|
142
|
+
if (entry.isDirectory()) {
|
|
143
|
+
htmlFiles.push(...await findHtmlFiles(entryPath));
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (entry.isFile() && entry.name.endsWith(".html")) {
|
|
147
|
+
htmlFiles.push(entryPath);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return htmlFiles.sort();
|
|
151
|
+
}
|
|
152
|
+
function pagePathFromOutputFile(outDir, filePath) {
|
|
153
|
+
const relativePath = relative(outDir, filePath).replace(/\\/g, "/");
|
|
154
|
+
const candidatePath = relativePath === "index.html" ? "/" : `/${relativePath}`;
|
|
155
|
+
return normalizePagePath(candidatePath);
|
|
156
|
+
}
|
|
157
|
+
function existingOutputFileExists(filePath) {
|
|
158
|
+
return existsSync(filePath);
|
|
159
|
+
}
|
|
160
|
+
export {
|
|
161
|
+
agentmarkup
|
|
162
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentmarkup/astro",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Build-time llms.txt, JSON-LD, and AI crawler controls for Astro",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Sebastian Cochinescu <hello@animafelix.com> (https://animafelix.com)",
|
|
8
|
+
"homepage": "https://agentmarkup.dev",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/agentmarkup/agentmarkup/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/agentmarkup/agentmarkup",
|
|
15
|
+
"directory": "packages/astro"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"astro",
|
|
19
|
+
"llms-txt",
|
|
20
|
+
"json-ld",
|
|
21
|
+
"schema-org",
|
|
22
|
+
"structured-data",
|
|
23
|
+
"robots-txt",
|
|
24
|
+
"ai-crawler",
|
|
25
|
+
"machine-readable"
|
|
26
|
+
],
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@agentmarkup/core": "0.2.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"astro": ">=4.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"astro": "^5.7.0",
|
|
46
|
+
"eslint": "^9.0.0",
|
|
47
|
+
"tsup": "^8.4.0",
|
|
48
|
+
"typescript": "^5.7.0",
|
|
49
|
+
"vitest": "^3.0.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"prebuild": "pnpm -C ../core build",
|
|
53
|
+
"build": "tsup",
|
|
54
|
+
"predev": "pnpm -C ../core build",
|
|
55
|
+
"dev": "tsup --watch",
|
|
56
|
+
"pretest": "pnpm -C ../core build",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"test:watch": "vitest",
|
|
59
|
+
"lint": "eslint src/ test/",
|
|
60
|
+
"pretypecheck": "pnpm -C ../core build",
|
|
61
|
+
"typecheck": "tsc --noEmit"
|
|
62
|
+
}
|
|
63
|
+
}
|