aeo.js 0.0.1 → 0.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.
Files changed (70) hide show
  1. package/README.md +303 -6
  2. package/dist/angular.d.mts +29 -0
  3. package/dist/angular.d.ts +29 -0
  4. package/dist/angular.js +1314 -0
  5. package/dist/angular.js.map +1 -0
  6. package/dist/angular.mjs +1310 -0
  7. package/dist/angular.mjs.map +1 -0
  8. package/dist/astro.d.mts +15 -0
  9. package/dist/astro.d.ts +15 -0
  10. package/dist/astro.js +1421 -0
  11. package/dist/astro.js.map +1 -0
  12. package/dist/astro.mjs +1414 -0
  13. package/dist/astro.mjs.map +1 -0
  14. package/dist/cli.d.mts +1 -0
  15. package/dist/cli.d.ts +1 -0
  16. package/dist/cli.js +1880 -2
  17. package/dist/cli.js.map +1 -0
  18. package/dist/cli.mjs +1878 -0
  19. package/dist/cli.mjs.map +1 -0
  20. package/dist/index.d.mts +191 -0
  21. package/dist/index.d.ts +191 -1
  22. package/dist/index.js +1829 -1
  23. package/dist/index.js.map +1 -0
  24. package/dist/index.mjs +1801 -1
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/next.d.mts +18 -0
  27. package/dist/next.d.ts +18 -0
  28. package/dist/next.js +1302 -0
  29. package/dist/next.js.map +1 -0
  30. package/dist/next.mjs +1295 -0
  31. package/dist/next.mjs.map +1 -0
  32. package/dist/nuxt.d.mts +13 -0
  33. package/dist/nuxt.d.ts +13 -0
  34. package/dist/nuxt.js +1344 -0
  35. package/dist/nuxt.js.map +1 -0
  36. package/dist/nuxt.mjs +1337 -0
  37. package/dist/nuxt.mjs.map +1 -0
  38. package/dist/react.d.mts +10 -0
  39. package/dist/react.d.ts +10 -0
  40. package/dist/react.js +1023 -0
  41. package/dist/react.js.map +1 -0
  42. package/dist/react.mjs +1020 -0
  43. package/dist/react.mjs.map +1 -0
  44. package/dist/types-Cn_Qbkmg.d.mts +166 -0
  45. package/dist/types-Cn_Qbkmg.d.ts +166 -0
  46. package/dist/vite.d.mts +5 -0
  47. package/dist/vite.d.ts +5 -0
  48. package/dist/vite.js +1370 -0
  49. package/dist/vite.js.map +1 -0
  50. package/dist/vite.mjs +1366 -0
  51. package/dist/vite.mjs.map +1 -0
  52. package/dist/vue.d.mts +19 -0
  53. package/dist/vue.d.ts +19 -0
  54. package/dist/vue.js +1078 -0
  55. package/dist/vue.js.map +1 -0
  56. package/dist/vue.mjs +1072 -0
  57. package/dist/vue.mjs.map +1 -0
  58. package/dist/webpack.d.mts +11 -0
  59. package/dist/webpack.d.ts +11 -0
  60. package/dist/webpack.js +1179 -0
  61. package/dist/webpack.js.map +1 -0
  62. package/dist/webpack.mjs +1173 -0
  63. package/dist/webpack.mjs.map +1 -0
  64. package/dist/widget.d.mts +37 -0
  65. package/dist/widget.d.ts +37 -0
  66. package/dist/widget.js +1004 -0
  67. package/dist/widget.js.map +1 -0
  68. package/dist/widget.mjs +1001 -0
  69. package/dist/widget.mjs.map +1 -0
  70. package/package.json +110 -10
