aeo.js 0.0.7 → 0.0.9

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 (68) hide show
  1. package/README.md +119 -164
  2. package/dist/angular.d.mts +1 -1
  3. package/dist/angular.d.ts +1 -1
  4. package/dist/angular.js +69 -13
  5. package/dist/angular.js.map +1 -1
  6. package/dist/angular.mjs +69 -13
  7. package/dist/angular.mjs.map +1 -1
  8. package/dist/astro.d.mts +1 -1
  9. package/dist/astro.d.ts +1 -1
  10. package/dist/astro.js +78 -18
  11. package/dist/astro.js.map +1 -1
  12. package/dist/astro.mjs +78 -18
  13. package/dist/astro.mjs.map +1 -1
  14. package/dist/cli.js +84 -27
  15. package/dist/cli.js.map +1 -1
  16. package/dist/cli.mjs +84 -27
  17. package/dist/cli.mjs.map +1 -1
  18. package/dist/index.d.mts +2 -2
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +89 -29
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +89 -29
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/next.d.mts +1 -1
  25. package/dist/next.d.ts +1 -1
  26. package/dist/next.js +71 -15
  27. package/dist/next.js.map +1 -1
  28. package/dist/next.mjs +71 -15
  29. package/dist/next.mjs.map +1 -1
  30. package/dist/nuxt.d.mts +1 -1
  31. package/dist/nuxt.d.ts +1 -1
  32. package/dist/nuxt.js +69 -13
  33. package/dist/nuxt.js.map +1 -1
  34. package/dist/nuxt.mjs +69 -13
  35. package/dist/nuxt.mjs.map +1 -1
  36. package/dist/react.d.mts +1 -1
  37. package/dist/react.d.ts +1 -1
  38. package/dist/react.js +52 -7
  39. package/dist/react.js.map +1 -1
  40. package/dist/react.mjs +52 -7
  41. package/dist/react.mjs.map +1 -1
  42. package/dist/{types-Cn_Qbkmg.d.mts → types-BlLNcw-X.d.mts} +2 -0
  43. package/dist/{types-Cn_Qbkmg.d.ts → types-BlLNcw-X.d.ts} +2 -0
  44. package/dist/vite.d.mts +1 -1
  45. package/dist/vite.d.ts +1 -1
  46. package/dist/vite.js +94 -20
  47. package/dist/vite.js.map +1 -1
  48. package/dist/vite.mjs +94 -20
  49. package/dist/vite.mjs.map +1 -1
  50. package/dist/vue.d.mts +1 -1
  51. package/dist/vue.d.ts +1 -1
  52. package/dist/vue.js +52 -7
  53. package/dist/vue.js.map +1 -1
  54. package/dist/vue.mjs +52 -7
  55. package/dist/vue.mjs.map +1 -1
  56. package/dist/webpack.d.mts +1 -1
  57. package/dist/webpack.d.ts +1 -1
  58. package/dist/webpack.js +69 -13
  59. package/dist/webpack.js.map +1 -1
  60. package/dist/webpack.mjs +69 -13
  61. package/dist/webpack.mjs.map +1 -1
  62. package/dist/widget.d.mts +1 -1
  63. package/dist/widget.d.ts +1 -1
  64. package/dist/widget.js +52 -7
  65. package/dist/widget.js.map +1 -1
  66. package/dist/widget.mjs +52 -7
  67. package/dist/widget.mjs.map +1 -1
  68. package/package.json +1 -1
package/dist/astro.mjs CHANGED
@@ -77,10 +77,19 @@ function generateRobotsTxt(config) {
77
77
  }
78
78
  lines.push("# Default for all other bots");
79
79
  lines.push("User-agent: *");
80
- lines.push("Allow: /");
80
+ for (const path of config.robots.allow.length > 0 ? config.robots.allow : ["/"]) {
81
+ lines.push(`Allow: ${path}`);
82
+ }
83
+ for (const path of config.robots.disallow) {
84
+ lines.push(`Disallow: ${path}`);
85
+ }
86
+ if (config.robots.crawlDelay > 0) {
87
+ lines.push(`Crawl-delay: ${config.robots.crawlDelay}`);
88
+ }
81
89
  lines.push("");
