From 742f3a1c99d8e1458c7a4070280e06e6f3d35f14 Mon Sep 17 00:00:00 2001 From: jer3m01 Date: Wed, 14 Feb 2024 23:48:50 +0100 Subject: [PATCH] fix: netlify config --- apps/docs/src/app.tsx | 32 +++---- .../docs/src/components/table-of-contents.tsx | 83 +++++++++---------- apps/docs/vite.config.ts | 36 ++++---- netlify.toml | 4 +- 4 files changed, 77 insertions(+), 78 deletions(-) diff --git a/apps/docs/src/app.tsx b/apps/docs/src/app.tsx index a5c68d3a..deb21dbd 100644 --- a/apps/docs/src/app.tsx +++ b/apps/docs/src/app.tsx @@ -19,22 +19,22 @@ import { getCookie } from "vinxi/server"; import toastStyles from "./examples/toast.module.css"; import { mdxComponents } from "./mdx-components"; -//export const mods = /*#__PURE__*/ import.meta.glob< -// true, -// string, -// { -// getHeadings: () => { -// depth: number; -// text: string; -// slug: string; -// }[]; -// } -//>("./routes/docs/**/*.{md,mdx}", { -// eager: true, -// query: { -// meta: "", -// }, -//}); +export const mods = /*#__PURE__*/ import.meta.glob< + true, + string, + { + getHeadings: () => { + depth: number; + text: string; + slug: string; + }[]; + } +>("./routes/docs/**/*.{md,mdx}", { + eager: true, + query: { + meta: "", + }, +}); function getServerCookies() { "use server"; diff --git a/apps/docs/src/components/table-of-contents.tsx b/apps/docs/src/components/table-of-contents.tsx index be82cc33..503272ca 100644 --- a/apps/docs/src/components/table-of-contents.tsx +++ b/apps/docs/src/components/table-of-contents.tsx @@ -3,7 +3,6 @@ import { clsx } from "clsx"; import { Accessor, For, - Setter, Suspense, createEffect, createSignal, @@ -11,7 +10,7 @@ import { onCleanup, } from "solid-js"; import { isServer } from "solid-js/web"; -//import { mods } from "../app"; +import { mods } from "../app"; interface TocItem { depth: number; @@ -82,53 +81,53 @@ function useCurrentSection(tableOfContents: Accessor) { return currentSection; } -//const getTOC = cache(async (pathname: string) => { -// "use server"; +const getTOC = cache(async (pathname: string) => { + "use server"; + + const mod = mods[`./routes${pathname}.mdx`] ?? mods[`./routes${pathname}.md`]; + return !mod + ? [] + : mod.getHeadings().filter((h) => h.depth > 1 && h.depth <= 3); +}, "toc"); + +//function updateHeadings(setter: Setter) { +// if (document.getElementsByTagName("article").length === 0) { +// setTimeout(() => updateHeadings(setter), 1); +// return; +// } // -// const mod = mods[`./routes${pathname}.mdx`] ?? mods[`./routes${pathname}.md`]; -// return !mod -// ? [] -// : mod.getHeadings().filter((h) => h.depth > 1 && h.depth <= 3); -//}, "toc"); - -function updateHeadings(setter: Setter) { - if (document.getElementsByTagName("article").length === 0) { - setTimeout(() => updateHeadings(setter), 1); - return; - } - - console.log("update"); - - setter( - [ - ...document - .getElementsByTagName("article")[0] - .querySelectorAll("h1, h2, h3, h4, h5, h6"), - ].map((element) => ({ - depth: Number(element.tagName.substr(1)), - text: element.textContent!, - slug: element.id, - })), - ); -} +// console.log("update"); +// +// setter( +// [ +// ...document +// .getElementsByTagName("article")[0] +// .querySelectorAll("h1, h2, h3, h4, h5, h6"), +// ].map((element) => ({ +// depth: Number(element.tagName.substr(1)), +// text: element.textContent!, +// slug: element.id, +// })), +// ); +//} export function TableOfContents() { const path = useLocation(); - // const toc = createAsync(() => getTOC(path.pathname)); - - const [toc, setToc] = createSignal([]); + const toc = createAsync(() => getTOC(path.pathname)); - createEffect( - on( - () => path.pathname, - (pathname) => { - if (isServer) return; +// const [toc, setToc] = createSignal([]); - updateHeadings(setToc); - }, - ), - ); +// createEffect( +// on( +// () => path.pathname, +// (pathname) => { +// if (isServer) return; +// +// updateHeadings(setToc); +// }, +// ), +// ); const currentSection = useCurrentSection(toc); diff --git a/apps/docs/vite.config.ts b/apps/docs/vite.config.ts index 1191f7b8..db8abff1 100644 --- a/apps/docs/vite.config.ts +++ b/apps/docs/vite.config.ts @@ -157,24 +157,24 @@ export default defineConfig({ ], ], }), - // { - // name: "mdx-meta", - // async transform(code: any, id: any) { - // if (id.endsWith(".mdx?meta") || id.endsWith(".md?meta")) { - // const replacedId = id.replace(/\?meta$/, ""); - // - // if (headingsCache.has(replacedId)) { - // return { - // code: ` - // export function getHeadings() { - // return ${JSON.stringify(headingsCache.get(id), null, 2)} - // } - // `, - // }; - // } - // } - // }, - // }, + { + name: "mdx-meta", + async transform(code: any, id: any) { + if (id.endsWith(".mdx?meta") || id.endsWith(".md?meta")) { + const replacedId = id.replace(/\?meta$/, ""); + + if (headingsCache.has(replacedId)) { + return { + code: ` + export function getHeadings() { + return ${JSON.stringify(headingsCache.get(id), null, 2)} + } + `, + }; + } + } + }, + }, ], ssr: { noExternal: ["@tanstack/solid-virtual"], diff --git a/netlify.toml b/netlify.toml index ab068ae5..2e5ad958 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,5 +1,5 @@ [build] - publish = "apps/docs/netlify/" + publish = "apps/docs/dist/" [functions] - directory = "apps/docs/netlify/functions/" + directory = "apps/docs/.netlify/functions-internal/" \ No newline at end of file