nuxt-ai-ready 0.3.7 → 0.3.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/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mkdir, stat, open, access, appendFile } from 'node:fs/promises';
|
|
1
2
|
import { dirname, join } from 'node:path';
|
|
2
3
|
import { useLogger, useNuxt, defineNuxtModule, createResolver, addTypeTemplate, hasNuxtModule, addServerHandler, addPlugin, extendPages } from '@nuxt/kit';
|
|
3
4
|
import defu from 'defu';
|
|
@@ -9,7 +10,6 @@ import { $fetch } from 'ofetch';
|
|
|
9
10
|
import { isTest, isCI } from 'std-env';
|
|
10
11
|
import { createHash } from 'node:crypto';
|
|
11
12
|
import { mkdirSync, createWriteStream } from 'node:fs';
|
|
12
|
-
import { mkdir, stat, open } from 'node:fs/promises';
|
|
13
13
|
import { encodeLines } from '@toon-format/toon';
|
|
14
14
|
import { createLlmsTxtStream } from 'mdream/llms-txt';
|
|
15
15
|
import { createStorage } from 'unstorage';
|
|
@@ -602,8 +602,23 @@ export {}
|
|
|
602
602
|
setupPrerenderHandler(mergedLlmsTxt, config.timestamps);
|
|
603
603
|
}
|
|
604
604
|
nuxt.options.nitro.routeRules = nuxt.options.nitro.routeRules || {};
|
|
605
|
+
nuxt.options.nitro.routeRules["/llms.txt"] = { headers: { "Content-Type": "text/plain; charset=utf-8" } };
|
|
606
|
+
nuxt.options.nitro.routeRules["/llms-full.txt"] = { headers: { "Content-Type": "text/plain; charset=utf-8" } };
|
|
605
607
|
nuxt.options.nitro.routeRules["/llms.toon"] = { headers: { "Content-Type": "text/toon; charset=utf-8" } };
|
|
606
608
|
nuxt.options.nitro.routeRules["/llms-full.toon"] = { headers: { "Content-Type": "text/toon; charset=utf-8" } };
|
|
609
|
+
nuxt.hooks.hook("nitro:build:before", (nitro) => {
|
|
610
|
+
nitro.hooks.hook("compiled", async () => {
|
|
611
|
+
const headersPath = join(nitro.options.output.publicDir, "_headers");
|
|
612
|
+
const exists = await access(headersPath).then(() => true).catch(() => false);
|
|
613
|
+
if (exists) {
|
|
614
|
+
await appendFile(headersPath, `
|
|
615
|
+
/*.md
|
|
616
|
+
Content-Type: text/markdown; charset=utf-8
|
|
617
|
+
`);
|
|
618
|
+
logger.debug("Appended .md charset header to _headers");
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
});
|
|
607
622
|
}
|
|
608
623
|
});
|
|
609
624
|
|
|
@@ -3,7 +3,7 @@ import { useEvent } from "nitropack/runtime";
|
|
|
3
3
|
export default {
|
|
4
4
|
uri: "resource://nuxt-ai-ready/pages",
|
|
5
5
|
name: "All Pages",
|
|
6
|
-
description: "Page-level metadata (route, title, description,
|
|
6
|
+
description: "Page-level metadata (route, title, description, headings, chunkIds, updatedAt) in TOON format. Each page includes chunkIds to join with pages-chunks resource for chunk-level content. TOON is token-efficient JSON encoding (see https://toonformat.dev)",
|
|
7
7
|
metadata: {
|
|
8
8
|
mimeType: "text/toon"
|
|
9
9
|
},
|
|
@@ -3,14 +3,6 @@ import { extractionPlugin } from "mdream/plugins";
|
|
|
3
3
|
import { withMinimalPreset } from "mdream/preset/minimal";
|
|
4
4
|
import { htmlToMarkdownSplitChunks } from "mdream/splitter";
|
|
5
5
|
import { estimateTokenCount } from "tokenx";
|
|
6
|
-
function stripFrontmatter(text) {
|
|
7
|
-
if (!text.startsWith("---\n"))
|
|
8
|
-
return text;
|
|
9
|
-
const endIdx = text.indexOf("\n---", 4);
|
|
10
|
-
if (endIdx === -1)
|
|
11
|
-
return text;
|
|
12
|
-
return text.slice(endIdx + 4).trimStart();
|
|
13
|
-
}
|
|
14
6
|
function normalizeWhitespace(text) {
|
|
15
7
|
return text.replace(/\u00A0/g, " ");
|
|
16
8
|
}
|
|
@@ -42,7 +34,7 @@ export function convertHtmlToMarkdownChunks(html, url, mdreamOptions) {
|
|
|
42
34
|
options.plugins = [extractPlugin, ...options.plugins || []];
|
|
43
35
|
}
|
|
44
36
|
const rawMarkdown = htmlToMarkdown(html, options);
|
|
45
|
-
const markdown = normalizeWhitespace(
|
|
37
|
+
const markdown = normalizeWhitespace(rawMarkdown);
|
|
46
38
|
const rawChunks = htmlToMarkdownSplitChunks(html, {
|
|
47
39
|
...options,
|
|
48
40
|
headersToSplitOn: [TagIdMap.h1, TagIdMap.h2, TagIdMap.h3],
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-ai-ready",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.8",
|
|
5
5
|
"description": "Best practice AI & LLM discoverability for Nuxt sites.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"unstorage": "^1.17.3"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@antfu/eslint-config": "^6.
|
|
52
|
+
"@antfu/eslint-config": "^6.6.1",
|
|
53
53
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
54
54
|
"@headlessui/vue": "^1.7.23",
|
|
55
55
|
"@nuxt/content": "^3.9.0",
|