diff --git a/docs/app.config.ts b/docs/app.config.ts index aa2fc88..4b81c32 100644 --- a/docs/app.config.ts +++ b/docs/app.config.ts @@ -12,123 +12,111 @@ import { matter } from "vfile-matter"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -export default defineConfig({ - extensions: ["mdx"], - vite: () => { - // https://andi.dev/blog/how-solid-start-blog - const processFiles = () => { - const docs: { - headings?: { depth: number; slug: string; text: string }[]; - frontmatter?: { - title: string; - description: string; - component: boolean; - link: { - doc: string; - api: string; - }; - toc: boolean; - }; - slug?: string; - }[] = []; - - const outputFile = resolve(".content/index.js"); - const docsDir = resolve("src/routes/docs"); +// https://andi.dev/blog/how-solid-start-blog +const processFiles = () => { + const docs: { + headings?: { depth: number; slug: string; text: string }[]; + frontmatter?: { + title: string; + description: string; + component: boolean; + link: { + doc: string; + api: string; + }; + toc: boolean; + }; + slug?: string; + }[] = []; - if (!existsSync(".content")) { - mkdirSync(".content", { recursive: true }); - } + const outputFile = resolve(".content/index.js"); + const docsDir = resolve("src/routes/docs"); - (function processDirectory(currentDir: string) { - const items = readdirSync(currentDir, { withFileTypes: true }); + if (!existsSync(".content")) { + mkdirSync(".content", { recursive: true }); + } - for (const item of items) { - const fullPath = join(currentDir, item.name); + (function processDirectory(currentDir: string) { + const items = readdirSync(currentDir, { withFileTypes: true }); - if (item.isDirectory()) { - processDirectory(fullPath); - } else if (item.isFile() && item.name.endsWith(".mdx")) { - const fileContent = readSync(fullPath, "utf-8"); - matter(fileContent); + for (const item of items) { + const fullPath = join(currentDir, item.name); - const relativePath = relative(docsDir, fullPath); - const slug = `/docs/${relativePath.replace(/\.mdx$/, "").replace(/\\/g, "/")}`; + if (item.isDirectory()) { + processDirectory(fullPath); + } else if (item.isFile() && item.name.endsWith(".mdx")) { + const fileContent = readSync(fullPath, "utf-8"); + matter(fileContent); - const headings: { depth: number; slug: string; text: string }[] = - []; - const regex = /^(#{1,6})\s+(.+)$/gm; - let match: RegExpExecArray | null; + const relativePath = relative(docsDir, fullPath); + const slug = `/docs/${relativePath.replace(/\.mdx$/, "").replace(/\\/g, "/")}`; - // biome-ignore lint/suspicious/noAssignInExpressions: - while ((match = regex.exec(String(fileContent))) !== null) { - const depth = match[1].length; - const text = match[2].trim(); + const headings: { depth: number; slug: string; text: string }[] = []; + const regex = /^(#{1,6})\s+(.+)$/gm; + let match: RegExpExecArray | null; - headings.push({ - depth, - text, - slug: text - .toLowerCase() - .replace(/[^a-z0-9]+/g, "-") - .replace(/(^-|-$)/g, ""), - }); - } + // biome-ignore lint/suspicious/noAssignInExpressions: + while ((match = regex.exec(String(fileContent))) !== null) { + const depth = match[1].length; + const text = match[2].trim(); - docs.push({ - frontmatter: fileContent.data - .matter as (typeof docs)[0]["frontmatter"], - headings, - slug, - }); - } + headings.push({ + depth, + text, + slug: text + .toLowerCase() + .replace(/[^a-z0-9]+/g, "-") + .replace(/(^-|-$)/g, ""), + }); } - })(docsDir); - writeFileSync( - outputFile, - `export const allDocs = ${JSON.stringify(docs, null, 2)}`, - "utf-8", - ); - }; + docs.push({ + frontmatter: fileContent.data + .matter as (typeof docs)[0]["frontmatter"], + headings, + slug, + }); + } + } + })(docsDir); - return { - plugins: [ - { - name: "posts-gen", - buildStart() { - processFiles(); - }, - configureServer(server) { - server.watcher.on("change", (filePath) => { - if (filePath.includes("/src/routes/docs")) { - processFiles(); - } - }); - }, + writeFileSync( + outputFile, + `export const allDocs = ${JSON.stringify(docs, null, 2)}`, + "utf-8", + ); +}; + +export default defineConfig({ + ssr: false, + extensions: ["mdx"], + vite: { + plugins: [ + { + name: "posts-gen", + buildStart() { + processFiles(); }, - mdx({ - jsx: true, - jsxImportSource: "solid-js", - providerImportSource: "@/components/mdx", - remarkPlugins: [remarkGfm, remarkFrontmatter], - rehypePlugins: [rehypeSlug], - }), - ], - resolve: { - alias: { - "@": resolve(__dirname, "./src"), - "#content": resolve(__dirname, "./.content"), + configureServer(server) { + server.watcher.on("change", (filePath) => { + if (filePath.includes("/src/routes/docs")) { + processFiles(); + } + }); }, }, - }; - }, - server: { - prerender: { - crawlLinks: true, - }, - esbuild: { - options: { - target: "esnext", + mdx({ + jsx: true, + jsxImportSource: "solid-js", + providerImportSource: "@/components/mdx", + remarkPlugins: [remarkGfm, remarkFrontmatter], + rehypePlugins: [rehypeSlug], + }), + ], + resolve: { + alias: { + "@": resolve(__dirname, "./src"), + "#content": resolve(__dirname, "./.content"), }, }, }, diff --git a/turbo.json b/turbo.json index bd8fb08..5bfba8e 100644 --- a/turbo.json +++ b/turbo.json @@ -1,26 +1,17 @@ { - "$schema": "https://turbo.build/schema.json", - "globalDependencies": [ - "**/.env.*local" - ], - "tasks": { - "build": { - "dependsOn": [ - "^build" - ], - "outputs": [ - ".next/**", - "!.next/cache/**" - ] - }, - "check": { - "dependsOn": [ - "^check" - ] - }, - "dev": { - "cache": false, - "persistent": true - } - } + "$schema": "https://turbo.build/schema.json", + "globalDependencies": ["**/.env.*local"], + "tasks": { + "build": { + "dependsOn": ["^build"], + "outputs": [".vercel/output/**", ".vinxi/**"] + }, + "check": { + "dependsOn": ["^check"] + }, + "dev": { + "cache": false, + "persistent": true + } + } }