aeo.js 0.0.3 → 0.0.5
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/dist/angular.js.map +1 -1
- package/dist/angular.mjs.map +1 -1
- package/dist/astro.js +60 -2
- package/dist/astro.js.map +1 -1
- package/dist/astro.mjs +60 -2
- package/dist/astro.mjs.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/next.js.map +1 -1
- package/dist/next.mjs.map +1 -1
- package/dist/nuxt.js.map +1 -1
- package/dist/nuxt.mjs.map +1 -1
- package/dist/react.js +331 -5
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +331 -5
- package/dist/react.mjs.map +1 -1
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs.map +1 -1
- package/dist/vue.js +331 -5
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +331 -5
- package/dist/vue.mjs.map +1 -1
- package/dist/webpack.js.map +1 -1
- package/dist/webpack.mjs.map +1 -1
- package/dist/widget.d.mts +10 -0
- package/dist/widget.d.ts +10 -0
- package/dist/widget.js +331 -5
- package/dist/widget.js.map +1 -1
- package/dist/widget.mjs +331 -5
- package/dist/widget.mjs.map +1 -1
- package/package.json +1 -1
package/dist/astro.mjs
CHANGED
|
@@ -1135,7 +1135,7 @@ function escapeAttr(str) {
|
|
|
1135
1135
|
}
|
|
1136
1136
|
|
|
1137
1137
|
// src/plugins/astro.ts
|
|
1138
|
-
function scanBuiltPages(dir,
|
|
1138
|
+
function scanBuiltPages(dir, _baseUrl) {
|
|
1139
1139
|
const pages = [];
|
|
1140
1140
|
function walk(currentDir) {
|
|
1141
1141
|
try {
|
|
@@ -1164,7 +1164,8 @@ function scanBuiltPages(dir, baseUrl) {
|
|
|
1164
1164
|
pathname,
|
|
1165
1165
|
title,
|
|
1166
1166
|
description,
|
|
1167
|
-
content: textContent
|
|
1167
|
+
content: textContent,
|
|
1168
|
+
filePath: fullPath
|
|
1168
1169
|
});
|
|
1169
1170
|
} catch {
|
|
1170
1171
|
}
|
|
@@ -1208,6 +1209,55 @@ function scanDevPages(pagesDir) {
|
|
|
1208
1209
|
}
|
|
1209
1210
|
return pages;
|
|
1210
1211
|
}
|
|
1212
|
+
function escapeAttr2(str) {
|
|
1213
|
+
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
1214
|
+
}
|
|
1215
|
+
function injectHeadTags(pages, config) {
|
|
1216
|
+
let injectedCount = 0;
|
|
1217
|
+
for (const page of pages) {
|
|
1218
|
+
let html;
|
|
1219
|
+
try {
|
|
1220
|
+
html = readFileSync(page.filePath, "utf-8");
|
|
1221
|
+
} catch {
|
|
1222
|
+
continue;
|
|
1223
|
+
}
|
|
1224
|
+
const tags = [];
|
|
1225
|
+
if (!/name=["']description["']/i.test(html)) {
|
|
1226
|
+
const desc = page.description || config.description;
|
|
1227
|
+
if (desc) {
|
|
1228
|
+
tags.push(`<meta name="description" content="${escapeAttr2(desc)}" />`);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
if (!/rel=["']canonical["']/i.test(html)) {
|
|
1232
|
+
const pageUrl = page.pathname === "/" ? config.url : `${config.url.replace(/\/$/, "")}${page.pathname}`;
|
|
1233
|
+
tags.push(`<link rel="canonical" href="${escapeAttr2(pageUrl)}" />`);
|
|
1234
|
+
}
|
|
1235
|
+
if (config.og.enabled && !/property=["']og:/i.test(html)) {
|
|
1236
|
+
const ogHtml = generateOGTagsHtml(page, config);
|
|
1237
|
+
if (ogHtml) tags.push(ogHtml);
|
|
1238
|
+
}
|
|
1239
|
+
if (config.schema.enabled && !/application\/ld\+json/i.test(html)) {
|
|
1240
|
+
const siteSchemas = generateSiteSchemas(config);
|
|
1241
|
+
const pageSchemas = generatePageSchemas(page, config);
|
|
1242
|
+
const jsonLdHtml = generateJsonLdScript([...siteSchemas, ...pageSchemas]);
|
|
1243
|
+
if (jsonLdHtml) tags.push(jsonLdHtml);
|
|
1244
|
+
}
|
|
1245
|
+
if (!/rel=["']alternate["'][^>]*llms\.txt/i.test(html)) {
|
|
1246
|
+
tags.push(`<link rel="alternate" type="text/plain" href="/llms.txt" title="LLM Summary" />`);
|
|
1247
|
+
tags.push(`<link rel="alternate" type="text/plain" href="/llms-full.txt" title="Full Content for LLMs" />`);
|
|
1248
|
+
tags.push(`<link rel="alternate" type="application/json" href="/docs.json" title="Documentation Manifest" />`);
|
|
1249
|
+
tags.push(`<link rel="alternate" type="application/json" href="/ai-index.json" title="AI-Optimized Index" />`);
|
|
1250
|
+
}
|
|
1251
|
+
if (tags.length === 0) continue;
|
|
1252
|
+
const injection = "\n " + tags.join("\n ") + "\n ";
|
|
1253
|
+
const newHtml = html.replace("</head>", injection + "</head>");
|
|
1254
|
+
if (newHtml !== html) {
|
|
1255
|
+
writeFileSync(page.filePath, newHtml, "utf-8");
|
|
1256
|
+
injectedCount++;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
return injectedCount;
|
|
1260
|
+
}
|
|
1211
1261
|
function aeoAstroIntegration(options = {}) {
|
|
1212
1262
|
let resolvedConfig = resolveConfig(options);
|
|
1213
1263
|
let astroConfig;
|
|
@@ -1288,6 +1338,14 @@ if (!document.querySelector('meta[name="astro-view-transitions-enabled"]')) {
|
|
|
1288
1338
|
} catch (error) {
|
|
1289
1339
|
buildLogger.error(`Failed to generate AEO files: ${error}`);
|
|
1290
1340
|
}
|
|
1341
|
+
try {
|
|
1342
|
+
const injected = injectHeadTags(discoveredPages, resolvedConfig);
|
|
1343
|
+
if (injected > 0) {
|
|
1344
|
+
buildLogger.info(`Injected head tags into ${injected} pages`);
|
|
1345
|
+
}
|
|
1346
|
+
} catch (error) {
|
|
1347
|
+
buildLogger.error(`Failed to inject head tags: ${error}`);
|
|
1348
|
+
}
|
|
1291
1349
|
},
|
|
1292
1350
|
"astro:server:setup": async ({ server, logger }) => {
|
|
1293
1351
|
const devLogger = logger.fork("aeo.js");
|