package/dist/astro.mjs ADDED
@@ -0,0 +1,1414 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, statSync, copyFileSync } from 'fs';
2
+ import { join, dirname, extname, relative } from 'path';
3
+ import 'minimatch';
4
+ import { createHash } from 'crypto';
5
+
6
+ // src/core/robots.ts
7
+ var AI_CRAWLERS = [
8
+ "GPTBot",
9
+ "OAI-SearchBot",
10
+ "ChatGPT-User",
11
+ "ClaudeBot",
12
+ "Claude-Web",
13
+ "anthropic-ai",
14
+ "PerplexityBot",
15
+ "Google-Extended",
16
+ "Gemini-Deep-Research",
17
+ "Bingbot",
18
+ "FacebookBot",
19
+ "meta-externalagent",
20
+ "Amazonbot",
21
+ "Applebot",
22
+ "DeepSeekBot",
23
+ "Bytespider",
24
+ "cohere-ai",
25
+ "CCBot",
26
+ "DiffBot",
27
+ "YouBot",
28
+ "FirecrawlAgent",
29
+ "Crawl4AI",
30
+ "BraveBot",
31
+ "SemrushBot",
32
+ "AhrefsBot",
33
+ "MJ12bot",
34
+ "DotBot",
35
+ "DataForSeoBot",
36
+ "Screaming Frog SEO Spider",
37
+ "SEOkicks",
38
+ "SEMrushBot",
39
+ "BLEXBot",
40
+ "Yandex",
41
+ "Baiduspider",
42
+ "Sogou",
43
+ "Exabot",
44
+ "facebookexternalhit",
45
+ "LinkedInBot",
46
+ "WhatsApp",
47
+ "Slackbot",
48
+ "TwitterBot",
49
+ "TelegramBot",
50
+ "Discordbot",
51
+ "PinterestBot",
52
+ "TumblrBot",
53
+ "ViberBot",
54
+ "SkypeUriPreview",
55
+ "redditbot",
56
+ "Snapchat",
57
+ "TikTok"
58
+ ];
59
+ function generateRobotsTxt(config) {
60
+ const lines = [
61
+ "# robots.txt generated by aeo.js",
62
+ "# Allow AI crawlers to index this site",
63
+ "",
64
+ "# Traditional search engines",
65
+ "User-agent: Googlebot",
66
+ "Allow: /",
67
+ "",
68
+ "User-agent: Bingbot",
69
+ "Allow: /",
70
+ "",
71
+ "# AI crawlers and answer engines"
72
+ ];
73
+ for (const crawler of AI_CRAWLERS) {
74
+ lines.push(`User-agent: ${crawler}`);
75
+ lines.push("Allow: /");
76
+ lines.push("");
77
+ }
78
+ lines.push("# Default for all other bots");
79
+ lines.push("User-agent: *");
80
+ lines.push("Allow: /");
81
+ lines.push("");
82
+ if (config.url) {
83
+ lines.push(`Sitemap: ${config.url}/sitemap.xml`);
84
+ }
85
+ lines.push("");
86
+ lines.push("# AEO (Answer Engine Optimization) files");
87
+ lines.push("# These help LLMs understand your content better");
88
+ lines.push(`# ${config.url}/llms.txt`);
89
+ lines.push(`# ${config.url}/llms-full.txt`);
90
+ lines.push(`# ${config.url}/docs.json`);
91
+ lines.push(`# ${config.url}/ai-index.json`);
92
+ return lines.join("\n");
93
+ }
94
+
95
+ // src/core/detect.ts
96
+ function detectFramework(projectRoot = process.cwd()) {
97
+ const packageJson = readPackageJson(projectRoot);
98
+ const dependencies = {
99
+ ...packageJson.dependencies,
100
+ ...packageJson.devDependencies
101
+ };
102
+ if (dependencies["next"]) {
103
+ return {
104
+ framework: "next",
105
+ contentDir: "app",
106
+ outDir: "out"
107
+ };
108
+ }
109
+ if (dependencies["nuxt"] || dependencies["@nuxt/kit"]) {
110
+ return {
111
+ framework: "nuxt",
112
+ contentDir: "content",
113
+ outDir: ".output/public"
114
+ };
115
+ }
116
+ if (dependencies["astro"] || dependencies["@astrojs/astro"]) {
117
+ return {
118
+ framework: "astro",
119
+ contentDir: "src/content",
120
+ outDir: "dist"
121
+ };
122
+ }
123
+ if (dependencies["@remix-run/dev"]) {
124
+ return {
125
+ framework: "remix",
126
+ contentDir: "app",
127
+ outDir: "build/client"
128
+ };
129
+ }
130
+ if (dependencies["@sveltejs/kit"]) {
131
+ return {
132
+ framework: "sveltekit",
133
+ contentDir: "src",
134
+ outDir: "build"
135
+ };
136
+ }
137
+ if (dependencies["@angular/core"]) {
138
+ return {
139
+ framework: "angular",
140
+ contentDir: "src",
141
+ outDir: "dist"
142
+ };
143
+ }
144
+ if (dependencies["@docusaurus/core"]) {
145
+ return {
146
+ framework: "docusaurus",
147
+ contentDir: "docs",
148
+ outDir: "build"
149
+ };
150
+ }
151
+ if (dependencies["vite"]) {
152
+ return {
153
+ framework: "vite",
154
+ contentDir: "src",
155
+ outDir: "dist"
156
+ };
157
+ }
158
+ return {
159
+ framework: "unknown",
160
+ contentDir: "src",
161
+ outDir: "dist"
162
+ };
163
+ }
164
+ function resolveConfig(config = {}) {
165
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M;
166
+ const frameworkInfo = detectFramework();
167
+ return {
168
+ title: config.title || "My Site",
169
+ description: config.description || "",
170
+ url: config.url || "https://example.com",
171
+ contentDir: config.contentDir || frameworkInfo.contentDir,
172
+ outDir: config.outDir || frameworkInfo.outDir,
173
+ pages: config.pages || [],
174
+ generators: {
175
+ robotsTxt: ((_a = config.generators) == null ? void 0 : _a.robotsTxt) !== false,
176
+ llmsTxt: ((_b = config.generators) == null ? void 0 : _b.llmsTxt) !== false,
177
+ llmsFullTxt: ((_c = config.generators) == null ? void 0 : _c.llmsFullTxt) !== false,
178
+ rawMarkdown: ((_d = config.generators) == null ? void 0 : _d.rawMarkdown) !== false,
179
+ manifest: ((_e = config.generators) == null ? void 0 : _e.manifest) !== false,
180
+ sitemap: ((_f = config.generators) == null ? void 0 : _f.sitemap) !== false,
181
+ aiIndex: ((_g = config.generators) == null ? void 0 : _g.aiIndex) !== false,
182
+ schema: ((_h = config.generators) == null ? void 0 : _h.schema) !== false
183
+ },
184
+ robots: {
185
+ allow: ((_i = config.robots) == null ? void 0 : _i.allow) || ["/"],
186
+ disallow: ((_j = config.robots) == null ? void 0 : _j.disallow) || [],
187
+ crawlDelay: ((_k = config.robots) == null ? void 0 : _k.crawlDelay) || 0,
188
+ sitemap: ((_l = config.robots) == null ? void 0 : _l.sitemap) || ""
189
+ },
190
+ schema: {
191
+ enabled: ((_m = config.schema) == null ? void 0 : _m.enabled) !== false,
192
+ organization: {
193
+ name: ((_o = (_n = config.schema) == null ? void 0 : _n.organization) == null ? void 0 : _o.name) || config.title || "My Site",
194
+ url: ((_q = (_p = config.schema) == null ? void 0 : _p.organization) == null ? void 0 : _q.url) || config.url || "https://example.com",
195
+ logo: ((_s = (_r = config.schema) == null ? void 0 : _r.organization) == null ? void 0 : _s.logo) || "",
196
+ sameAs: ((_u = (_t = config.schema) == null ? void 0 : _t.organization) == null ? void 0 : _u.sameAs) || []
197
+ },
198
+ defaultType: ((_v = config.schema) == null ? void 0 : _v.defaultType) || "WebPage"
199
+ },
200
+ og: {
201
+ enabled: ((_w = config.og) == null ? void 0 : _w.enabled) !== false,
202
+ image: ((_x = config.og) == null ? void 0 : _x.image) || "",
203
+ twitterHandle: ((_y = config.og) == null ? void 0 : _y.twitterHandle) || "",
204
+ type: ((_z = config.og) == null ? void 0 : _z.type) || "website"
205
+ },
206
+ widget: {
207
+ enabled: ((_A = config.widget) == null ? void 0 : _A.enabled) !== false,
208
+ position: ((_B = config.widget) == null ? void 0 : _B.position) || "bottom-right",
209
+ theme: {
210
+ background: ((_D = (_C = config.widget) == null ? void 0 : _C.theme) == null ? void 0 : _D.background) || "rgba(18, 18, 24, 0.9)",
211
+ text: ((_F = (_E = config.widget) == null ? void 0 : _E.theme) == null ? void 0 : _F.text) || "#C0C0C5",
212
+ accent: ((_H = (_G = config.widget) == null ? void 0 : _G.theme) == null ? void 0 : _H.accent) || "#E8E8EA",
213
+ badge: ((_J = (_I = config.widget) == null ? void 0 : _I.theme) == null ? void 0 : _J.badge) || "#4ADE80"
214
+ },
215
+ humanLabel: ((_K = config.widget) == null ? void 0 : _K.humanLabel) || "Human",
216
+ aiLabel: ((_L = config.widget) == null ? void 0 : _L.aiLabel) || "AI",
217
+ showBadge: ((_M = config.widget) == null ? void 0 : _M.showBadge) !== false
218
+ }
219
+ };
220
+ }
221
+ function parseFrontmatter(content) {
222
+ const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)/);
223
+ if (frontmatterMatch) {
224
+ const frontmatterStr = frontmatterMatch[1];
225
+ const contentWithoutFrontmatter = frontmatterMatch[2];
226
+ const frontmatter = {};
227
+ const lines = frontmatterStr.split("\n");
228
+ for (const line of lines) {
229
+ const [key, ...valueParts] = line.split(":");
230
+ if (key && valueParts.length > 0) {
231
+ const value = valueParts.join(":").trim();
232
+ frontmatter[key.trim()] = value.replace(/^["']|["']$/g, "");
233
+ }
234
+ }
235
+ return { frontmatter, content: contentWithoutFrontmatter };
236
+ }
237
+ return { frontmatter: {}, content };
238
+ }
239
+ function bumpHeadings(content, levels = 1) {
240
+ return content.replace(/^(#{1,6})\s/gm, (match, hashes) => {
241
+ const newLevel = Math.min(hashes.length + levels, 6);
242
+ return "#".repeat(newLevel) + " ";
243
+ });
244
+ }
245
+ function extractTitle(content) {
246
+ const h1Match = content.match(/^#\s+(.+)$/m);
247
+ if (h1Match) return h1Match[1];
248
+ const h2Match = content.match(/^##\s+(.+)$/m);
249
+ if (h2Match) return h2Match[1];
250
+ const firstLine = content.split("\n")[0];
251
+ return firstLine.slice(0, 100);
252
+ }
253
+ function readPackageJson(projectRoot = process.cwd()) {
254
+ const packageJsonPath = join(projectRoot, "package.json");
255
+ if (!existsSync(packageJsonPath)) {
256
+ return {};
257
+ }
258
+ try {
259
+ const content = readFileSync(packageJsonPath, "utf-8");
260
+ return JSON.parse(content);
261
+ } catch {
262
+ return {};
263
+ }
264
+ }
265
+
266
+ // src/core/llms-txt.ts
267
+ function collectMarkdownFiles(dir, base = dir) {
268
+ const files = [];
269
+ try {
270
+ const entries = readdirSync(dir);
271
+ for (const entry of entries) {
272
+ const fullPath = join(dir, entry);
273
+ const stat = statSync(fullPath);
274
+ if (stat.isDirectory() && !entry.startsWith(".") && entry !== "node_modules") {
275
+ files.push(...collectMarkdownFiles(fullPath, base));
276
+ } else if (stat.isFile() && (extname(entry) === ".md" || extname(entry) === ".mdx")) {
277
+ const content = readFileSync(fullPath, "utf-8");
278
+ const { frontmatter, content: mainContent } = parseFrontmatter(content);
279
+ const relativePath = relative(base, fullPath);
280
+ files.push({
281
+ path: relativePath,
282
+ content: mainContent,
283
+ title: frontmatter.title || extractTitle(mainContent),
284
+ description: frontmatter.description,
285
+ frontmatter
286
+ });
287
+ }
288
+ }
289
+ } catch (error) {
290
+ console.warn(`Warning: Could not read directory ${dir}:`, error);
291
+ }
292
+ return files;
293
+ }
294
+ function generateLlmsTxt(config) {
295
+ const lines = [
296
+ `# ${config.title}`,
297
+ ""
298
+ ];
299
+ if (config.description) {
300
+ lines.push(`> ${config.description}`);
301
+ lines.push("");
302
+ }
303
+ lines.push("## About");
304
+ lines.push("");
305
+ lines.push("This file provides a structured overview of the documentation and content available on this site,");
306
+ lines.push("optimized for consumption by Large Language Models (LLMs) and AI assistants.");
307
+ lines.push("");
308
+ if (config.pages && config.pages.length > 0) {
309
+ lines.push("## Pages");
310
+ lines.push("");
311
+ for (const page of config.pages) {
312
+ const url = `${config.url}${page.pathname === "/" ? "" : page.pathname}`;
313
+ const title = page.title || page.pathname;
314
+ lines.push(`- [${title}](${url})`);
315
+ if (page.description) {
316
+ lines.push(` ${page.description}`);
317
+ }
318
+ }
319
+ lines.push("");
320
+ }
321
+ const markdownFiles = collectMarkdownFiles(config.contentDir);
322
+ if (markdownFiles.length > 0) {
323
+ lines.push("## Documentation");
324
+ lines.push("");
325
+ const grouped = {};
326
+ for (const file of markdownFiles) {
327
+ const dir = file.path.split("/")[0] || "root";
328
+ if (!grouped[dir]) grouped[dir] = [];
329
+ grouped[dir].push(file);
330
+ }
331
+ for (const [dir, files] of Object.entries(grouped)) {
332
+ lines.push(`### ${dir === "root" ? "Main Documentation" : dir}`);
333
+ lines.push("");
334
+ for (const file of files) {
335
+ const url = `${config.url}/${file.path.replace(/\.mdx?$/, "")}`;
336
+ lines.push(`- [${file.title}](${url})`);
337
+ if (file.description) {
338
+ lines.push(` ${file.description}`);
339
+ }
340
+ }
341
+ lines.push("");
342
+ }
343
+ }
344
+ lines.push("## Quick Links");
345
+ lines.push("");
346
+ lines.push(`- Full Documentation: ${config.url}/llms-full.txt`);
347
+ lines.push(`- Documentation Manifest: ${config.url}/docs.json`);
348
+ lines.push(`- AI-Optimized Index: ${config.url}/ai-index.json`);
349
+ lines.push(`- Sitemap: ${config.url}/sitemap.xml`);
350
+ lines.push("");
351
+ lines.push("## For LLMs");
352
+ lines.push("");
353
+ lines.push("To get the complete documentation in a single file, request:");
354
+ lines.push(`${config.url}/llms-full.txt`);
355
+ lines.push("");
356
+ lines.push("For structured access to individual pages with metadata:");
357
+ lines.push(`${config.url}/docs.json`);
358
+ lines.push("");
359
+ lines.push("For RAG (Retrieval Augmented Generation) systems:");
360
+ lines.push(`${config.url}/ai-index.json`);
361
+ lines.push("");
362
+ lines.push("---");
363
+ lines.push("Generated by aeo.js - Answer Engine Optimization for the modern web");
364
+ lines.push("Learn more at https://aeojs.org");
365
+ return lines.join("\n");
366
+ }
367
+ function collectAndConcatenateMarkdown(dir, base = dir) {
368
+ const sections = [];
369
+ try {
370
+ const entries = readdirSync(dir).sort();
371
+ for (const entry of entries) {
372
+ const fullPath = join(dir, entry);
373
+ const stat = statSync(fullPath);
374
+ if (stat.isDirectory() && !entry.startsWith(".") && entry !== "node_modules") {
375
+ const subSections = collectAndConcatenateMarkdown(fullPath, base);
376
+ if (subSections.length > 0) {
377
+ sections.push(...subSections);
378
+ }
379
+ } else if (stat.isFile() && (extname(entry) === ".md" || extname(entry) === ".mdx")) {
380
+ const content = readFileSync(fullPath, "utf-8");
381
+ const { frontmatter, content: mainContent } = parseFrontmatter(content);
382
+ const relativePath = relative(base, fullPath);
383
+ const sectionLines = [
384
+ "---",
385
+ "",
386
+ `# ${frontmatter.title || relativePath}`,
387
+ "",
388
+ `Source: ${relativePath}`,
389
+ ""
390
+ ];
391
+ if (frontmatter.description) {
392
+ sectionLines.push(`> ${frontmatter.description}`);
393
+ sectionLines.push("");
394
+ }
395
+ const bumpedContent = bumpHeadings(mainContent, 1);
396
+ sectionLines.push(bumpedContent);
397
+ sectionLines.push("");
398
+ sections.push(sectionLines.join("\n"));
399
+ }
400
+ }
401
+ } catch (error) {
402
+ console.warn(`Warning: Could not read directory ${dir}:`, error);
403
+ }
404
+ return sections;
405
+ }
406
+ function generateLlmsFullTxt(config) {
407
+ const lines = [
408
+ `# ${config.title} - Complete Documentation`,
409
+ "",
410
+ `This file contains all documentation concatenated into a single file for easy consumption by LLMs.`,
411
+ ""
412
+ ];
413
+ if (config.description) {
414
+ lines.push(`> ${config.description}`);
415
+ lines.push("");
416
+ }
417
+ lines.push("## Table of Contents");
418
+ lines.push("");
419
+ lines.push("This document includes all content from this project.");
420
+ lines.push("Each section is separated by a horizontal rule (---) for easy parsing.");
421
+ lines.push("");
422
+ let hasContent = false;
423
+ if (config.pages && config.pages.length > 0) {
424
+ for (const page of config.pages) {
425
+ const url = `${config.url}${page.pathname === "/" ? "" : page.pathname}`;
426
+ const title = page.title || page.pathname;
427
+ const sectionLines = [
428
+ "---",
429
+ "",
430
+ `# ${title}`,
431
+ "",
432
+ `URL: ${url}`,
433
+ ""
434
+ ];
435
+ if (page.description) {
436
+ sectionLines.push(`> ${page.description}`);
437
+ sectionLines.push("");
438
+ }
439
+ if (page.content) {
440
+ sectionLines.push(page.content);
441
+ sectionLines.push("");
442
+ }
443
+ lines.push(sectionLines.join("\n"));
444
+ hasContent = true;
445
+ }
446
+ }
447
+ const sections = collectAndConcatenateMarkdown(config.contentDir);
448
+ if (sections.length > 0) {
449
+ lines.push(...sections);
450
+ hasContent = true;
451
+ }
452
+ if (!hasContent) {
453
+ lines.push("---");
454
+ lines.push("");
455
+ lines.push(`# ${config.title}`);
456
+ lines.push("");
457
+ lines.push(`URL: ${config.url}`);
458
+ lines.push("");
459
+ if (config.description) {
460
+ lines.push(config.description);
461
+ lines.push("");
462
+ }
463
+ }
464
+ lines.push("---");
465
+ lines.push("");
466
+ lines.push("## About This Document");
467
+ lines.push("");
468
+ lines.push("This concatenated documentation file is generated automatically by aeo.js");
469
+ lines.push("to make it easier for AI systems to understand the complete context of this project.");
470
+ lines.push("");
471
+ lines.push(`For a structured index, see: ${config.url}/llms.txt`);
472
+ lines.push(`For individual files, see: ${config.url}/docs.json`);
473
+ lines.push("");
474
+ lines.push("Generated by aeo.js - https://aeojs.org");
475
+ return lines.join("\n");
476
+ }
477
+ function ensureDir(path) {
478
+ mkdirSync(path, { recursive: true });
479
+ }
480
+ function copyMarkdownFiles(config) {
481
+ const copiedFiles = [];
482
+ function copyRecursive(dir, base = config.contentDir) {
483
+ try {
484
+ const entries = readdirSync(dir);
485
+ for (const entry of entries) {
486
+ const fullPath = join(dir, entry);
487
+ const stat = statSync(fullPath);
488
+ if (stat.isDirectory() && !entry.startsWith(".") && entry !== "node_modules") {
489
+ copyRecursive(fullPath, base);
490
+ } else if (stat.isFile() && extname(entry) === ".md") {
491
+ const relativePath = relative(base, fullPath);
492
+ const destPath = join(config.outDir, relativePath);
493
+ ensureDir(dirname(destPath));
494
+ try {
495
+ copyFileSync(fullPath, destPath);
496
+ copiedFiles.push({
497
+ source: fullPath,
498
+ destination: destPath
499
+ });
500
+ } catch (error) {
501
+ console.warn(`Warning: Could not copy ${fullPath}:`, error);
502
+ }
503
+ }
504
+ }
505
+ } catch (error) {
506
+ console.warn(`Warning: Could not read directory ${dir}:`, error);
507
+ }
508
+ }
509
+ copyRecursive(config.contentDir);
510
+ return copiedFiles;
511
+ }
512
+ function generatePageMarkdownFiles(config) {
513
+ const generated = [];
514
+ const pages = config.pages || [];
515
+ for (const page of pages) {
516
+ if (!page.content) continue;
517
+ const pageTitle = page.title || (page.pathname === "/" ? config.title : void 0);
518
+ let filename;
519
+ if (page.pathname === "/") {
520
+ filename = "index.md";
521
+ } else {
522
+ const clean = page.pathname.replace(/^\//, "").replace(/\/$/, "");
523
+ filename = clean.includes("/") ? `${clean}.md` : `${clean}.md`;
524
+ }
525
+ const destPath = join(config.outDir, filename);
526
+ const pageUrl = page.pathname === "/" ? config.url : `${config.url.replace(/\/$/, "")}${page.pathname}`;
527
+ const lines = [];
528
+ lines.push("---");
529
+ if (pageTitle) lines.push(`title: "${pageTitle}"`);
530
+ if (page.description) lines.push(`description: "${page.description}"`);
531
+ lines.push(`url: ${pageUrl}`);
532
+ lines.push(`source: ${pageUrl}`);
533
+ lines.push(`generated_by: aeo.js`);
534
+ lines.push("---", "");
535
+ if (pageTitle) {
536
+ lines.push(`# ${pageTitle}`, "");
537
+ }
538
+ if (page.description) {
539
+ lines.push(`${page.description}`, "");
540
+ }
541
+ if (page.content) {
542
+ lines.push(page.content);
543
+ }
544
+ const content = lines.join("\n");
545
+ ensureDir(dirname(destPath));
546
+ try {
547
+ writeFileSync(destPath, content, "utf-8");
548
+ generated.push({ pathname: page.pathname, destination: destPath });
549
+ } catch {
550
+ }
551
+ }
552
+ return generated;
553
+ }
554
+ function collectManifestEntries(dir, config, base = dir) {
555
+ const entries = [];
556
+ try {
557
+ const files = readdirSync(dir);
558
+ for (const file of files) {
559
+ const fullPath = join(dir, file);
560
+ const stat = statSync(fullPath);
561
+ if (stat.isDirectory() && !file.startsWith(".") && file !== "node_modules") {
562
+ entries.push(...collectManifestEntries(fullPath, config, base));
563
+ } else if (stat.isFile() && (extname(file) === ".md" || extname(file) === ".mdx")) {
564
+ const content = readFileSync(fullPath, "utf-8");
565
+ const { frontmatter, content: mainContent } = parseFrontmatter(content);
566
+ const relativePath = relative(base, fullPath);
567
+ const urlPath = relativePath.replace(/\.mdx?$/, "");
568
+ entries.push({
569
+ url: `${config.url}/${urlPath}`,
570
+ title: frontmatter.title || extractTitle(mainContent),
571
+ description: frontmatter.description,
572
+ lastModified: stat.mtime.toISOString()
573
+ });
574
+ }
575
+ }
576
+ } catch (error) {
577
+ console.warn(`Warning: Could not read directory ${dir}:`, error);
578
+ }
579
+ return entries;
580
+ }
581
+ function generateManifest(config) {
582
+ const entries = [];
583
+ if (config.pages && config.pages.length > 0) {
584
+ for (const page of config.pages) {
585
+ entries.push({
586
+ url: `${config.url}${page.pathname === "/" ? "" : page.pathname}`,
587
+ title: page.title || page.pathname,
588
+ description: page.description
589
+ });
590
+ }
591
+ }
592
+ entries.push(...collectManifestEntries(config.contentDir, config));
593
+ const manifest = {
594
+ version: "1.0",
595
+ generated: (/* @__PURE__ */ new Date()).toISOString(),
596
+ site: {
597
+ title: config.title,
598
+ description: config.description,
599
+ url: config.url
600
+ },
601
+ documents: entries.sort((a, b) => a.url.localeCompare(b.url)),
602
+ metadata: {
603
+ totalDocuments: entries.length,
604
+ generator: "aeo.js",
605
+ generatorUrl: "https://aeojs.org"
606
+ }
607
+ };
608
+ return JSON.stringify(manifest, null, 2);
609
+ }
610
+ function collectUrls(dir, config, base = dir) {
611
+ const urls = [];
612
+ try {
613
+ const entries = readdirSync(dir);
614
+ for (const entry of entries) {
615
+ const fullPath = join(dir, entry);
616
+ const stat = statSync(fullPath);
617
+ if (stat.isDirectory() && !entry.startsWith(".") && entry !== "node_modules") {
618
+ urls.push(...collectUrls(fullPath, config, base));
619
+ } else if (stat.isFile() && (extname(entry) === ".md" || extname(entry) === ".mdx" || extname(entry) === ".html")) {
620
+ const relativePath = relative(base, fullPath);
621
+ const urlPath = relativePath.replace(/\.(md|mdx|html)$/, "");
622
+ urls.push(`${config.url}/${urlPath}`);
623
+ }
624
+ }
625
+ } catch (error) {
626
+ console.warn(`Warning: Could not read directory ${dir}:`, error);
627
+ }
628
+ return urls;
629
+ }
630
+ function escapeXml(str) {
631
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
632
+ }
633
+ function generateSitemap(config) {
634
+ const urls = [];
635
+ if (config.pages && config.pages.length > 0) {
636
+ for (const page of config.pages) {
637
+ urls.push(`${config.url}${page.pathname === "/" ? "" : page.pathname}`);
638
+ }
639
+ }
640
+ if (config.contentDir) {
641
+ urls.push(...collectUrls(config.contentDir, config));
642
+ }
643
+ const lines = [
644
+ '<?xml version="1.0" encoding="UTF-8"?>',
645
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
646
+ ];
647
+ urls.push(config.url);
648
+ const uniqueUrls = [...new Set(urls)].sort();
649
+ for (const url of uniqueUrls) {
650
+ lines.push(" <url>");
651
+ lines.push(` <loc>${escapeXml(url)}</loc>`);
652
+ lines.push(` <lastmod>${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}</lastmod>`);
653
+ lines.push(" <changefreq>weekly</changefreq>");
654
+ lines.push(" <priority>0.8</priority>");
655
+ lines.push(" </url>");
656
+ }
657
+ lines.push("</urlset>");
658
+ return lines.join("\n");
659
+ }
660
+ function extractKeywords(content) {
661
+ const words = content.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).filter((word) => word.length > 3);
662
+ const wordCount = {};
663
+ for (const word of words) {
664
+ wordCount[word] = (wordCount[word] || 0) + 1;
665
+ }
666
+ return Object.entries(wordCount).sort((a, b) => b[1] - a[1]).slice(0, 10).map(([word]) => word);
667
+ }
668
+ function chunkContent(content, maxLength = 2e3) {
669
+ const chunks = [];
670
+ const paragraphs = content.split("\n\n");
671
+ let currentChunk = "";
672
+ for (const paragraph of paragraphs) {
673
+ if (currentChunk.length + paragraph.length > maxLength && currentChunk.length > 0) {
674
+ chunks.push(currentChunk.trim());
675
+ currentChunk = "";
676
+ }
677
+ currentChunk += paragraph + "\n\n";
678
+ }
679
+ if (currentChunk.trim()) {
680
+ chunks.push(currentChunk.trim());
681
+ }
682
+ return chunks;
683
+ }
684
+ function collectAIIndexEntries(dir, config, base = dir) {
685
+ const entries = [];
686
+ try {
687
+ const files = readdirSync(dir);
688
+ for (const file of files) {
689
+ const fullPath = join(dir, file);
690
+ const stat = statSync(fullPath);
691
+ if (stat.isDirectory() && !file.startsWith(".") && file !== "node_modules") {
692
+ entries.push(...collectAIIndexEntries(fullPath, config, base));
693
+ } else if (stat.isFile() && (extname(file) === ".md" || extname(file) === ".mdx")) {
694
+ const content = readFileSync(fullPath, "utf-8");
695
+ const { frontmatter, content: mainContent } = parseFrontmatter(content);
696
+ const relativePath = relative(base, fullPath);
697
+ const urlPath = relativePath.replace(/\.mdx?$/, "");
698
+ const url = `${config.url}/${urlPath}`;
699
+ const chunks = chunkContent(mainContent);
700
+ const title = frontmatter.title || extractTitle(mainContent);
701
+ const keywords = extractKeywords(mainContent);
702
+ chunks.forEach((chunk, index) => {
703
+ const id = createHash("sha256").update(`${url}-${index}`).digest("hex").slice(0, 16);
704
+ entries.push({
705
+ id,
706
+ url,
707
+ title: chunks.length > 1 ? `${title} (Part ${index + 1})` : title,
708
+ content: chunk,
709
+ description: frontmatter.description,
710
+ keywords,
711
+ metadata: {
712
+ ...frontmatter,
713
+ chunkIndex: index,
714
+ totalChunks: chunks.length,
715
+ sourcePath: relativePath
716
+ }
717
+ });
718
+ });
719
+ }
720
+ }
721
+ } catch (error) {
722
+ console.warn(`Warning: Could not read directory ${dir}:`, error);
723
+ }
724
+ return entries;
725
+ }
726
+ function generateAIIndex(config) {
727
+ const entries = [];
728
+ if (config.pages && config.pages.length > 0) {
729
+ for (const page of config.pages) {
730
+ const url = `${config.url}${page.pathname === "/" ? "" : page.pathname}`;
731
+ const title = page.title || page.pathname;
732
+ const content = page.content || "";
733
+ if (content) {
734
+ const chunks = chunkContent(content);
735
+ const keywords = extractKeywords(content);
736
+ chunks.forEach((chunk, index2) => {
737
+ const id = createHash("sha256").update(`${url}-${index2}`).digest("hex").slice(0, 16);
738
+ entries.push({
739
+ id,
740
+ url,
741
+ title: chunks.length > 1 ? `${title} (Part ${index2 + 1})` : title,
742
+ content: chunk,
743
+ description: page.description,
744
+ keywords,
745
+ metadata: {
746
+ chunkIndex: index2,
747
+ totalChunks: chunks.length,
748
+ sourcePath: page.pathname
749
+ }
750
+ });
751
+ });
752
+ } else {
753
+ const id = createHash("sha256").update(url).digest("hex").slice(0, 16);
754
+ entries.push({
755
+ id,
756
+ url,
757
+ title,
758
+ content: page.description || title,
759
+ description: page.description,
760
+ keywords: []
761
+ });
762
+ }
763
+ }
764
+ }
765
+ entries.push(...collectAIIndexEntries(config.contentDir, config));
766
+ const index = {
767
+ version: "1.0",
768
+ generated: (/* @__PURE__ */ new Date()).toISOString(),
769
+ site: {
770
+ title: config.title,
771
+ description: config.description,
772
+ url: config.url
773
+ },
774
+ entries: entries.sort((a, b) => a.id.localeCompare(b.id)),
775
+ metadata: {
776
+ totalEntries: entries.length,
777
+ generator: "aeo.js",
778
+ generatorUrl: "https://aeojs.org",
779
+ embedding: {
780
+ recommended: "text-embedding-ada-002",
781
+ dimensions: 1536
782
+ }
783
+ }
784
+ };
785
+ return JSON.stringify(index, null, 2);
786
+ }
787
+
788
+ // src/core/schema.ts
789
+ function generateSchema(config) {
790
+ const output = generateSchemaObjects(config);
791
+ return JSON.stringify(output, null, 2);
792
+ }
793
+ function generateSchemaObjects(config) {
794
+ const siteSchemas = generateSiteSchemas(config);
795
+ const pageSchemas = {};
796
+ for (const page of config.pages) {
797
+ const schemas = generatePageSchemas(page, config);
798
+ if (schemas.length > 0) {
799
+ pageSchemas[page.pathname] = schemas;
800
+ }
801
+ }
802
+ return { site: siteSchemas, pages: pageSchemas };
803
+ }
804
+ function generateSiteSchemas(config) {
805
+ const schemas = [];
806
+ schemas.push({
807
+ "@context": "https://schema.org",
808
+ "@type": "WebSite",
809
+ name: config.title,
810
+ description: config.description || void 0,
811
+ url: config.url
812
+ });
813
+ const org = config.schema.organization;
814
+ if (org.name || org.sameAs.length > 0) {
815
+ const orgSchema = {
816
+ "@context": "https://schema.org",
817
+ "@type": "Organization",
818
+ name: org.name,
819
+ url: org.url
820
+ };
821
+ if (org.logo) orgSchema.logo = org.logo;
822
+ if (org.sameAs.length > 0) orgSchema.sameAs = org.sameAs;
823
+ schemas.push(orgSchema);
824
+ }
825
+ return schemas;
826
+ }
827
+ function generatePageSchemas(page, config) {
828
+ const schemas = [];
829
+ const pageUrl = page.pathname === "/" ? config.url : `${config.url.replace(/\/$/, "")}${page.pathname}`;
830
+ const faqItems = detectFaqPatterns(page.content || "");
831
+ if (faqItems.length > 0) {
832
+ schemas.push({
833
+ "@context": "https://schema.org",
834
+ "@type": "FAQPage",
835
+ mainEntity: faqItems.map(({ question, answer }) => ({
836
+ "@type": "Question",
837
+ name: question,
838
+ acceptedAnswer: {
839
+ "@type": "Answer",
840
+ text: answer
841
+ }
842
+ }))
843
+ });
844
+ }
845
+ const pageType = config.schema.defaultType;
846
+ const pageSchema = {
847
+ "@context": "https://schema.org",
848
+ "@type": pageType,
849
+ name: page.title || config.title,
850
+ url: pageUrl
851
+ };
852
+ if (page.description) pageSchema.description = page.description;
853
+ if (pageType === "Article") {
854
+ pageSchema.headline = page.title || config.title;
855
+ pageSchema.author = {
856
+ "@type": "Organization",
857
+ name: config.schema.organization.name
858
+ };
859
+ }
860
+ schemas.push(pageSchema);
861
+ if (page.pathname !== "/") {
862
+ const breadcrumbs = generateBreadcrumbs(page.pathname, config);
863
+ if (breadcrumbs.length > 1) {
864
+ schemas.push({
865
+ "@context": "https://schema.org",
866
+ "@type": "BreadcrumbList",
867
+ itemListElement: breadcrumbs.map((crumb, i) => ({
868
+ "@type": "ListItem",
869
+ position: i + 1,
870
+ name: crumb.name,
871
+ item: crumb.url
872
+ }))
873
+ });
874
+ }
875
+ }
876
+ return schemas;
877
+ }
878
+ function generateBreadcrumbs(pathname, config) {
879
+ const baseUrl = config.url.replace(/\/$/, "");
880
+ const parts = pathname.split("/").filter(Boolean);
881
+ const crumbs = [
882
+ { name: "Home", url: baseUrl + "/" }
883
+ ];
884
+ let currentPath = "";
885
+ for (const part of parts) {
886
+ currentPath += "/" + part;
887
+ crumbs.push({
888
+ name: part.charAt(0).toUpperCase() + part.slice(1).replace(/-/g, " "),
889
+ url: baseUrl + currentPath
890
+ });
891
+ }
892
+ return crumbs;
893
+ }
894
+ function detectFaqPatterns(content) {
895
+ const items = [];
896
+ const lines = content.split("\n");
897
+ for (let i = 0; i < lines.length; i++) {
898
+ const line = lines[i].trim();
899
+ const headingMatch = line.match(/^#{1,6}\s+(.+\?)\s*$/);
900
+ if (headingMatch) {
901
+ const answerLines = [];
902
+ for (let j = i + 1; j < lines.length; j++) {
903
+ const nextLine = lines[j].trim();
904
+ if (!nextLine) {
905
+ if (answerLines.length > 0) break;
906
+ continue;
907
+ }
908
+ if (/^#{1,6}\s/.test(nextLine)) break;
909
+ answerLines.push(nextLine);
910
+ }
911
+ if (answerLines.length > 0) {
912
+ items.push({
913
+ question: headingMatch[1],
914
+ answer: answerLines.join(" ").slice(0, 500)
915
+ });
916
+ }
917
+ }
918
+ }
919
+ return items;
920
+ }
921
+ function generateJsonLdScript(schemas) {
922
+ if (schemas.length === 0) return "";
923
+ if (schemas.length === 1) {
924
+ return `<script type="application/ld+json">${JSON.stringify(schemas[0])}</script>`;
925
+ }
926
+ return schemas.map((s) => `<script type="application/ld+json">${JSON.stringify(s)}</script>`).join("\n");
927
+ }
928
+ async function generateAEOFiles(configOrRoot, maybeConfig) {
929
+ var _a;
930
+ let config;
931
+ if (typeof configOrRoot === "string") {
932
+ config = resolveConfig({ ...maybeConfig, outDir: configOrRoot });
933
+ } else if (configOrRoot && typeof configOrRoot === "object" && "generators" in configOrRoot && typeof ((_a = configOrRoot.generators) == null ? void 0 : _a.robotsTxt) === "boolean") {
934
+ config = configOrRoot;
935
+ } else {
936
+ config = resolveConfig(configOrRoot);
937
+ }
938
+ const outDir = config.outDir;
939
+ const files = [];
940
+ const errors = [];
941
+ if (!existsSync(outDir)) {
942
+ mkdirSync(outDir, { recursive: true });
943
+ }
944
+ if (config.generators.robotsTxt) {
945
+ try {
946
+ const content = generateRobotsTxt(config);
947
+ writeFileSync(join(outDir, "robots.txt"), content, "utf-8");
948
+ files.push("robots.txt");
949
+ } catch (e) {
950
+ errors.push(`robots.txt: ${e.message}`);
951
+ }
952
+ }
953
+ if (config.generators.llmsTxt) {
954
+ try {
955
+ const content = generateLlmsTxt(config);
956
+ writeFileSync(join(outDir, "llms.txt"), content, "utf-8");
957
+ files.push("llms.txt");
958
+ } catch (e) {
959
+ errors.push(`llms.txt: ${e.message}`);
960
+ }
961
+ }
962
+ if (config.generators.llmsFullTxt) {
963
+ try {
964
+ const content = generateLlmsFullTxt(config);
965
+ writeFileSync(join(outDir, "llms-full.txt"), content, "utf-8");
966
+ files.push("llms-full.txt");
967
+ } catch (e) {
968
+ errors.push(`llms-full.txt: ${e.message}`);
969
+ }
970
+ }
971
+ if (config.generators.rawMarkdown) {
972
+ try {
973
+ const generated = generatePageMarkdownFiles(config);
974
+ for (const f of generated) {
975
+ files.push(f.destination);
976
+ }
977
+ } catch (e) {
978
+ errors.push(`page-markdown: ${e.message}`);
979
+ }
980
+ try {
981
+ const copied = copyMarkdownFiles(config);
982
+ for (const f of copied) {
983
+ files.push(f.destination);
984
+ }
985
+ } catch (e) {
986
+ errors.push(`raw-markdown: ${e.message}`);
987
+ }
988
+ }
989
+ if (config.generators.manifest) {
990
+ try {
991
+ const content = generateManifest(config);
992
+ writeFileSync(join(outDir, "docs.json"), content, "utf-8");
993
+ files.push("docs.json");
994
+ } catch (e) {
995
+ errors.push(`docs.json: ${e.message}`);
996
+ }
997
+ }
998
+ if (config.generators.sitemap) {
999
+ try {
1000
+ const content = generateSitemap(config);
1001
+ writeFileSync(join(outDir, "sitemap.xml"), content, "utf-8");
1002
+ files.push("sitemap.xml");
1003
+ } catch (e) {
1004
+ errors.push(`sitemap.xml: ${e.message}`);
1005
+ }
1006
+ }
1007
+ if (config.generators.aiIndex) {
1008
+ try {
1009
+ const content = generateAIIndex(config);
1010
+ writeFileSync(join(outDir, "ai-index.json"), content, "utf-8");
1011
+ files.push("ai-index.json");
1012
+ } catch (e) {
1013
+ errors.push(`ai-index.json: ${e.message}`);
1014
+ }
1015
+ }
1016
+ if (config.generators.schema && config.schema.enabled) {
1017
+ try {
1018
+ const content = generateSchema(config);
1019
+ writeFileSync(join(outDir, "schema.json"), content, "utf-8");
1020
+ files.push("schema.json");
1021
+ } catch (e) {
1022
+ errors.push(`schema.json: ${e.message}`);
1023
+ }
1024
+ }
1025
+ return { files, errors };
1026
+ }
1027
+
1028
+ // src/core/html-extract.ts
1029
+ function extractTextFromHtml(html) {
1030
+ let text = html;
1031
+ text = text.replace(/<script[\s\S]*?<\/script>/gi, "");
1032
+ text = text.replace(/<style[\s\S]*?<\/style>/gi, "");
1033
+ text = text.replace(/<svg[\s\S]*?<\/svg>/gi, "");
1034
+ const mainMatch = text.match(/<main[^>]*>([\s\S]*)<\/main>/i);
1035
+ if (mainMatch) {
1036
+ text = mainMatch[1];
1037
+ } else {
1038
+ text = text.replace(/<nav[\s\S]*?<\/nav>/gi, "");
1039
+ text = text.replace(/<header[\s\S]*?<\/header>/gi, "");
1040
+ text = text.replace(/<footer[\s\S]*?<\/footer>/gi, "");
1041
+ }
1042
+ text = text.replace(/<a[^>]+href=["']([^"']*)["'][^>]*>([\s\S]*?)<\/a>/gi, (_, url, inner) => {
1043
+ if (/<(?:h[1-6]|div|p|section)[^>]*>/i.test(inner)) {
1044
+ const cleanInner = inner.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
1045
+ return `
1046
+ [${cleanInner.slice(0, 120).trim()}](${url})
1047
+ `;
1048
+ }
1049
+ return `[${inner}](${url})`;
1050
+ });
1051
+ text = text.replace(/<h1[^>]*>([\s\S]*?)<\/h1>/gi, "\n\n## $1\n\n");
1052
+ text = text.replace(/<h2[^>]*>([\s\S]*?)<\/h2>/gi, "\n\n## $1\n\n");
1053
+ text = text.replace(/<h3[^>]*>([\s\S]*?)<\/h3>/gi, "\n\n### $1\n\n");
1054
+ text = text.replace(/<h4[^>]*>([\s\S]*?)<\/h4>/gi, "\n\n#### $1\n\n");
1055
+ text = text.replace(/<h5[^>]*>([\s\S]*?)<\/h5>/gi, "\n\n##### $1\n\n");
1056
+ text = text.replace(/<h6[^>]*>([\s\S]*?)<\/h6>/gi, "\n\n###### $1\n\n");
1057
+ text = text.replace(/<a[^>]+href=["']([^"']*)["'][^>]*>([\s\S]*?)<\/a>/gi, "[$2]($1)");
1058
+ text = text.replace(/<(?:strong|b)[^>]*>([\s\S]*?)<\/(?:strong|b)>/gi, "**$1**");
1059
+ text = text.replace(/<(?:em|i)[^>]*>([\s\S]*?)<\/(?:em|i)>/gi, "*$1*");
1060
+ text = text.replace(/<li[^>]*>([\s\S]*?)<\/li>/gi, "\n- $1");
1061
+ text = text.replace(/<blockquote[^>]*>([\s\S]*?)<\/blockquote>/gi, "\n\n> $1\n\n");
1062
+ text = text.replace(/<hr[^>]*\/?>/gi, "\n\n---\n\n");
1063
+ text = text.replace(/<br[^>]*\/?>/gi, "\n");
1064
+ text = text.replace(/<\/p>/gi, "\n\n");
1065
+ text = text.replace(/<p[^>]*>/gi, "");
1066
+ text = text.replace(/<\/?(?:div|section|article|header|main|aside|figure|figcaption|table|thead|tbody|tr|td|th|ul|ol|dl|dt|dd)[^>]*>/gi, "\n");
1067
+ text = text.replace(/<[^>]+>/g, "");
1068
+ text = text.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&nbsp;/g, " ").replace(/&copy;/g, "(c)");
1069
+ text = text.replace(/[\u{1F1E0}-\u{1FAFF}\u{2600}-\u{27BF}\u{FE00}-\u{FE0F}\u{200D}\u{20E3}]/gu, "");
1070
+ text = text.split("\n").map((l) => l.replace(/\s+/g, " ").trim()).join("\n");
1071
+ text = text.replace(/\n{3,}/g, "\n\n");
1072
+ text = text.replace(/\[[\s\n]+/g, "[").replace(/[\s\n]+\]/g, "]");
1073
+ text = text.replace(/(#{2,6})\s*\n+\s*/g, "$1 ");
1074
+ text = text.replace(/^#{2,6}\s*$/gm, "");
1075
+ text = text.replace(/\n{3,}/g, "\n\n");
1076
+ return text.trim().slice(0, 8e3);
1077
+ }
1078
+ function extractTitle2(html) {
1079
+ var _a, _b;
1080
+ const match = html.match(/<title>([^<]*)<\/title>/i);
1081
+ if (!match) return void 0;
1082
+ return ((_b = (_a = match[1]) == null ? void 0 : _a.split("|")[0]) == null ? void 0 : _b.trim()) || match[1];
1083
+ }
1084
+ function extractDescription(html) {
1085
+ const match = html.match(/<meta\s+name=["']description["']\s+content=["']([^"']*)["']/i);
1086
+ return match == null ? void 0 : match[1];
1087
+ }
1088
+ function htmlToMarkdown(html, pagePath, config) {
1089
+ const rawTitle = extractTitle2(html);
1090
+ const description = extractDescription(html);
1091
+ const textContent = extractTextFromHtml(html);
1092
+ const pageUrl = pagePath === "/" ? config.url : `${config.url.replace(/\/$/, "")}${pagePath}`;
1093
+ const lines = [];
1094
+ lines.push("---");
1095
+ if (rawTitle) lines.push(`title: "${rawTitle}"`);
1096
+ if (description) lines.push(`description: "${description}"`);
1097
+ lines.push(`url: ${pageUrl}`);
1098
+ lines.push(`source: ${pageUrl}`);
1099
+ lines.push(`generated_by: aeo.js`);
1100
+ lines.push("---", "");
1101
+ if (rawTitle) lines.push(`# ${rawTitle}`, "");
1102
+ if (description) lines.push(`${description}`, "");
1103
+ if (textContent) lines.push(textContent);
1104
+ return lines.join("\n");
1105
+ }
1106
+
1107
+ // src/core/opengraph.ts
1108
+ function generateOGTags(page, config) {
1109
+ const tags = [];
1110
+ const pageUrl = page.pathname === "/" ? config.url : `${config.url.replace(/\/$/, "")}${page.pathname}`;
1111
+ const title = page.title || config.title;
1112
+ const description = page.description || config.description;
1113
+ tags.push({ property: "og:type", content: config.og.type });
1114
+ tags.push({ property: "og:title", content: title });
1115
+ if (description) tags.push({ property: "og:description", content: description });
1116
+ tags.push({ property: "og:url", content: pageUrl });
1117
+ tags.push({ property: "og:site_name", content: config.title });
1118
+ if (config.og.image) tags.push({ property: "og:image", content: config.og.image });
1119
+ tags.push({ name: "twitter:card", content: config.og.image ? "summary_large_image" : "summary" });
1120
+ tags.push({ name: "twitter:title", content: title });
1121
+ if (description) tags.push({ name: "twitter:description", content: description });
1122
+ if (config.og.twitterHandle) tags.push({ name: "twitter:site", content: config.og.twitterHandle });
1123
+ if (config.og.image) tags.push({ name: "twitter:image", content: config.og.image });
1124
+ return tags;
1125
+ }
1126
+ function generateOGTagsHtml(page, config) {
1127
+ const tags = generateOGTags(page, config);
1128
+ return tags.map((tag) => {
1129
+ if (tag.property) return `<meta property="${tag.property}" content="${escapeAttr(tag.content)}" />`;
1130
+ return `<meta name="${tag.name}" content="${escapeAttr(tag.content)}" />`;
1131
+ }).join("\n ");
1132
+ }
1133
+ function escapeAttr(str) {
1134
+ return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1135
+ }
1136
+
1137
+ // src/plugins/astro.ts
1138
+ function scanBuiltPages(dir, baseUrl) {
1139
+ const pages = [];
1140
+ function walk(currentDir) {
1141
+ try {
1142
+ const entries = readdirSync(currentDir);
1143
+ for (const entry of entries) {
1144
+ const fullPath = join(currentDir, entry);
1145
+ const stat = statSync(fullPath);
1146
+ if (stat.isDirectory() && !entry.startsWith(".") && entry !== "_astro") {
1147
+ walk(fullPath);
1148
+ } else if (entry === "index.html" || entry.endsWith(".html") && entry !== "404.html" && entry !== "500.html") {
1149
+ try {
1150
+ const html = readFileSync(fullPath, "utf-8");
1151
+ const title = extractTitle2(html);
1152
+ const description = extractDescription(html);
1153
+ const textContent = extractTextFromHtml(html);
1154
+ let pathname;
1155
+ const relative8 = fullPath.slice(dir.length);
1156
+ if (entry === "index.html") {
1157
+ pathname = "/" + relative8.replace(/\/?index\.html$/, "");
1158
+ if (pathname !== "/") pathname = pathname.replace(/\/$/, "");
1159
+ } else {
1160
+ pathname = "/" + relative8.replace(/\.html$/, "");
1161
+ }
1162
+ pathname = pathname.replace(/\/+/g, "/") || "/";
1163
+ pages.push({
1164
+ pathname,
1165
+ title,
1166
+ description,
1167
+ content: textContent
1168
+ });
1169
+ } catch {
1170
+ }
1171
+ }
1172
+ }
1173
+ } catch {
1174
+ }
1175
+ }
1176
+ walk(dir);
1177
+ return pages;
1178
+ }
1179
+ function scanDevPages(pagesDir) {
1180
+ const pages = [];
1181
+ function walk(currentDir, base) {
1182
+ try {
1183
+ const entries = readdirSync(currentDir);
1184
+ for (const entry of entries) {
1185
+ const fullPath = join(currentDir, entry);
1186
+ const stat = statSync(fullPath);
1187
+ if (stat.isDirectory() && !entry.startsWith(".") && !entry.startsWith("_")) {
1188
+ walk(fullPath, base);
1189
+ } else if (entry.endsWith(".astro") || entry.endsWith(".md") || entry.endsWith(".mdx")) {
1190
+ if (entry.startsWith("404") || entry.startsWith("500") || entry.startsWith("[")) continue;
1191
+ const relative8 = fullPath.slice(base.length);
1192
+ let pathname = "/" + relative8.replace(/\.(astro|md|mdx)$/, "");
1193
+ if (pathname.endsWith("/index")) pathname = pathname.slice(0, -6) || "/";
1194
+ pathname = pathname.replace(/\/+/g, "/") || "/";
1195
+ const name = entry.replace(/\.(astro|md|mdx)$/, "");
1196
+ pages.push({
1197
+ pathname,
1198
+ title: name === "index" ? void 0 : name.charAt(0).toUpperCase() + name.slice(1)
1199
+ });
1200
+ }
1201
+ }
1202
+ } catch {
1203
+ }
1204
+ }
1205
+ const resolvedPagesDir = join(process.cwd(), pagesDir);
1206
+ if (existsSync(resolvedPagesDir)) {
1207
+ walk(resolvedPagesDir, resolvedPagesDir);
1208
+ }
1209
+ return pages;
1210
+ }
1211
+ function aeoAstroIntegration(options = {}) {
1212
+ let resolvedConfig = resolveConfig(options);
1213
+ let astroConfig;
1214
+ return {
1215
+ name: "aeo-astro",
1216
+ hooks: {
1217
+ "astro:config:setup": ({ config, command, injectScript }) => {
1218
+ astroConfig = config;
1219
+ resolvedConfig = resolveConfig({
1220
+ ...options,
1221
+ contentDir: options.contentDir || "src/content",
1222
+ outDir: options.outDir || (command === "build" ? config.outDir.pathname : config.publicDir.pathname)
1223
+ });
1224
+ if (command === "dev") {
1225
+ const publicPath = config.publicDir.pathname;
1226
+ if (!existsSync(publicPath)) {
1227
+ mkdirSync(publicPath, { recursive: true });
1228
+ }
1229
+ }
1230
+ if (resolvedConfig.widget.enabled && injectScript) {
1231
+ const widgetConfig = JSON.stringify({
1232
+ title: resolvedConfig.title,
1233
+ description: resolvedConfig.description,
1234
+ url: resolvedConfig.url,
1235
+ widget: resolvedConfig.widget
1236
+ });
1237
+ injectScript(
1238
+ "page",
1239
+ `import { AeoWidget } from 'aeo.js/widget';
1240
+ let __aeoWidget;
1241
+ function __initAeoWidget() {
1242
+ if (__aeoWidget) __aeoWidget.destroy();
1243
+ try {
1244
+ __aeoWidget = new AeoWidget({ config: ${widgetConfig} });
1245
+ } catch (e) {
1246
+ console.warn('[aeo.js] Widget initialization failed:', e);
1247
+ }
1248
+ }
1249
+ // astro:page-load fires on initial load AND after every View Transition navigation
1250
+ document.addEventListener('astro:page-load', __initAeoWidget);
1251
+ // Fallback for Astro sites without View Transitions
1252
+ if (!document.querySelector('meta[name="astro-view-transitions-enabled"]')) {
1253
+ if (document.readyState === 'loading') {
1254
+ document.addEventListener('DOMContentLoaded', __initAeoWidget);
1255
+ } else {
1256
+ __initAeoWidget();
1257
+ }
1258
+ }`
1259
+ );
1260
+ }
1261
+ },
1262
+ "astro:build:done": async ({ dir, logger }) => {
1263
+ const buildLogger = logger.fork("aeo.js");
1264
+ buildLogger.info("Generating AEO files...");
1265
+ const outPath = dir instanceof URL ? dir.pathname : dir || astroConfig.outDir.pathname;
1266
+ options.url || astroConfig.site || "https://example.com";
1267
+ const discoveredPages = scanBuiltPages(outPath);
1268
+ buildLogger.info(`Discovered ${discoveredPages.length} pages from build output`);
1269
+ resolvedConfig = resolveConfig({
1270
+ ...options,
1271
+ outDir: options.outDir || outPath,
1272
+ pages: [...options.pages || [], ...discoveredPages]
1273
+ });
1274
+ try {
1275
+ const result = await generateAEOFiles(resolvedConfig);
1276
+ if (result.files.length > 0) {
1277
+ buildLogger.info(`Generated ${result.files.length} files`);
1278
+ result.files.forEach((file) => {
1279
+ buildLogger.debug(` - ${file}`);
1280
+ });
1281
+ }
1282
+ if (result.errors.length > 0) {
1283
+ buildLogger.error("Errors during generation:");
1284
+ result.errors.forEach((error) => {
1285
+ buildLogger.error(` - ${error}`);
1286
+ });
1287
+ }
1288
+ } catch (error) {
1289
+ buildLogger.error(`Failed to generate AEO files: ${error}`);
1290
+ }
1291
+ },
1292
+ "astro:server:setup": async ({ server, logger }) => {
1293
+ const devLogger = logger.fork("aeo.js");
1294
+ devLogger.info("Generating AEO files for development...");
1295
+ const devPages = scanDevPages("src/pages");
1296
+ resolvedConfig = resolveConfig({
1297
+ ...options,
1298
+ contentDir: options.contentDir || "src/content",
1299
+ outDir: resolvedConfig.outDir,
1300
+ pages: [...options.pages || [], ...devPages]
1301
+ });
1302
+ try {
1303
+ const result = await generateAEOFiles(resolvedConfig);
1304
+ if (result.files.length > 0) {
1305
+ devLogger.info(`Generated ${result.files.length} files`);
1306
+ }
1307
+ if (result.errors.length > 0) {
1308
+ devLogger.error("Errors during generation:", result.errors);
1309
+ }
1310
+ } catch (error) {
1311
+ devLogger.error(`Failed to generate AEO files: ${error}`);
1312
+ }
1313
+ const mdHandler = async (req, res, next) => {
1314
+ var _a, _b;
1315
+ if (!((_a = req.url) == null ? void 0 : _a.endsWith(".md"))) return next();
1316
+ if (req.headers["x-aeo-internal"]) return next();
1317
+ const filename = req.url.startsWith("/") ? req.url.slice(1) : req.url;
1318
+ if (resolvedConfig.contentDir) {
1319
+ const contentFile = join(process.cwd(), resolvedConfig.contentDir, filename);
1320
+ if (existsSync(contentFile)) {
1321
+ res.setHeader("Content-Type", "text/markdown; charset=utf-8");
1322
+ res.end(readFileSync(contentFile, "utf-8"));
1323
+ return;
1324
+ }
1325
+ }
1326
+ let pagePath = req.url.replace(/\.md$/, "") || "/";
1327
+ if (pagePath === "/index") pagePath = "/";
1328
+ try {
1329
+ const host = req.headers.host || "localhost:4321";
1330
+ const protocol = ((_b = req.connection) == null ? void 0 : _b.encrypted) ? "https" : "http";
1331
+ const response = await fetch(`${protocol}://${host}${pagePath}`, {
1332
+ headers: { "x-aeo-internal": "1" }
1333
+ });
1334
+ if (response.ok) {
1335
+ const html = await response.text();
1336
+ const md = htmlToMarkdown(html, pagePath, resolvedConfig);
1337
+ res.setHeader("Content-Type", "text/markdown; charset=utf-8");
1338
+ res.end(md);
1339
+ return;
1340
+ }
1341
+ } catch {
1342
+ }
1343
+ const filepath = join(resolvedConfig.outDir, filename);
1344
+ if (existsSync(filepath)) {
1345
+ res.setHeader("Content-Type", "text/markdown; charset=utf-8");
1346
+ res.end(readFileSync(filepath, "utf-8"));
1347
+ return;
1348
+ }
1349
+ next();
1350
+ };
1351
+ server.middlewares.stack.unshift({ route: "", handle: mdHandler });
1352
+ if (resolvedConfig.contentDir) {
1353
+ const contentPath = join(process.cwd(), resolvedConfig.contentDir);
1354
+ server.watcher.add(join(contentPath, "**/*.md"));
1355
+ server.watcher.add(join(contentPath, "**/*.mdx"));
1356
+ server.watcher.on("change", async (file) => {
1357
+ if (file.endsWith(".md") || file.endsWith(".mdx")) {
1358
+ devLogger.info("Content file changed, regenerating AEO files...");
1359
+ try {
1360
+ const result = await generateAEOFiles(resolvedConfig);
1361
+ if (result.files.length > 0) {
1362
+ devLogger.info(`Regenerated ${result.files.length} files`);
1363
+ }
1364
+ if (result.errors.length > 0) {
1365
+ devLogger.error("Errors during regeneration:", result.errors);
1366
+ }
1367
+ } catch (error) {
1368
+ devLogger.error(`Failed to regenerate AEO files: ${error}`);
1369
+ }
1370
+ }
1371
+ });
1372
+ }
1373
+ }
1374
+ }
1375
+ };
1376
+ }
1377
+ var AeoMetaTags = ({ config, page }) => {
1378
+ const resolvedConfig = resolveConfig(config);
1379
+ const currentPage = page || { pathname: "/" };
1380
+ const pageEntry = {
1381
+ pathname: currentPage.pathname || "/",
1382
+ title: currentPage.title,
1383
+ description: currentPage.description,
1384
+ content: currentPage.content
1385
+ };
1386
+ let jsonLd = "";
1387
+ if (resolvedConfig.schema.enabled) {
1388
+ const schemas = generatePageSchemas(pageEntry, resolvedConfig);
1389
+ jsonLd = generateJsonLdScript(schemas);
1390
+ }
1391
+ let ogTags = "";
1392
+ if (resolvedConfig.og.enabled) {
1393
+ ogTags = generateOGTagsHtml(pageEntry, resolvedConfig);
1394
+ }
1395
+ return `
1396
+ <link rel="alternate" type="text/plain" href="/llms.txt" title="LLM Summary" />
1397
+ <link rel="alternate" type="text/plain" href="/llms-full.txt" title="Full Content for LLMs" />
1398
+ <link rel="alternate" type="application/json" href="/docs.json" title="Documentation Manifest" />
1399
+ <link rel="alternate" type="application/json" href="/ai-index.json" title="AI-Optimized Index" />
1400
+ <meta name="aeo:title" content="${resolvedConfig.title}" />
1401
+ <meta name="aeo:description" content="${resolvedConfig.description}" />
1402
+ <meta name="aeo:url" content="${resolvedConfig.url}" />
1403
+ ${ogTags}
1404
+ ${jsonLd}
1405
+ `;
1406
+ };
1407
+ function defineAeoConfig(config) {
1408
+ return config;
1409
+ }
1410
+ var astro_default = aeoAstroIntegration;
1411
+
1412
+ export { AeoMetaTags, aeoAstroIntegration, astro_default as default, defineAeoConfig };
1413
+ //# sourceMappingURL=astro.mjs.map
1414
+ //# sourceMappingURL=astro.mjs.map