Skip to content

Commit

Permalink
fix: netlify config
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Feb 15, 2024
1 parent 6456142 commit 742f3a1
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 78 deletions.
32 changes: 16 additions & 16 deletions apps/docs/src/app.tsx
Original file line number Diff line number Diff line change
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
83 changes: 41 additions & 42 deletions apps/docs/src/components/table-of-contents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { clsx } from "clsx";
import {
Accessor,
For,
Setter,
Suspense,
createEffect,
createSignal,
on,
onCleanup,
} from "solid-js";
import { isServer } from "solid-js/web";
//import { mods } from "../app";
import { mods } from "../app";

interface TocItem {
depth: number;
Expand Down Expand Up @@ -82,53 +81,53 @@ function useCurrentSection(tableOfContents: Accessor<TocItem[] | undefined>) {
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<TocItem[]>) {
// 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<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,
})),
);
}
// 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<TocItem[]>([]);
const toc = createAsync(() => getTOC(path.pathname));

createEffect(
on(
() => path.pathname,
(pathname) => {
if (isServer) return;
// const [toc, setToc] = createSignal<TocItem[]>([]);

updateHeadings(setToc);
},
),
);
// createEffect(
// on(
// () => path.pathname,
// (pathname) => {
// if (isServer) return;
//
// updateHeadings(setToc);
// },
// ),
// );

const currentSection = useCurrentSection(toc);

Expand Down
36 changes: 18 additions & 18 deletions apps/docs/vite.config.ts
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -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/"

0 comments on commit 742f3a1

Please sign in to comment.