Skip to content

Commit d388749

Browse files
authored
Pim 1868 (#95)
* wip * bump vocs
1 parent a41b322 commit d388749

File tree

4 files changed

+2914
-1672
lines changed

4 files changed

+2914
-1672
lines changed

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"react-dom": "latest",
4444
"viem": "^2.28.0",
4545
"vitest": "^2.0.5",
46-
"vocs": "^1.0.5",
46+
"vocs": "1.0.14-main.20250716T102132",
4747
"wagmi": "^2.5.5"
4848
},
4949
"devDependencies": {
@@ -53,10 +53,5 @@
5353
"tailwindcss": "^4.0.12",
5454
"tsx": "^4.7.1"
5555
},
56-
"packageManager": "[email protected]+sha512.38dc6fba8dba35b39340b9700112c2fe1e12f10b17134715a4aa98ccf7bb035e76fd981cf0bb384dfa98f8d6af5481c2bef2f4266a24bfa20c34eb7147ce0b5e",
57-
"pnpm": {
58-
"patchedDependencies": {
59-
60-
}
61-
}
56+
"packageManager": "[email protected]+sha512.38dc6fba8dba35b39340b9700112c2fe1e12f10b17134715a4aa98ccf7bb035e76fd981cf0bb384dfa98f8d6af5481c2bef2f4266a24bfa20c34eb7147ce0b5e"
6257
}

patches/[email protected]

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
diff --git a/_lib/vite/plugins/llms.js b/_lib/vite/plugins/llms.js
2+
index ce64c723e0165145405c8a382acc57ff553c51a6..a4ca3387880a2273a58d96fcb979cfef0a1c2a96 100644
3+
--- a/_lib/vite/plugins/llms.js
4+
+++ b/_lib/vite/plugins/llms.js
5+
@@ -13,6 +13,7 @@ import { unified } from 'unified';
6+
import { visit } from 'unist-util-visit';
7+
import { resolveVocsConfig } from '../utils/resolveVocsConfig.js';
8+
import { getRemarkPlugins } from './mdx.js';
9+
+import { resolveVocsModules } from '../utils/search.js';
10+
const remarkPlugins = getRemarkPlugins();
11+
export async function llms() {
12+
let viteConfig;
13+
@@ -36,6 +37,9 @@ export async function llms() {
14+
const llmsTxtContent = [...content, '## Docs', ''];
15+
const llmsCtxTxtContent = content;
16+
for (const file of files) {
17+
+ // Skip files that contain v0_1 in their path
18+
+ if (file.includes('v0_1')) continue;
19+
+
20+
let path = file.replace(pagesPath, '').replace(/\.[^.]*$/, '');
21+
if (path.endsWith('index'))
22+
path = path.replace('index', '').replace(/\/$/, '');
23+
@@ -45,7 +49,7 @@ export async function llms() {
24+
const parser = unified().use(remarkParse).use(remarkMdx).use(remarkStringify);
25+
for (const plugin of remarkPlugins)
26+
parser.use(plugin);
27+
- const ast = parser.parse(contents);
28+
+ const ast = parser.parse(await resolveVocsModules(file, contents));
29+
// process llms.txt content
30+
visit(ast, { type: 'heading', depth: 1 }, (n, i) => {
31+
const node = n.children[0];
32+
diff --git a/_lib/vite/utils/search.js b/_lib/vite/utils/search.js
33+
index b2c1d6548f7b263ceabf0a8d39c9973e14a01823..56d49360e530b75997edc2ba3a07675b5f37dc24 100644
34+
--- a/_lib/vite/utils/search.js
35+
+++ b/_lib/vite/utils/search.js
36+
@@ -1,5 +1,5 @@
37+
import { readFileSync } from 'node:fs';
38+
-import { join, relative, resolve } from 'node:path';
39+
+import { join, relative, resolve, extname } from 'node:path';
40+
import { pathToFileURL } from 'node:url';
41+
import { compile, run } from '@mdx-js/mdx';
42+
import debug_ from 'debug';
43+
@@ -14,6 +14,7 @@ import { getRehypePlugins, getRemarkPlugins } from '../plugins/mdx.js';
44+
import * as cache_ from './cache.js';
45+
import { hash } from './hash.js';
46+
import { slash } from './slash.js';
47+
+import { resolveVocsConfig } from '../utils/resolveVocsConfig.js';
48+
const limit = pLimit(30);
49+
export const debug = debug_('vocs:search');
50+
export async function buildIndex({ baseDir, cacheDir, }) {
51+
@@ -70,6 +71,28 @@ export function saveIndex(outDir, index, { cacheDir } = {}) {
52+
return hash_;
53+
}
54+
const remarkPlugins = getRemarkPlugins();
55+
+
56+
+export async function resolveVocsModules(filePath, file) {
57+
+ const { config } = await resolveVocsConfig()
58+
+
59+
+ // Transform imports in the file content similar to resolveVocsModules plugin
60+
+ let transformedFile = file
61+
+ if (filePath.startsWith(resolve(config.rootDir))) {
62+
+ if ([".js", ".jsx", ".ts", ".tsx", ".md", ".mdx"].includes(extname(filePath))) {
63+
+ transformedFile = file.replace(
64+
+ /import (.*) from ("|')vocs("|')/g,
65+
+ `import $1 from $2${resolve(import.meta.dirname, "../..")}.js$3`,
66+
+ )
67+
+ transformedFile = transformedFile.replace(
68+
+ /import (.*) from ("|')vocs\/components("|')/g,
69+
+ `import $1 from $2${resolve(import.meta.dirname, "../../components")}.js$3`,
70+
+ )
71+
+ }
72+
+ }
73+
+
74+
+ return transformedFile
75+
+}
76+
+
77+
export async function processMdx(filePath, file, options) {
78+
const { rehypePlugins } = options;
79+
try {

0 commit comments

Comments
 (0)