82
- if (config.url) {
83
- lines.push(`Sitemap: ${config.url}/sitemap.xml`);
90
+ const sitemapUrl = config.robots.sitemap || (config.url ? `${config.url}/sitemap.xml` : "");
91
+ if (sitemapUrl) {
92
+ lines.push(`Sitemap: ${sitemapUrl}`);
84
93
  }
85
94
  lines.push("");
86
95
  lines.push("# AEO (Answer Engine Optimization) files");
@@ -162,7 +171,7 @@ function detectFramework(projectRoot = process.cwd()) {
162
171
  };
163
172
  }
164
173
  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;
174
+ 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;
166
175
  const frameworkInfo = detectFramework();
167
176
  return {
168
177
  title: config.title || "My Site",
@@ -206,15 +215,16 @@ function resolveConfig(config = {}) {
206
215
  widget: {
207
216
  enabled: ((_A = config.widget) == null ? void 0 : _A.enabled) !== false,
208
217
  position: ((_B = config.widget) == null ? void 0 : _B.position) || "bottom-right",
218
+ size: ((_C = config.widget) == null ? void 0 : _C.size) || "default",
209
219
  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"
220
+ background: ((_E = (_D = config.widget) == null ? void 0 : _D.theme) == null ? void 0 : _E.background) || "rgba(18, 18, 24, 0.9)",
221
+ text: ((_G = (_F = config.widget) == null ? void 0 : _F.theme) == null ? void 0 : _G.text) || "#C0C0C5",
222
+ accent: ((_I = (_H = config.widget) == null ? void 0 : _H.theme) == null ? void 0 : _I.accent) || "#E8E8EA",
223
+ badge: ((_K = (_J = config.widget) == null ? void 0 : _J.theme) == null ? void 0 : _K.badge) || "#4ADE80"
214
224
  },
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
225
+ humanLabel: ((_L = config.widget) == null ? void 0 : _L.humanLabel) || "Human",
226
+ aiLabel: ((_M = config.widget) == null ? void 0 : _M.aiLabel) || "AI",
227
+ showBadge: ((_N = config.widget) == null ? void 0 : _N.showBadge) !== false
218
228
  }
219
229
  };
220
230
  }
@@ -271,7 +281,8 @@ function collectMarkdownFiles(dir, base = dir) {
271
281
  for (const entry of entries) {
272
282
  const fullPath = join(dir, entry);
273
283
  const stat = statSync(fullPath);
274
- if (stat.isDirectory() && !entry.startsWith(".") && entry !== "node_modules") {
284
+ const SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "public", "dist", ".next", ".nuxt", ".output", ".open-next", "coverage", "__tests__", "__mocks__"]);
285
+ if (stat.isDirectory() && !entry.startsWith(".") && !SKIP_DIRS.has(entry)) {
275
286
  files.push(...collectMarkdownFiles(fullPath, base));
276
287
  } else if (stat.isFile() && (extname(entry) === ".md" || extname(entry) === ".mdx")) {
277
288
  const content = readFileSync(fullPath, "utf-8");
@@ -614,7 +625,8 @@ function collectUrls(dir, config, base = dir) {
614
625
  for (const entry of entries) {
615
626
  const fullPath = join(dir, entry);
616
627
  const stat = statSync(fullPath);
617
- if (stat.isDirectory() && !entry.startsWith(".") && entry !== "node_modules") {
628
+ const SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "public", "dist", ".next", ".nuxt", ".output", ".open-next", "coverage", "__tests__", "__mocks__"]);
629
+ if (stat.isDirectory() && !entry.startsWith(".") && !SKIP_DIRS.has(entry)) {
618
630
  urls.push(...collectUrls(fullPath, config, base));
619
631
  } else if (stat.isFile() && (extname(entry) === ".md" || extname(entry) === ".mdx" || extname(entry) === ".html")) {
620
632
  const relativePath = relative(base, fullPath);
@@ -842,6 +854,22 @@ function generatePageSchemas(page, config) {
842
854
  }))
843
855
  });
844
856
  }
