|
| 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