diff --git a/.vscode/settings.json b/.vscode/settings.json index 44a73ec3..f06462a7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,6 @@ { "mode": "auto" } - ] + ], + "prettier.configPath": "./apps/www/prettier.config.js" } diff --git a/apps/www/package.json b/apps/www/package.json index 7c7c003d..1d672b38 100644 --- a/apps/www/package.json +++ b/apps/www/package.json @@ -7,7 +7,8 @@ "start": "vinxi start", "format": "prettier -w \"./src/**/*.{js,ts,tsx,mdx}\"", "lint": "eslint src --ext ts,tsx --report-unused-disable-directives", - "build:registry": "tsx build-registry.ts" + "build:registry": "tsx scripts/build-registry.ts", + "build:contents": "tsx scripts/build-contents.ts" }, "dependencies": { "@ark-ui/solid": "^2.0.1", diff --git a/apps/www/scripts/build-contents.ts b/apps/www/scripts/build-contents.ts new file mode 100644 index 00000000..0b31f2a3 --- /dev/null +++ b/apps/www/scripts/build-contents.ts @@ -0,0 +1,55 @@ +import fs from "fs"; +import { join } from "path"; +import { rimraf } from "rimraf"; + +const folderPath = "./src/contents/docs"; + +const generateContentsArray = (folderPath: string): { component: string }[] => { + const contentsArray: { component: string }[] = []; + + fs.readdirSync(folderPath).forEach(file => { + const filePath = join(folderPath, file); + + if (fs.statSync(filePath).isDirectory()) { + const subdirectoryContents = generateContentsArray(filePath); + contentsArray.push(...subdirectoryContents); + } else { + if (file.endsWith(".mdx")) { + const componentPath = filePath.replace(/src/g, "@").replace(/\\/g, "/"); + contentsArray.push({ component: componentPath }); + } + } + }); + + return contentsArray; +}; + +const contentsArray = generateContentsArray(folderPath); + +const generateRouteKey = (filePath: string): string => + `/${filePath + .replace(/\/index\.mdx$/, "") + .replace(/@\/contents\//, "") + .replace(/\.mdx$/, "")}`; + +const formattedContents = contentsArray + .map( + item => + ` "${generateRouteKey(item.component)}": {\n component: lazy(() => import("${ + item.component + }"))\n },` + ) + .join("\n"); + +const fileContent = `// @ts-nocheck +// This file is autogenerated by scripts/build-contents.ts +// Do not edit this file directly. +import type { Component } from "solid-js"; +import { lazy } from "solid-js"; + +export const Contents : Record>> = {\n${formattedContents}\n};`; + +rimraf.sync(join(process.cwd(), "src/contents/index.ts")); +fs.writeFileSync(join(process.cwd(), "src/contents/index.ts"), fileContent); + +console.log("✅ Done!"); diff --git a/apps/www/build-registry.ts b/apps/www/scripts/build-registry.ts similarity index 100% rename from apps/www/build-registry.ts rename to apps/www/scripts/build-registry.ts diff --git a/apps/www/src/routes/docs/changelog.mdx b/apps/www/src/contents/docs/changelog.mdx similarity index 100% rename from apps/www/src/routes/docs/changelog.mdx rename to apps/www/src/contents/docs/changelog.mdx diff --git a/apps/www/src/routes/docs/cli.mdx b/apps/www/src/contents/docs/cli.mdx similarity index 100% rename from apps/www/src/routes/docs/cli.mdx rename to apps/www/src/contents/docs/cli.mdx diff --git a/apps/www/src/routes/docs/components-json.mdx b/apps/www/src/contents/docs/components-json.mdx similarity index 100% rename from apps/www/src/routes/docs/components-json.mdx rename to apps/www/src/contents/docs/components-json.mdx diff --git a/apps/www/src/routes/docs/components/accordion.mdx b/apps/www/src/contents/docs/components/accordion.mdx similarity index 100% rename from apps/www/src/routes/docs/components/accordion.mdx rename to apps/www/src/contents/docs/components/accordion.mdx diff --git a/apps/www/src/routes/docs/components/alert-dialog.mdx b/apps/www/src/contents/docs/components/alert-dialog.mdx similarity index 100% rename from apps/www/src/routes/docs/components/alert-dialog.mdx rename to apps/www/src/contents/docs/components/alert-dialog.mdx diff --git a/apps/www/src/routes/docs/components/alert.mdx b/apps/www/src/contents/docs/components/alert.mdx similarity index 100% rename from apps/www/src/routes/docs/components/alert.mdx rename to apps/www/src/contents/docs/components/alert.mdx diff --git a/apps/www/src/routes/docs/components/badge.mdx b/apps/www/src/contents/docs/components/badge.mdx similarity index 100% rename from apps/www/src/routes/docs/components/badge.mdx rename to apps/www/src/contents/docs/components/badge.mdx diff --git a/apps/www/src/routes/docs/components/button.mdx b/apps/www/src/contents/docs/components/button.mdx similarity index 100% rename from apps/www/src/routes/docs/components/button.mdx rename to apps/www/src/contents/docs/components/button.mdx diff --git a/apps/www/src/routes/docs/components/card.mdx b/apps/www/src/contents/docs/components/card.mdx similarity index 100% rename from apps/www/src/routes/docs/components/card.mdx rename to apps/www/src/contents/docs/components/card.mdx diff --git a/apps/www/src/routes/docs/components/carousel.mdx b/apps/www/src/contents/docs/components/carousel.mdx similarity index 100% rename from apps/www/src/routes/docs/components/carousel.mdx rename to apps/www/src/contents/docs/components/carousel.mdx diff --git a/apps/www/src/routes/docs/components/checkbox.mdx b/apps/www/src/contents/docs/components/checkbox.mdx similarity index 100% rename from apps/www/src/routes/docs/components/checkbox.mdx rename to apps/www/src/contents/docs/components/checkbox.mdx diff --git a/apps/www/src/routes/docs/components/collapsible.mdx b/apps/www/src/contents/docs/components/collapsible.mdx similarity index 100% rename from apps/www/src/routes/docs/components/collapsible.mdx rename to apps/www/src/contents/docs/components/collapsible.mdx diff --git a/apps/www/src/routes/docs/components/combobox.mdx b/apps/www/src/contents/docs/components/combobox.mdx similarity index 100% rename from apps/www/src/routes/docs/components/combobox.mdx rename to apps/www/src/contents/docs/components/combobox.mdx diff --git a/apps/www/src/routes/docs/components/command.mdx b/apps/www/src/contents/docs/components/command.mdx similarity index 100% rename from apps/www/src/routes/docs/components/command.mdx rename to apps/www/src/contents/docs/components/command.mdx diff --git a/apps/www/src/routes/docs/components/context-menu.mdx b/apps/www/src/contents/docs/components/context-menu.mdx similarity index 100% rename from apps/www/src/routes/docs/components/context-menu.mdx rename to apps/www/src/contents/docs/components/context-menu.mdx diff --git a/apps/www/src/routes/docs/components/date-picker.mdx b/apps/www/src/contents/docs/components/date-picker.mdx similarity index 100% rename from apps/www/src/routes/docs/components/date-picker.mdx rename to apps/www/src/contents/docs/components/date-picker.mdx diff --git a/apps/www/src/routes/docs/components/dialog.mdx b/apps/www/src/contents/docs/components/dialog.mdx similarity index 100% rename from apps/www/src/routes/docs/components/dialog.mdx rename to apps/www/src/contents/docs/components/dialog.mdx diff --git a/apps/www/src/routes/docs/components/dropdown-menu.mdx b/apps/www/src/contents/docs/components/dropdown-menu.mdx similarity index 100% rename from apps/www/src/routes/docs/components/dropdown-menu.mdx rename to apps/www/src/contents/docs/components/dropdown-menu.mdx diff --git a/apps/www/src/routes/docs/components/hover-card.mdx b/apps/www/src/contents/docs/components/hover-card.mdx similarity index 100% rename from apps/www/src/routes/docs/components/hover-card.mdx rename to apps/www/src/contents/docs/components/hover-card.mdx diff --git a/apps/www/src/routes/docs/components/image.mdx b/apps/www/src/contents/docs/components/image.mdx similarity index 100% rename from apps/www/src/routes/docs/components/image.mdx rename to apps/www/src/contents/docs/components/image.mdx diff --git a/apps/www/src/routes/docs/components/pagination.mdx b/apps/www/src/contents/docs/components/pagination.mdx similarity index 100% rename from apps/www/src/routes/docs/components/pagination.mdx rename to apps/www/src/contents/docs/components/pagination.mdx diff --git a/apps/www/src/routes/docs/components/popover.mdx b/apps/www/src/contents/docs/components/popover.mdx similarity index 100% rename from apps/www/src/routes/docs/components/popover.mdx rename to apps/www/src/contents/docs/components/popover.mdx diff --git a/apps/www/src/routes/docs/components/progress.mdx b/apps/www/src/contents/docs/components/progress.mdx similarity index 100% rename from apps/www/src/routes/docs/components/progress.mdx rename to apps/www/src/contents/docs/components/progress.mdx diff --git a/apps/www/src/routes/docs/components/radio-group.mdx b/apps/www/src/contents/docs/components/radio-group.mdx similarity index 100% rename from apps/www/src/routes/docs/components/radio-group.mdx rename to apps/www/src/contents/docs/components/radio-group.mdx diff --git a/apps/www/src/routes/docs/components/select.mdx b/apps/www/src/contents/docs/components/select.mdx similarity index 100% rename from apps/www/src/routes/docs/components/select.mdx rename to apps/www/src/contents/docs/components/select.mdx diff --git a/apps/www/src/routes/docs/components/separator.mdx b/apps/www/src/contents/docs/components/separator.mdx similarity index 100% rename from apps/www/src/routes/docs/components/separator.mdx rename to apps/www/src/contents/docs/components/separator.mdx diff --git a/apps/www/src/routes/docs/components/sheet.mdx b/apps/www/src/contents/docs/components/sheet.mdx similarity index 100% rename from apps/www/src/routes/docs/components/sheet.mdx rename to apps/www/src/contents/docs/components/sheet.mdx diff --git a/apps/www/src/routes/docs/components/skeleton.mdx b/apps/www/src/contents/docs/components/skeleton.mdx similarity index 100% rename from apps/www/src/routes/docs/components/skeleton.mdx rename to apps/www/src/contents/docs/components/skeleton.mdx diff --git a/apps/www/src/routes/docs/components/switch.mdx b/apps/www/src/contents/docs/components/switch.mdx similarity index 100% rename from apps/www/src/routes/docs/components/switch.mdx rename to apps/www/src/contents/docs/components/switch.mdx diff --git a/apps/www/src/routes/docs/components/table.mdx b/apps/www/src/contents/docs/components/table.mdx similarity index 100% rename from apps/www/src/routes/docs/components/table.mdx rename to apps/www/src/contents/docs/components/table.mdx diff --git a/apps/www/src/routes/docs/components/tabs.mdx b/apps/www/src/contents/docs/components/tabs.mdx similarity index 100% rename from apps/www/src/routes/docs/components/tabs.mdx rename to apps/www/src/contents/docs/components/tabs.mdx diff --git a/apps/www/src/routes/docs/components/textarea.mdx b/apps/www/src/contents/docs/components/textarea.mdx similarity index 100% rename from apps/www/src/routes/docs/components/textarea.mdx rename to apps/www/src/contents/docs/components/textarea.mdx diff --git a/apps/www/src/routes/docs/components/textfield.mdx b/apps/www/src/contents/docs/components/textfield.mdx similarity index 100% rename from apps/www/src/routes/docs/components/textfield.mdx rename to apps/www/src/contents/docs/components/textfield.mdx diff --git a/apps/www/src/routes/docs/components/toast.mdx b/apps/www/src/contents/docs/components/toast.mdx similarity index 100% rename from apps/www/src/routes/docs/components/toast.mdx rename to apps/www/src/contents/docs/components/toast.mdx diff --git a/apps/www/src/routes/docs/components/toggle.mdx b/apps/www/src/contents/docs/components/toggle.mdx similarity index 100% rename from apps/www/src/routes/docs/components/toggle.mdx rename to apps/www/src/contents/docs/components/toggle.mdx diff --git a/apps/www/src/routes/docs/components/tooltip.mdx b/apps/www/src/contents/docs/components/tooltip.mdx similarity index 100% rename from apps/www/src/routes/docs/components/tooltip.mdx rename to apps/www/src/contents/docs/components/tooltip.mdx diff --git a/apps/www/src/routes/docs/dark-mode.mdx b/apps/www/src/contents/docs/dark-mode.mdx similarity index 100% rename from apps/www/src/routes/docs/dark-mode.mdx rename to apps/www/src/contents/docs/dark-mode.mdx diff --git a/apps/www/src/routes/docs/figma.mdx b/apps/www/src/contents/docs/figma.mdx similarity index 100% rename from apps/www/src/routes/docs/figma.mdx rename to apps/www/src/contents/docs/figma.mdx diff --git a/apps/www/src/routes/docs/index.mdx b/apps/www/src/contents/docs/index.mdx similarity index 100% rename from apps/www/src/routes/docs/index.mdx rename to apps/www/src/contents/docs/index.mdx diff --git a/apps/www/src/routes/docs/installation/index.mdx b/apps/www/src/contents/docs/installation/index.mdx similarity index 100% rename from apps/www/src/routes/docs/installation/index.mdx rename to apps/www/src/contents/docs/installation/index.mdx diff --git a/apps/www/src/routes/docs/installation/manual.mdx b/apps/www/src/contents/docs/installation/manual.mdx similarity index 100% rename from apps/www/src/routes/docs/installation/manual.mdx rename to apps/www/src/contents/docs/installation/manual.mdx diff --git a/apps/www/src/routes/docs/installation/solid-start.mdx b/apps/www/src/contents/docs/installation/solid-start.mdx similarity index 100% rename from apps/www/src/routes/docs/installation/solid-start.mdx rename to apps/www/src/contents/docs/installation/solid-start.mdx diff --git a/apps/www/src/routes/docs/theming.mdx b/apps/www/src/contents/docs/theming.mdx similarity index 100% rename from apps/www/src/routes/docs/theming.mdx rename to apps/www/src/contents/docs/theming.mdx diff --git a/apps/www/src/routes/docs/typography.mdx b/apps/www/src/contents/docs/typography.mdx similarity index 100% rename from apps/www/src/routes/docs/typography.mdx rename to apps/www/src/contents/docs/typography.mdx diff --git a/apps/www/src/contents/index.ts b/apps/www/src/contents/index.ts new file mode 100644 index 00000000..fabdc535 --- /dev/null +++ b/apps/www/src/contents/index.ts @@ -0,0 +1,140 @@ +// @ts-nocheck +// This file is autogenerated by scripts/build-contents.ts +// Do not edit this file directly. +import type { Component } from "solid-js"; +import { lazy } from "solid-js"; + +export const Contents: Record>> = { + "/docs/changelog": { + component: lazy(() => import("@/contents/docs/changelog.mdx")) + }, + "/docs/cli": { + component: lazy(() => import("@/contents/docs/cli.mdx")) + }, + "/docs/components/accordion": { + component: lazy(() => import("@/contents/docs/components/accordion.mdx")) + }, + "/docs/components/alert-dialog": { + component: lazy(() => import("@/contents/docs/components/alert-dialog.mdx")) + }, + "/docs/components/alert": { + component: lazy(() => import("@/contents/docs/components/alert.mdx")) + }, + "/docs/components/badge": { + component: lazy(() => import("@/contents/docs/components/badge.mdx")) + }, + "/docs/components/button": { + component: lazy(() => import("@/contents/docs/components/button.mdx")) + }, + "/docs/components/card": { + component: lazy(() => import("@/contents/docs/components/card.mdx")) + }, + "/docs/components/carousel": { + component: lazy(() => import("@/contents/docs/components/carousel.mdx")) + }, + "/docs/components/checkbox": { + component: lazy(() => import("@/contents/docs/components/checkbox.mdx")) + }, + "/docs/components/collapsible": { + component: lazy(() => import("@/contents/docs/components/collapsible.mdx")) + }, + "/docs/components/combobox": { + component: lazy(() => import("@/contents/docs/components/combobox.mdx")) + }, + "/docs/components/command": { + component: lazy(() => import("@/contents/docs/components/command.mdx")) + }, + "/docs/components/context-menu": { + component: lazy(() => import("@/contents/docs/components/context-menu.mdx")) + }, + "/docs/components/date-picker": { + component: lazy(() => import("@/contents/docs/components/date-picker.mdx")) + }, + "/docs/components/dialog": { + component: lazy(() => import("@/contents/docs/components/dialog.mdx")) + }, + "/docs/components/dropdown-menu": { + component: lazy(() => import("@/contents/docs/components/dropdown-menu.mdx")) + }, + "/docs/components/hover-card": { + component: lazy(() => import("@/contents/docs/components/hover-card.mdx")) + }, + "/docs/components/image": { + component: lazy(() => import("@/contents/docs/components/image.mdx")) + }, + "/docs/components/pagination": { + component: lazy(() => import("@/contents/docs/components/pagination.mdx")) + }, + "/docs/components/popover": { + component: lazy(() => import("@/contents/docs/components/popover.mdx")) + }, + "/docs/components/progress": { + component: lazy(() => import("@/contents/docs/components/progress.mdx")) + }, + "/docs/components/radio-group": { + component: lazy(() => import("@/contents/docs/components/radio-group.mdx")) + }, + "/docs/components/select": { + component: lazy(() => import("@/contents/docs/components/select.mdx")) + }, + "/docs/components/separator": { + component: lazy(() => import("@/contents/docs/components/separator.mdx")) + }, + "/docs/components/sheet": { + component: lazy(() => import("@/contents/docs/components/sheet.mdx")) + }, + "/docs/components/skeleton": { + component: lazy(() => import("@/contents/docs/components/skeleton.mdx")) + }, + "/docs/components/switch": { + component: lazy(() => import("@/contents/docs/components/switch.mdx")) + }, + "/docs/components/table": { + component: lazy(() => import("@/contents/docs/components/table.mdx")) + }, + "/docs/components/tabs": { + component: lazy(() => import("@/contents/docs/components/tabs.mdx")) + }, + "/docs/components/textarea": { + component: lazy(() => import("@/contents/docs/components/textarea.mdx")) + }, + "/docs/components/textfield": { + component: lazy(() => import("@/contents/docs/components/textfield.mdx")) + }, + "/docs/components/toast": { + component: lazy(() => import("@/contents/docs/components/toast.mdx")) + }, + "/docs/components/toggle": { + component: lazy(() => import("@/contents/docs/components/toggle.mdx")) + }, + "/docs/components/tooltip": { + component: lazy(() => import("@/contents/docs/components/tooltip.mdx")) + }, + "/docs/components-json": { + component: lazy(() => import("@/contents/docs/components-json.mdx")) + }, + "/docs/dark-mode": { + component: lazy(() => import("@/contents/docs/dark-mode.mdx")) + }, + "/docs/figma": { + component: lazy(() => import("@/contents/docs/figma.mdx")) + }, + "/docs": { + component: lazy(() => import("@/contents/docs/index.mdx")) + }, + "/docs/installation": { + component: lazy(() => import("@/contents/docs/installation/index.mdx")) + }, + "/docs/installation/manual": { + component: lazy(() => import("@/contents/docs/installation/manual.mdx")) + }, + "/docs/installation/solid-start": { + component: lazy(() => import("@/contents/docs/installation/solid-start.mdx")) + }, + "/docs/theming": { + component: lazy(() => import("@/contents/docs/theming.mdx")) + }, + "/docs/typography": { + component: lazy(() => import("@/contents/docs/typography.mdx")) + } +}; diff --git a/apps/www/src/routes/docs.tsx b/apps/www/src/routes/docs.tsx index 64f3f8cb..c85f1eef 100644 --- a/apps/www/src/routes/docs.tsx +++ b/apps/www/src/routes/docs.tsx @@ -4,7 +4,7 @@ import { Pager } from "@/components/pager"; import { Sidebar } from "@/components/sidebar"; import { TableOfContents } from "@/components/toc"; import { badgeVariants } from "@/registry/default/ui/badge"; -import { A, useLocation, type RouteSectionProps } from "@solidjs/router"; +import { A, type RouteSectionProps } from "@solidjs/router"; import { Show, createMemo } from "solid-js"; import { MDXProvider } from "solid-mdx"; import { Balancer } from "solid-wrap-balancer"; @@ -29,28 +29,26 @@ const contents = /*#__PURE__*/ import.meta.glob< headings: Heading[]; frontmatter: Frontmatter; } ->("./docs/**/*.mdx", { +>("../contents/docs/**/*.mdx", { eager: true }); -const Documents = (props: RouteSectionProps) => { - const location = useLocation(); - +const DocumentLayout = (props: RouteSectionProps) => { const markdownData = createMemo(() => ({ frontmatter: contents[ - `.${ - location.pathname === "/docs" || location.pathname === "/docs/installation" - ? location.pathname + "/index" - : location.pathname + `../contents${ + props.location.pathname === "/docs" || props.location.pathname === "/docs/installation" + ? props.location.pathname + "/index" + : props.location.pathname }.mdx` ].frontmatter, headings: contents[ - `.${ - location.pathname === "/docs" || location.pathname === "/docs/installation" - ? location.pathname + "/index" - : location.pathname + `../contents${ + props.location.pathname === "/docs" || props.location.pathname === "/docs/installation" + ? props.location.pathname + "/index" + : props.location.pathname }.mdx` ].headings })); @@ -154,7 +152,7 @@ const Documents = (props: RouteSectionProps) => {
{props.children}
- +