aeo.js 0.0.6 → 0.0.8
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.d.mts +1 -1
- package/dist/angular.d.ts +1 -1
- package/dist/angular.js +65 -11
- package/dist/angular.js.map +1 -1
- package/dist/angular.mjs +65 -11
- package/dist/angular.mjs.map +1 -1
- package/dist/astro.d.mts +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +74 -16
- package/dist/astro.js.map +1 -1
- package/dist/astro.mjs +74 -16
- package/dist/astro.mjs.map +1 -1
- package/dist/cli.js +80 -25
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +80 -25
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +85 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -27
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +65 -11
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +65 -11
- package/dist/next.mjs.map +1 -1
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +65 -11
- package/dist/nuxt.js.map +1 -1
- package/dist/nuxt.mjs +65 -11
- package/dist/nuxt.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +61 -9
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +61 -9
- package/dist/react.mjs.map +1 -1
- package/dist/{types-Cn_Qbkmg.d.mts → types-BlLNcw-X.d.mts} +2 -0
- package/dist/{types-Cn_Qbkmg.d.ts → types-BlLNcw-X.d.ts} +2 -0
- package/dist/vite.d.mts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +90 -18
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +90 -18
- package/dist/vite.mjs.map +1 -1
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +61 -9
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +61 -9
- package/dist/vue.mjs.map +1 -1
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +65 -11
- package/dist/webpack.js.map +1 -1
- package/dist/webpack.mjs +65 -11
- package/dist/webpack.mjs.map +1 -1
- package/dist/widget.d.mts +1 -1
- package/dist/widget.d.ts +1 -1
- package/dist/widget.js +61 -9
- package/dist/widget.js.map +1 -1
- package/dist/widget.mjs +61 -9
- package/dist/widget.mjs.map +1 -1
- package/package.json +1 -1
package/dist/vite.mjs
CHANGED
|
@@ -83,10 +83,19 @@ function generateRobotsTxt(config) {
|
|
|
83
83
|
}
|
|
84
84
|
lines.push("# Default for all other bots");
|
|
85
85
|
lines.push("User-agent: *");
|
|
86
|
-
|
|
86
|
+
for (const path2 of config.robots.allow.length > 0 ? config.robots.allow : ["/"]) {
|
|
87
|
+
lines.push(`Allow: ${path2}`);
|
|
88
|
+
}
|
|
89
|
+
for (const path2 of config.robots.disallow) {
|
|
90
|
+
lines.push(`Disallow: ${path2}`);
|
|
91
|
+
}
|
|
92
|
+
if (config.robots.crawlDelay > 0) {
|
|
93
|
+
lines.push(`Crawl-delay: ${config.robots.crawlDelay}`);
|
|
94
|
+
}
|
|
87
95
|
lines.push("");
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
const sitemapUrl = config.robots.sitemap || (config.url ? `${config.url}/sitemap.xml` : "");
|
|
97
|
+
if (sitemapUrl) {
|
|
98
|
+
lines.push(`Sitemap: ${sitemapUrl}`);
|
|
90
99
|
}
|
|
91
100
|
lines.push("");
|
|
92
101
|
lines.push("# AEO (Answer Engine Optimization) files");
|
|
@@ -168,7 +177,7 @@ function detectFramework(projectRoot = process.cwd()) {
|
|
|
168
177
|
};
|
|
169
178
|
}
|
|
170
179
|
function resolveConfig(config = {}) {
|
|
171
|
-
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;
|
|
180
|
+
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, _N;
|
|
172
181
|
const frameworkInfo = detectFramework();
|
|
173
182
|
return {
|
|
174
183
|
title: config.title || "My Site",
|
|
@@ -212,15 +221,16 @@ function resolveConfig(config = {}) {
|
|
|
212
221
|
widget: {
|
|
213
222
|
enabled: ((_A = config.widget) == null ? void 0 : _A.enabled) !== false,
|
|
214
223
|
position: ((_B = config.widget) == null ? void 0 : _B.position) || "bottom-right",
|
|
224
|
+
size: ((_C = config.widget) == null ? void 0 : _C.size) || "default",
|
|
215
225
|
theme: {
|
|
216
|
-
background: ((
|
|
217
|
-
text: ((
|
|
218
|
-
accent: ((
|
|
219
|
-
badge: ((
|
|
226
|
+
background: ((_E = (_D = config.widget) == null ? void 0 : _D.theme) == null ? void 0 : _E.background) || "rgba(18, 18, 24, 0.9)",
|
|
227
|
+
text: ((_G = (_F = config.widget) == null ? void 0 : _F.theme) == null ? void 0 : _G.text) || "#C0C0C5",
|
|
228
|
+
accent: ((_I = (_H = config.widget) == null ? void 0 : _H.theme) == null ? void 0 : _I.accent) || "#E8E8EA",
|
|
229
|
+
badge: ((_K = (_J = config.widget) == null ? void 0 : _J.theme) == null ? void 0 : _K.badge) || "#4ADE80"
|
|
220
230
|
},
|
|
221
|
-
humanLabel: ((
|
|
222
|
-
aiLabel: ((
|
|
223
|
-
showBadge: ((
|
|
231
|
+
humanLabel: ((_L = config.widget) == null ? void 0 : _L.humanLabel) || "Human",
|
|
232
|
+
aiLabel: ((_M = config.widget) == null ? void 0 : _M.aiLabel) || "AI",
|
|
233
|
+
showBadge: ((_N = config.widget) == null ? void 0 : _N.showBadge) !== false
|
|
224
234
|
}
|
|
225
235
|
};
|
|
226
236
|
}
|
|
@@ -848,6 +858,22 @@ function generatePageSchemas(page, config) {
|
|
|
848
858
|
}))
|
|
849
859
|
});
|
|
850
860
|
}
|
|
861
|
+
if (faqItems.length === 0) {
|
|
862
|
+
const howToSteps = detectHowToSteps(page.content || "");
|
|
863
|
+
if (howToSteps.length > 0) {
|
|
864
|
+
schemas.push({
|
|
865
|
+
"@context": "https://schema.org",
|
|
866
|
+
"@type": "HowTo",
|
|
867
|
+
name: page.title || config.title,
|
|
868
|
+
step: howToSteps.map((s, i) => ({
|
|
869
|
+
"@type": "HowToStep",
|
|
870
|
+
position: i + 1,
|
|
871
|
+
name: s.name,
|
|
872
|
+
text: s.text
|
|
873
|
+
}))
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
}
|
|
851
877
|
const pageType = config.schema.defaultType;
|
|
852
878
|
const pageSchema = {
|
|
853
879
|
"@context": "https://schema.org",
|
|
@@ -924,12 +950,43 @@ function detectFaqPatterns(content) {
|
|
|
924
950
|
}
|
|
925
951
|
return items;
|
|
926
952
|
}
|
|
953
|
+
function serializeJsonForHtml(value) {
|
|
954
|
+
return JSON.stringify(value).replace(/</g, "\\u003C").replace(/>/g, "\\u003E").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
955
|
+
}
|
|
956
|
+
function detectHowToSteps(content) {
|
|
957
|
+
const steps = [];
|
|
958
|
+
const lines = content.split("\n");
|
|
959
|
+
for (let i = 0; i < lines.length; i++) {
|
|
960
|
+
const line = lines[i].trim();
|
|
961
|
+
const stepMatch = line.match(/^#{1,6}\s+(?:Step\s+\d+[\s:.-]*|(\d+)[.)]\s*)(.+)$/i);
|
|
962
|
+
if (stepMatch) {
|
|
963
|
+
const name = (stepMatch[2] || stepMatch[1] || "").trim();
|
|
964
|
+
const bodyLines = [];
|
|
965
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
966
|
+
const nextLine = lines[j].trim();
|
|
967
|
+
if (!nextLine) {
|
|
968
|
+
if (bodyLines.length > 0) break;
|
|
969
|
+
continue;
|
|
970
|
+
}
|
|
971
|
+
if (/^#{1,6}\s/.test(nextLine)) break;
|
|
972
|
+
bodyLines.push(nextLine);
|
|
973
|
+
}
|
|
974
|
+
if (name) {
|
|
975
|
+
steps.push({
|
|
976
|
+
name,
|
|
977
|
+
text: bodyLines.join(" ").slice(0, 500)
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return steps.length >= 2 ? steps : [];
|
|
983
|
+
}
|
|
927
984
|
function generateJsonLdScript(schemas) {
|
|
928
985
|
if (schemas.length === 0) return "";
|
|
929
986
|
if (schemas.length === 1) {
|
|
930
|
-
return `<script type="application/ld+json">${
|
|
987
|
+
return `<script type="application/ld+json">${serializeJsonForHtml(schemas[0])}</script>`;
|
|
931
988
|
}
|
|
932
|
-
return schemas.map((s) => `<script type="application/ld+json">${
|
|
989
|
+
return schemas.map((s) => `<script type="application/ld+json">${serializeJsonForHtml(s)}</script>`).join("\n");
|
|
933
990
|
}
|
|
934
991
|
async function generateAEOFiles(configOrRoot, maybeConfig) {
|
|
935
992
|
var _a;
|
|
@@ -1205,7 +1262,7 @@ function aeoVitePlugin(options = {}) {
|
|
|
1205
1262
|
if (result.errors.length > 0) console.error("[aeo.js] Errors:", result.errors);
|
|
1206
1263
|
}).catch((err) => console.error("[aeo.js] Failed:", err));
|
|
1207
1264
|
const mdHandler = async (req, res, next) => {
|
|
1208
|
-
var _a
|
|
1265
|
+
var _a;
|
|
1209
1266
|
if (!((_a = req.url) == null ? void 0 : _a.endsWith(".md"))) return next();
|
|
1210
1267
|
if (req.headers["x-aeo-internal"]) return next();
|
|
1211
1268
|
const filename = req.url.startsWith("/") ? req.url.slice(1) : req.url;
|
|
@@ -1220,8 +1277,9 @@ function aeoVitePlugin(options = {}) {
|
|
|
1220
1277
|
let pagePath = req.url.replace(/\.md$/, "") || "/";
|
|
1221
1278
|
if (pagePath === "/index") pagePath = "/";
|
|
1222
1279
|
try {
|
|
1223
|
-
const
|
|
1224
|
-
const
|
|
1280
|
+
const rawHost = req.headers.host || "localhost:5173";
|
|
1281
|
+
const host = /^(localhost|127\.0\.0\.1)(:\d+)?$/.test(rawHost) ? rawHost : "localhost:5173";
|
|
1282
|
+
const protocol = "http";
|
|
1225
1283
|
const response = await fetch(`${protocol}://${host}${pagePath}`, {
|
|
1226
1284
|
headers: { "x-aeo-internal": "1" }
|
|
1227
1285
|
});
|
|
@@ -1337,14 +1395,28 @@ if (typeof window !== 'undefined') {
|
|
|
1337
1395
|
description: extractDescription(html),
|
|
1338
1396
|
content: extractTextFromHtml(html)
|
|
1339
1397
|
};
|
|
1398
|
+
if (!/rel=["']canonical["']/i.test(result)) {
|
|
1399
|
+
const canonicalUrl = pagePath === "/" ? resolvedConfig.url : `${resolvedConfig.url.replace(/\/$/, "")}${pagePath}`;
|
|
1400
|
+
result = result.replace("</head>", ` <link rel="canonical" href="${canonicalUrl}" />
|
|
1401
|
+
</head>`);
|
|
1402
|
+
}
|
|
1403
|
+
if (!/name=["']description["']/i.test(result)) {
|
|
1404
|
+
const desc = pageEntry.description || resolvedConfig.description;
|
|
1405
|
+
if (desc) {
|
|
1406
|
+
const escDesc = desc.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
1407
|
+
result = result.replace("</head>", ` <meta name="description" content="${escDesc}" />
|
|
1408
|
+
</head>`);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1340
1411
|
if (resolvedConfig.og.enabled) {
|
|
1341
1412
|
const ogHtml = generateOGTagsHtml(pageEntry, resolvedConfig);
|
|
1342
1413
|
result = result.replace("</head>", ` ${ogHtml}
|
|
1343
1414
|
</head>`);
|
|
1344
1415
|
}
|
|
1345
1416
|
if (resolvedConfig.schema.enabled) {
|
|
1346
|
-
const
|
|
1347
|
-
const
|
|
1417
|
+
const siteSchemas = generateSiteSchemas(resolvedConfig);
|
|
1418
|
+
const pageSchemas = generatePageSchemas(pageEntry, resolvedConfig);
|
|
1419
|
+
const jsonLd = generateJsonLdScript([...siteSchemas, ...pageSchemas]);
|
|
1348
1420
|
if (jsonLd) {
|
|
1349
1421
|
result = result.replace("</head>", ` ${jsonLd}
|
|
1350
1422
|
</head>`);
|