nuxt-ai-ready 3.3.0 → 3.3.1

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 (35) hide show
  1. package/dist/chunks/agent-skills.mjs +1 -1
  2. package/dist/chunks/prerender.mjs +24 -17
  3. package/dist/cli.mjs +259 -0
  4. package/dist/module.json +1 -1
  5. package/dist/module.mjs +1 -1
  6. package/dist/runtime/llms-txt-files.js +58 -3
  7. package/dist/runtime/llms-txt-format.js +5 -4
  8. package/dist/runtime/markdown-text.d.ts +2 -0
  9. package/dist/runtime/markdown-text.js +3 -0
  10. package/dist/runtime/server/db/drizzle/queries.d.ts +2 -6
  11. package/dist/runtime/server/db/drizzle/queries.js +30 -10
  12. package/dist/runtime/server/db/queries.d.ts +2 -6
  13. package/dist/runtime/server/db/queries.js +12 -7
  14. package/dist/runtime/server/db/schema/postgres.d.ts +30 -0
  15. package/dist/runtime/server/db/schema/postgres.js +1 -0
  16. package/dist/runtime/server/db/schema/sqlite.d.ts +32 -0
  17. package/dist/runtime/server/db/schema/sqlite.js +1 -0
  18. package/dist/runtime/server/db/schema-sql.d.ts +1 -1
  19. package/dist/runtime/server/db/schema-sql.js +2 -1
  20. package/dist/runtime/server/db/seed.d.ts +8 -0
  21. package/dist/runtime/server/db/seed.js +16 -0
  22. package/dist/runtime/server/db/shared.d.ts +3 -3
  23. package/dist/runtime/server/db/shared.js +19 -1
  24. package/dist/runtime/server/plugins/sitemap-seeder.js +9 -1
  25. package/dist/runtime/server/routes/llms.txt.get.js +4 -2
  26. package/dist/runtime/server/utils/llms-full.js +31 -5
  27. package/dist/runtime/server/utils/negotiation-response.js +3 -0
  28. package/dist/runtime/server/utils/runCron.js +1 -1
  29. package/dist/runtime/server/utils/sitemap-lastmod.d.ts +4 -0
  30. package/dist/runtime/server/utils/sitemap-lastmod.js +19 -0
  31. package/dist/runtime/server/utils/sitemap-md.js +3 -2
  32. package/dist/runtime/server/utils/sitemap.js +4 -2
  33. package/dist/runtime/server/utils.js +50 -2
  34. package/dist/shared/{nuxt-ai-ready.BwnSMqRn.mjs → nuxt-ai-ready.CKXM1jnE.mjs} +1 -2
  35. package/package.json +3 -3
@@ -3,11 +3,57 @@ import { useNitroApp } from "#nuxtseo/nitro";
3
3
  import { stripLlmsTxtDirectiveHtml } from "../llms-txt-directive.js";
4
4
  import { hoistMetaDescription } from "./utils/frontmatter.js";
5
5
  const RE_NBSP = /\u00A0/g;
6
+ const JSON_LD_MAX_BYTES = 65536;
7
+ const JSON_LD_MAX_BLOCKS = 16;
8
+ const IMAGE_META_FIELDS = [
9
+ "og:image",
10
+ "og:image:url",
11
+ "og:image:secure_url",
12
+ "og:image:type",
13
+ "og:image:width",
14
+ "og:image:height",
15
+ "og:image:alt",
16
+ "twitter:image",
17
+ "twitter:image:src",
18
+ "twitter:image:alt"
19
+ ];
20
+ function parseJsonLdBlock(text, remainingBytes) {
21
+ if (text.length > remainingBytes)
22
+ return { _tag: "Skipped" };
23
+ const content = text.trim();
24
+ if (!content)
25
+ return { _tag: "Skipped" };
26
+ let value;
27
+ try {
28
+ value = JSON.parse(text);
29
+ } catch {
30
+ return { _tag: "Skipped" };
31
+ }
32
+ const isObject = (item) => typeof item === "object" && item !== null && !Array.isArray(item);
33
+ if (!isObject(value) && !(Array.isArray(value) && value.every(isObject)))
34
+ return { _tag: "Skipped" };
35
+ const markdown = `\`\`\`json
36
+ ${content.replace(RE_NBSP, "\\u00a0")}
37
+ \`\`\``;
38
+ const bytes = new TextEncoder().encode(markdown).byteLength + 2;
39
+ if (bytes > remainingBytes)
40
+ return { _tag: "Skipped" };
41
+ return { _tag: "Preserved", markdown, bytes };
42
+ }
6
43
  function normalizeWhitespace(text) {
7
44
  return text.replace(RE_NBSP, " ");
8
45
  }
