Skip to content

Commit

Permalink
fix: build
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Feb 14, 2024
1 parent f90caed commit 1ed6cb6
Show file tree
Hide file tree
Showing 5 changed files with 4,098 additions and 8,958 deletions.
5 changes: 2 additions & 3 deletions apps/docs/package.json
Expand Up @@ -25,7 +25,7 @@
"author": "Fabien Marie-Louise <fabienml.dev@gmail.com>",
"type": "module",
"scripts": {
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 vinxi build",
"build": "NODE_OPTIONS=\"--max-old-space-size=8192\" vinxi build",
"clean": "rm -rf .solid && rm -rf netlify && rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"dev": "vinxi dev --host",
"start": "vinxi start"
Expand Down Expand Up @@ -63,8 +63,7 @@
"typescript": "4.9.5",
"unist-util-visit": "5.0.0",
"vite": "5.0.12",
"@vinxi/plugin-mdx": "3.7.1",
"cross-env": "7.0.3"
"@vinxi/plugin-mdx": "3.7.1"
},
"engines": {
"node": ">=18"
Expand Down
32 changes: 16 additions & 16 deletions apps/docs/src/app.tsx
Expand Up @@ -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";
Expand Down
57 changes: 47 additions & 10 deletions apps/docs/src/components/table-of-contents.tsx
Expand Up @@ -3,12 +3,15 @@ import { clsx } from "clsx";
import {
Accessor,
For,
Setter,
Suspense,
createEffect,
createSignal,
on,
onCleanup,
} from "solid-js";
import { mods } from "../app";
import { isServer } from "solid-js/web";
//import { mods } from "../app";

interface TocItem {
depth: number;
Expand Down Expand Up @@ -79,19 +82,53 @@ function useCurrentSection(tableOfContents: Accessor<TocItem[] | undefined>) {
return currentSection;
}

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");
//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<TocItem[]>) {
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,
})),
);
}

export function TableOfContents() {
const path = useLocation();

const toc = createAsync(() => getTOC(path.pathname));
// const toc = createAsync(() => getTOC(path.pathname));

const [toc, setToc] = createSignal<TocItem[]>([]);

createEffect(
on(
() => path.pathname,
(pathname) => {
if (isServer) return;

updateHeadings(setToc);
},
),
);

const currentSection = useCurrentSection(toc);

Expand Down
38 changes: 19 additions & 19 deletions apps/docs/vite.config.ts
Expand Up @@ -126,7 +126,7 @@ export default defineConfig({
rehypePrettyCode,
rehypeSlug,
[rehypeRaw, { passThrough: nodeTypes }],
rehypeCollectHeadings,
// rehypeCollectHeadings,
],
remarkPlugins: [
remarkGfm,
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit 1ed6cb6

Please sign in to comment.