857
+ if (faqItems.length === 0) {
858
+ const howToSteps = detectHowToSteps(page.content || "");
859
+ if (howToSteps.length > 0) {
860
+ schemas.push({
861
+ "@context": "https://schema.org",
862
+ "@type": "HowTo",
863
+ name: page.title || config.title,
864
+ step: howToSteps.map((s, i) => ({
865
+ "@type": "HowToStep",
866
+ position: i + 1,
867
+ name: s.name,
868
+ text: s.text
869
+ }))
870
+ });
871
+ }
872
+ }
845
873
  const pageType = config.schema.defaultType;
846
874
  const pageSchema = {
847
875
  "@context": "https://schema.org",
@@ -918,12 +946,43 @@ function detectFaqPatterns(content) {
918
946
  }
919
947
  return items;
920
948
  }
949
+ function serializeJsonForHtml(value) {
950
+ return JSON.stringify(value).replace(/</g, "\\u003C").replace(/>/g, "\\u003E").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
951
+ }
952
+ function detectHowToSteps(content) {
953
+ const steps = [];
954
+ const lines = content.split("\n");
955
+ for (let i = 0; i < lines.length; i++) {
956
+ const line = lines[i].trim();
957
+ const stepMatch = line.match(/^#{1,6}\s+(?:Step\s+\d+[\s:.-]*|(\d+)[.)]\s*)(.+)$/i);
958
+ if (stepMatch) {
959
+ const name = (stepMatch[2] || stepMatch[1] || "").trim();
960
+ const bodyLines = [];
961
+ for (let j = i + 1; j < lines.length; j++) {
962
+ const nextLine = lines[j].trim();
963
+ if (!nextLine) {
964
+ if (bodyLines.length > 0) break;
965
+ continue;
966
+ }
967
+ if (/^#{1,6}\s/.test(nextLine)) break;
968
+ bodyLines.push(nextLine);
969
+ }
970
+ if (name) {
971
+ steps.push({
972
+ name,
973
+ text: bodyLines.join(" ").slice(0, 500)
974
+ });
975
+ }
976
+ }
977
+ }
978
+ return steps.length >= 2 ? steps : [];
979
+ }
921
980
  function generateJsonLdScript(schemas) {
922
981
  if (schemas.length === 0) return "";
923
982
  if (schemas.length === 1) {
924
- return `<script type="application/ld+json">${JSON.stringify(schemas[0])}</script>`;
983
+ return `<script type="application/ld+json">${serializeJsonForHtml(schemas[0])}</script>`;
925
984
  }
926
- return schemas.map((s) => `<script type="application/ld+json">${JSON.stringify(s)}</script>`).join("\n");
985
+ return schemas.map((s) => `<script type="application/ld+json">${serializeJsonForHtml(s)}</script>`).join("\n");
927
986
  }
928
987
  async function generateAEOFiles(configOrRoot, maybeConfig) {
929
988
  var _a;
@@ -1369,7 +1428,7 @@ if (!document.querySelector('meta[name="astro-view-transitions-enabled"]')) {
1369
1428
  devLogger.error(`Failed to generate AEO files: ${error}`);
1370
1429
  }
1371
1430
  const mdHandler = async (req, res, next) => {
1372
- var _a, _b;
1431
+ var _a;
1373
1432
  if (!((_a = req.url) == null ? void 0 : _a.endsWith(".md"))) return next();
1374
1433
  if (req.headers["x-aeo-internal"]) return next();
1375
1434
  const filename = req.url.startsWith("/") ? req.url.slice(1) : req.url;
@@ -1384,8 +1443,9 @@ if (!document.querySelector('meta[name="astro-view-transitions-enabled"]')) {
1384
1443
  let pagePath = req.url.replace(/\.md$/, "") || "/";
1385
1444
  if (pagePath === "/index") pagePath = "/";
1386
1445
  try {
1387
- const host = req.headers.host || "localhost:4321";
1388
- const protocol = ((_b = req.connection) == null ? void 0 : _b.encrypted) ? "https" : "http";
1446
+ const rawHost = req.headers.host || "localhost:4321";
1447
+ const host = /^(localhost|127\.0\.0\.1)(:\d+)?$/.test(rawHost) ? rawHost : "localhost:4321";
1448
+ const protocol = "http";
1389
1449
  const response = await fetch(`${protocol}://${host}${pagePath}`, {
1390
1450
  headers: { "x-aeo-internal": "1" }
1391
1451
  });