9
46
  function buildMdreamOptions(url, mdreamOptions, meta, extractUpdatedAt, additionalFields) {
10
47
  const extraction = {
48
+ "script[type]": (el) => {
49
+ if (el.attributes.type?.trim().toLowerCase() !== "application/ld+json" || meta.jsonLd.blocks.length >= JSON_LD_MAX_BLOCKS)
50
+ return;
51
+ const block = parseJsonLdBlock(el.textContent, JSON_LD_MAX_BYTES - meta.jsonLd.bytes);
52
+ if (block._tag === "Preserved") {
53
+ meta.jsonLd.blocks.push(block.markdown);
54
+ meta.jsonLd.bytes += block.bytes;
55
+ }
56
+ },
11
57
  'meta[name="keywords"]': (el) => {
12
58
  meta.metaKeywords = el.attributes.content || "";
13
59
  },
@@ -30,6 +76,7 @@ function buildMdreamOptions(url, mdreamOptions, meta, extractUpdatedAt, addition
30
76
  };
31
77
  const frontmatter = {
32
78
  additionalFields,
79
+ metaFields: [...IMAGE_META_FIELDS],
33
80
  onExtract: (fm) => {
34
81
  if (fm.title)
35
82
  meta.title = fm.title;
@@ -70,13 +117,14 @@ export function extractLastUpdated(html) {
70
117
  return void 0;
71
118
  }
72
119
  export async function convertHtmlToMarkdown(html, url, mdreamOptions, opts) {
73
- const meta = { title: "", description: "", metaKeywords: "", headings: [], textContent: [] };
120
+ const meta = { title: "", description: "", metaKeywords: "", headings: [], textContent: [], jsonLd: { blocks: [], bytes: 0 } };
74
121
  const options = buildMdreamOptions(url, mdreamOptions, meta, opts.extractUpdatedAt ?? false, opts.additionalFrontmatter ?? {});
75
122
  const nitroApp = useNitroApp();
76
123
  await nitroApp.hooks.callHook("ai-ready:mdreamConfig", options);
124
+ const convertedMarkdown = hoistMetaDescription(htmlToMarkdown(stripLlmsTxtDirectiveHtml(html), options));
77
125
  const context = {
78
126
  html,
79
- markdown: hoistMetaDescription(htmlToMarkdown(stripLlmsTxtDirectiveHtml(html), options)),
127
+ markdown: [convertedMarkdown, ...meta.jsonLd.blocks].join("\n\n"),
80
128
  route: opts.hooks.route,
81
129
  title: meta.title,
82
130
  description: meta.description,
@@ -2361,8 +2361,7 @@ export function trackDrizzleWork(event, work) { return work }
2361
2361
  src: resolve$1("./runtime/app/plugins/md-alternate.server")
2362
2362
  });
2363
2363
  if (generateLlmsTxt) {
2364
- for (const route of ["/llms.txt", "/llms/**"])
2365
- addServerHandler({ route, method: void 0, handler: resolve$1("./runtime/server/routes/llms.txt.get"), lazy: true });
2364
+ addServerHandler({ middleware: true, method: void 0, handler: resolve$1("./runtime/server/routes/llms.txt.get"), lazy: true });
2366
2365
  }
2367
2366
  if (config.llmsFullTxt !== false)
2368
2367
  addServerHandler({ route: "/llms-full.txt", method: void 0, handler: resolve$1("./runtime/server/routes/llms-full.txt.get"), lazy: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-ai-ready",
3
3
  "type": "module",
4
- "version": "3.3.0",
4
+ "version": "3.3.1",
5
5
  "description": "Best practice AI & LLM discoverability for Nuxt sites.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -71,7 +71,7 @@
71
71
  }
72
72
  },
73
73
  "dependencies": {
74
- "@mdream/js": "^2.0.1",
74
+ "@mdream/js": "^2.0.3",
75
75
  "@nuxt/kit": "^4.6.0",
76
76
  "@nuxtjs/robots": "^7.0.0",
77
77
  "@nuxtjs/sitemap": "^9.0.0",
@@ -79,7 +79,7 @@
79
79
  "confbox": "^0.3.1",
80
80
  "consola": "^3.4.2",
81
81
  "defu": "^6.1.7",
82
- "mdream": "^2.0.1",
82
+ "mdream": "^2.0.3",
83
83
  "nuxt-site-config": "^5.0.0",
84
84
  "nuxtseo-shared": "^6.0.0",
85
85
  "ohash": "^2.0.12",