blodemd 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +2 -2
  2. package/dev-server/app/[[...slug]]/page.tsx +139 -0
  3. package/dev-server/app/blodemd-dev/invalidate/route.ts +12 -0
  4. package/dev-server/app/blodemd-dev/static/[...path]/route.ts +32 -0
  5. package/dev-server/app/blodemd-dev/version/route.ts +14 -0
  6. package/dev-server/app/blodemd-internal/proxy/route.ts +86 -0
  7. package/dev-server/app/error.tsx +24 -0
  8. package/dev-server/app/favicon.ico +0 -0
  9. package/dev-server/app/globals.css +4 -0
  10. package/dev-server/app/layout.tsx +38 -0
  11. package/dev-server/app/not-found.tsx +18 -0
  12. package/dev-server/app/search/route.ts +17 -0
  13. package/dev-server/components/dev-reload-script.tsx +86 -0
  14. package/dev-server/components/providers.tsx +15 -0
  15. package/dev-server/lib/dev-state.ts +8 -0
  16. package/dev-server/lib/local-content-source.ts +103 -0
  17. package/dev-server/lib/local-runtime.tsx +558 -0
  18. package/dev-server/next-env.d.ts +5 -0
  19. package/dev-server/next.config.js +46 -0
  20. package/dev-server/package.json +57 -0
  21. package/dev-server/postcss.config.mjs +7 -0
  22. package/dev-server/public/glide-variable.woff2 +0 -0
  23. package/dev-server/tsconfig.json +50 -0
  24. package/dist/cli.mjs +311 -86
  25. package/dist/cli.mjs.map +1 -1
  26. package/docs/app/globals.css +457 -0
  27. package/docs/components/api/api-playground.tsx +295 -0
  28. package/docs/components/api/api-reference.tsx +121 -0
  29. package/docs/components/content/collection-index.tsx +114 -0
  30. package/docs/components/docs/contextual-menu.tsx +406 -0
  31. package/docs/components/docs/copy-page-menu.tsx +255 -0
  32. package/docs/components/docs/doc-header.tsx +210 -0
  33. package/docs/components/docs/doc-shell.tsx +313 -0
  34. package/docs/components/docs/doc-sidebar.tsx +211 -0
  35. package/docs/components/docs/doc-toc.tsx +45 -0
  36. package/docs/components/docs/mobile-nav.tsx +205 -0
  37. package/docs/components/icons/doc-icon.tsx +96 -0
  38. package/docs/components/mdx/accordion.tsx +83 -0
  39. package/docs/components/mdx/badge.tsx +79 -0
  40. package/docs/components/mdx/callout.tsx +88 -0
  41. package/docs/components/mdx/card.tsx +110 -0
  42. package/docs/components/mdx/code-block.tsx +75 -0
  43. package/docs/components/mdx/code-group.tsx +94 -0
  44. package/docs/components/mdx/color.tsx +87 -0
  45. package/docs/components/mdx/columns.tsx +25 -0
  46. package/docs/components/mdx/expandable.tsx +45 -0
  47. package/docs/components/mdx/field-layout.tsx +77 -0
  48. package/docs/components/mdx/frame.tsx +23 -0
  49. package/docs/components/mdx/get-text-content.ts +18 -0
  50. package/docs/components/mdx/icon.tsx +12 -0
  51. package/docs/components/mdx/index.tsx +107 -0
  52. package/docs/components/mdx/installer.tsx +20 -0
  53. package/docs/components/mdx/panel.tsx +11 -0
  54. package/docs/components/mdx/param-field.tsx +56 -0
  55. package/docs/components/mdx/preview.tsx +36 -0
  56. package/docs/components/mdx/prompt.tsx +63 -0
  57. package/docs/components/mdx/request-example.tsx +27 -0
  58. package/docs/components/mdx/response-field.tsx +42 -0
  59. package/docs/components/mdx/steps.tsx +92 -0
  60. package/docs/components/mdx/tabs.tsx +88 -0
  61. package/docs/components/mdx/tile.tsx +43 -0
  62. package/docs/components/mdx/tooltip.tsx +71 -0
  63. package/docs/components/mdx/tree.tsx +120 -0
  64. package/docs/components/mdx/type-table.tsx +71 -0
  65. package/docs/components/mdx/update.tsx +44 -0
  66. package/docs/components/mdx/video.tsx +12 -0
  67. package/docs/components/mdx/view.tsx +66 -0
  68. package/docs/components/providers.tsx +15 -0
  69. package/docs/components/ui/breadcrumb.tsx +92 -0
  70. package/docs/components/ui/button.tsx +90 -0
  71. package/docs/components/ui/card.tsx +92 -0
  72. package/docs/components/ui/command.tsx +139 -0
  73. package/docs/components/ui/dialog.tsx +97 -0
  74. package/docs/components/ui/field.tsx +237 -0
  75. package/docs/components/ui/input.tsx +105 -0
  76. package/docs/components/ui/label.tsx +22 -0
  77. package/docs/components/ui/popover.tsx +72 -0
  78. package/docs/components/ui/search.tsx +384 -0
  79. package/docs/components/ui/separator.tsx +26 -0
  80. package/docs/components/ui/sheet.tsx +104 -0
  81. package/docs/components/ui/sidebar.tsx +433 -0
  82. package/docs/components/ui/theme-toggle.tsx +62 -0
  83. package/docs/components/ui/tooltip.tsx +53 -0
  84. package/docs/lib/contextual-options.ts +193 -0
  85. package/docs/lib/docs-collection.ts +22 -0
  86. package/docs/lib/mdx.ts +87 -0
  87. package/docs/lib/navigation.ts +288 -0
  88. package/docs/lib/openapi.ts +158 -0
  89. package/docs/lib/routes.ts +44 -0
  90. package/docs/lib/server-cache.ts +83 -0
  91. package/docs/lib/shiki.ts +40 -0
  92. package/docs/lib/theme.ts +29 -0
  93. package/docs/lib/toc.ts +2 -0
  94. package/docs/lib/utils.ts +5 -0
  95. package/package.json +43 -6
  96. package/packages/@repo/common/dist/index.d.ts +9 -0
  97. package/packages/@repo/common/dist/index.d.ts.map +1 -0
  98. package/packages/@repo/common/dist/index.js +42 -0
  99. package/packages/@repo/common/package.json +34 -0
  100. package/packages/@repo/common/src/index.ts +51 -0
  101. package/packages/@repo/contracts/dist/api-key.d.ts +30 -0
  102. package/packages/@repo/contracts/dist/api-key.d.ts.map +1 -0
  103. package/packages/@repo/contracts/dist/api-key.js +20 -0
  104. package/packages/@repo/contracts/dist/dates.d.ts +4 -0
  105. package/packages/@repo/contracts/dist/dates.d.ts.map +1 -0
  106. package/packages/@repo/contracts/dist/dates.js +2 -0
  107. package/packages/@repo/contracts/dist/deployment.d.ts +71 -0
  108. package/packages/@repo/contracts/dist/deployment.d.ts.map +1 -0
  109. package/packages/@repo/contracts/dist/deployment.js +46 -0
  110. package/packages/@repo/contracts/dist/domain.d.ts +94 -0
  111. package/packages/@repo/contracts/dist/domain.d.ts.map +1 -0
  112. package/packages/@repo/contracts/dist/domain.js +36 -0
  113. package/packages/@repo/contracts/dist/ids.d.ts +14 -0
  114. package/packages/@repo/contracts/dist/ids.d.ts.map +1 -0
  115. package/packages/@repo/contracts/dist/ids.js +10 -0
  116. package/packages/@repo/contracts/dist/index.d.ts +10 -0
  117. package/packages/@repo/contracts/dist/index.d.ts.map +1 -0
  118. package/packages/@repo/contracts/dist/index.js +11 -0
  119. package/packages/@repo/contracts/dist/pagination.d.ts +23 -0
  120. package/packages/@repo/contracts/dist/pagination.d.ts.map +1 -0
  121. package/packages/@repo/contracts/dist/pagination.js +15 -0
  122. package/packages/@repo/contracts/dist/project.d.ts +25 -0
  123. package/packages/@repo/contracts/dist/project.d.ts.map +1 -0
  124. package/packages/@repo/contracts/dist/project.js +23 -0
  125. package/packages/@repo/contracts/dist/tenant.d.ts +111 -0
  126. package/packages/@repo/contracts/dist/tenant.d.ts.map +1 -0
  127. package/packages/@repo/contracts/dist/tenant.js +56 -0
  128. package/packages/@repo/contracts/dist/user.d.ts +9 -0
  129. package/packages/@repo/contracts/dist/user.d.ts.map +1 -0
  130. package/packages/@repo/contracts/dist/user.js +9 -0
  131. package/packages/@repo/contracts/package.json +37 -0
  132. package/packages/@repo/contracts/src/api-key.ts +27 -0
  133. package/packages/@repo/contracts/src/dates.ts +4 -0
  134. package/packages/@repo/contracts/src/deployment.ts +73 -0
  135. package/packages/@repo/contracts/src/domain.ts +51 -0
  136. package/packages/@repo/contracts/src/ids.ts +22 -0
  137. package/packages/@repo/contracts/src/index.ts +11 -0
  138. package/packages/@repo/contracts/src/pagination.ts +21 -0
  139. package/packages/@repo/contracts/src/project.ts +30 -0
  140. package/packages/@repo/contracts/src/tenant.ts +92 -0
  141. package/packages/@repo/contracts/src/user.ts +12 -0
  142. package/packages/@repo/models/dist/docs-config.d.ts +985 -0
  143. package/packages/@repo/models/dist/docs-config.d.ts.map +1 -0
  144. package/packages/@repo/models/dist/docs-config.js +548 -0
  145. package/packages/@repo/models/dist/index.d.ts +3 -0
  146. package/packages/@repo/models/dist/index.d.ts.map +1 -0
  147. package/packages/@repo/models/dist/index.js +3 -0
  148. package/packages/@repo/models/dist/tenant.d.ts +25 -0
  149. package/packages/@repo/models/dist/tenant.d.ts.map +1 -0
  150. package/packages/@repo/models/dist/tenant.js +1 -0
  151. package/packages/@repo/models/package.json +37 -0
  152. package/packages/@repo/models/src/docs-config.ts +648 -0
  153. package/packages/@repo/models/src/index.ts +3 -0
  154. package/packages/@repo/models/src/tenant.ts +29 -0
  155. package/packages/@repo/prebuild/dist/index.d.ts +2 -0
  156. package/packages/@repo/prebuild/dist/index.d.ts.map +1 -0
  157. package/packages/@repo/prebuild/dist/index.js +2 -0
  158. package/packages/@repo/prebuild/dist/openapi.d.ts +43 -0
  159. package/packages/@repo/prebuild/dist/openapi.d.ts.map +1 -0
  160. package/packages/@repo/prebuild/dist/openapi.js +58 -0
  161. package/packages/@repo/prebuild/package.json +39 -0
  162. package/packages/@repo/prebuild/src/index.ts +2 -0
  163. package/packages/@repo/prebuild/src/openapi.ts +116 -0
  164. package/packages/@repo/previewing/dist/blob-source.d.ts +16 -0
  165. package/packages/@repo/previewing/dist/blob-source.d.ts.map +1 -0
  166. package/packages/@repo/previewing/dist/blob-source.js +110 -0
  167. package/packages/@repo/previewing/dist/content-source.d.ts +12 -0
  168. package/packages/@repo/previewing/dist/content-source.d.ts.map +1 -0
  169. package/packages/@repo/previewing/dist/content-source.js +1 -0
  170. package/packages/@repo/previewing/dist/fs-source.d.ts +11 -0
  171. package/packages/@repo/previewing/dist/fs-source.d.ts.map +1 -0
  172. package/packages/@repo/previewing/dist/fs-source.js +72 -0
  173. package/packages/@repo/previewing/dist/index.d.ts +120 -0
  174. package/packages/@repo/previewing/dist/index.d.ts.map +1 -0
  175. package/packages/@repo/previewing/dist/index.js +984 -0
  176. package/packages/@repo/previewing/package.json +41 -0
  177. package/packages/@repo/previewing/src/blob-source.ts +167 -0
  178. package/packages/@repo/previewing/src/content-source.ts +12 -0
  179. package/packages/@repo/previewing/src/fs-source.ts +104 -0
  180. package/packages/@repo/previewing/src/index.ts +1490 -0
  181. package/packages/@repo/validation/dist/index.d.ts +12 -0
  182. package/packages/@repo/validation/dist/index.d.ts.map +1 -0
  183. package/packages/@repo/validation/dist/index.js +30 -0
  184. package/packages/@repo/validation/package.json +37 -0
  185. package/packages/@repo/validation/src/index.ts +59 -0
  186. package/packages/@repo/validation/src/mintlify-docs-schema.json +5016 -0
  187. package/scripts/prepare-package.mjs +39 -0
package/README.md CHANGED
@@ -23,7 +23,7 @@ Or run without installing:
23
23
  npx blodemd
24
24
  ```
25
25
 
26
- Requires Node.js 18+.
26
+ Requires Node.js 20.17+ and <25.
27
27
 
28
28
  ## Quick Start
29
29
 
@@ -90,7 +90,7 @@ The CLI looks for a `docs.json` file in the docs directory. Minimal example:
90
90
 
91
91
  ```json
92
92
  {
93
- "$schema": "https://mintlify.com/docs.json",
93
+ "$schema": "https://docs.blode.md/docs.json",
94
94
  "name": "my-project",
95
95
  "theme": "mint",
96
96
  "colors": { "primary": "#0D9373" },
@@ -0,0 +1,139 @@
1
+ import { getDocPageContent, getDocShellData } from "@dev/lib/local-runtime";
2
+ import type { Metadata } from "next";
3
+ import { notFound } from "next/navigation";
4
+
5
+ import { ApiReference } from "@/components/api/api-reference";
6
+ import { CollectionIndex } from "@/components/content/collection-index";
7
+ import { DocShell } from "@/components/docs/doc-shell";
8
+
9
+ const buildTitle = (pageTitle?: string, baseTitle = "Docs") =>
10
+ pageTitle ? `${pageTitle} · ${baseTitle}` : baseTitle;
11
+
12
+ export const generateMetadata = async ({
13
+ params,
14
+ }: {
15
+ params: Promise<{ slug?: string[] }>;
16
+ }): Promise<Metadata> => {
17
+ const { slug = [] } = await params;
18
+ const data = await getDocShellData(slug.join("/"));
19
+
20
+ if (!data || "configErrors" in data) {
21
+ return {
22
+ description: "Documentation",
23
+ title: "Docs",
24
+ };
25
+ }
26
+
27
+ const { config } = data;
28
+ const title = buildTitle(data.pageTitle, config.name ?? "Docs");
29
+ const noindex =
30
+ data.noindex || (data.hidden && config.seo?.indexing !== "all");
31
+ const ogImage = config.metadata?.ogImage;
32
+ const { favicon } = config;
33
+
34
+ return {
35
+ description: data.pageDescription ?? config.description,
36
+ icons: favicon ? { icon: favicon } : undefined,
37
+ openGraph: ogImage
38
+ ? {
39
+ images: [ogImage],
40
+ }
41
+ : undefined,
42
+ robots: noindex ? { index: false } : undefined,
43
+ title,
44
+ twitter: ogImage
45
+ ? {
46
+ card: "summary_large_image",
47
+ images: [ogImage],
48
+ }
49
+ : undefined,
50
+ };
51
+ };
52
+
53
+ const PreviewPage = async ({
54
+ params,
55
+ }: {
56
+ params: Promise<{ slug?: string[] }>;
57
+ }) => {
58
+ const { slug = [] } = await params;
59
+ const slugKey = slug.join("/");
60
+ const shell = await getDocShellData(slugKey);
61
+
62
+ if (!shell) {
63
+ return notFound();
64
+ }
65
+
66
+ if ("configErrors" in shell) {
67
+ const errors = shell.configErrors ?? [];
68
+ const warnings = shell.configWarnings ?? [];
69
+
70
+ return (
71
+ <div className="p-10">
72
+ <h1>Invalid docs.json</h1>
73
+ {warnings.length ? (
74
+ <>
75
+ <h2>Warnings</h2>
76
+ <ul>
77
+ {warnings.map((warning) => (
78
+ <li key={warning}>{warning}</li>
79
+ ))}
80
+ </ul>
81
+ </>
82
+ ) : null}
83
+ <ul>
84
+ {errors.map((error) => (
85
+ <li key={error}>{error}</li>
86
+ ))}
87
+ </ul>
88
+ </div>
89
+ );
90
+ }
91
+
92
+ let content: React.ReactNode;
93
+ let rawContent: string | undefined;
94
+ let toc: { id: string; level: number; title: string }[] = [];
95
+
96
+ if (shell.kind === "openapi") {
97
+ content = (
98
+ <ApiReference
99
+ entry={shell.openApiEntry}
100
+ proxyEnabled={shell.openapiProxyEnabled}
101
+ />
102
+ );
103
+ rawContent = shell.openApiEntry.operation.description ?? "";
104
+ } else if (shell.kind === "index") {
105
+ content = (
106
+ <CollectionIndex basePath="" entries={shell.collectionIndex.entries} />
107
+ );
108
+ } else {
109
+ ({ rawContent } = shell);
110
+ ({ toc } = shell);
111
+ const rendered = await getDocPageContent(slugKey);
112
+ content = rendered?.content ?? null;
113
+ }
114
+
115
+ return (
116
+ <DocShell
117
+ activeTabIndex={shell.activeTabIndex}
118
+ anchors={shell.anchors}
119
+ basePath=""
120
+ breadcrumbs={shell.breadcrumbs}
121
+ config={shell.config}
122
+ content={content}
123
+ currentPath={shell.currentPath}
124
+ deprecated={shell.deprecated}
125
+ hideFooterPagination={shell.hideFooterPagination}
126
+ mode={shell.mode}
127
+ nav={shell.nav}
128
+ nextPage={shell.nextPage}
129
+ pageDescription={shell.pageDescription}
130
+ pageTitle={shell.pageTitle}
131
+ prevPage={shell.prevPage}
132
+ rawContent={rawContent}
133
+ tabs={shell.tabs}
134
+ toc={toc}
135
+ />
136
+ );
137
+ };
138
+
139
+ export default PreviewPage;
@@ -0,0 +1,12 @@
1
+ import { bumpDevVersion } from "@dev/lib/dev-state";
2
+ import { clearLocalRuntimeCaches } from "@dev/lib/local-runtime";
3
+ import { NextResponse } from "next/server";
4
+
5
+ export const dynamic = "force-dynamic";
6
+
7
+ export const POST = () => {
8
+ clearLocalRuntimeCaches();
9
+ const version = bumpDevVersion();
10
+
11
+ return NextResponse.json({ ok: true, version });
12
+ };
@@ -0,0 +1,32 @@
1
+ import {
2
+ getStaticAssetContentType,
3
+ readStaticAsset,
4
+ } from "@dev/lib/local-content-source";
5
+ import { NextResponse } from "next/server";
6
+
7
+ export const dynamic = "force-dynamic";
8
+
9
+ export const GET = async (
10
+ _request: Request,
11
+ {
12
+ params,
13
+ }: {
14
+ params: Promise<{ path: string[] }>;
15
+ }
16
+ ) => {
17
+ const { path = [] } = await params;
18
+ const relativePath = path.join("/");
19
+
20
+ try {
21
+ const data = await readStaticAsset(relativePath);
22
+
23
+ return new NextResponse(data, {
24
+ headers: {
25
+ "Cache-Control": "no-store",
26
+ "Content-Type": getStaticAssetContentType(relativePath),
27
+ },
28
+ });
29
+ } catch {
30
+ return new NextResponse("Not found", { status: 404 });
31
+ }
32
+ };
@@ -0,0 +1,14 @@
1
+ import { getDevVersion } from "@dev/lib/dev-state";
2
+ import { NextResponse } from "next/server";
3
+
4
+ export const dynamic = "force-dynamic";
5
+
6
+ export const GET = () =>
7
+ NextResponse.json(
8
+ { version: getDevVersion() },
9
+ {
10
+ headers: {
11
+ "Cache-Control": "no-store",
12
+ },
13
+ }
14
+ );
@@ -0,0 +1,86 @@
1
+ import { getOpenApiProxyContext } from "@dev/lib/local-runtime";
2
+ import { NextResponse } from "next/server";
3
+
4
+ interface ProxyPayload {
5
+ body?: string;
6
+ headers?: Record<string, string>;
7
+ method: string;
8
+ url: string;
9
+ }
10
+
11
+ const jsonError = (error: string, status: number) =>
12
+ NextResponse.json({ error }, { status });
13
+
14
+ const resolveAllowedHosts = async () => {
15
+ const context = await getOpenApiProxyContext();
16
+
17
+ if (!context) {
18
+ return null;
19
+ }
20
+
21
+ const configuredHosts = context.config.openapiProxy?.allowedHosts ?? [];
22
+ if (configuredHosts.length) {
23
+ return configuredHosts;
24
+ }
25
+
26
+ const derivedHosts = context.registry.entries.flatMap((entry) =>
27
+ (entry.spec.servers ?? []).flatMap((server) => {
28
+ try {
29
+ return [new URL(server.url).hostname];
30
+ } catch {
31
+ return [];
32
+ }
33
+ })
34
+ );
35
+
36
+ return [...new Set(derivedHosts)];
37
+ };
38
+
39
+ export const POST = async (request: Request) => {
40
+ const payload = (await request.json()) as ProxyPayload;
41
+
42
+ if (!(payload?.url && payload?.method)) {
43
+ return jsonError("Invalid payload", 400);
44
+ }
45
+
46
+ const context = await getOpenApiProxyContext();
47
+ if (!context) {
48
+ return jsonError("Invalid docs configuration", 400);
49
+ }
50
+
51
+ if (!context.config.openapiProxy?.enabled) {
52
+ return jsonError("Proxy disabled", 403);
53
+ }
54
+
55
+ const url = new URL(payload.url);
56
+ if (!["http:", "https:"].includes(url.protocol)) {
57
+ return jsonError("Invalid protocol", 400);
58
+ }
59
+
60
+ const allowedHosts = await resolveAllowedHosts();
61
+ if (!allowedHosts?.length) {
62
+ return jsonError(
63
+ "No proxy allowlist is configured for this docs.json.",
64
+ 403
65
+ );
66
+ }
67
+
68
+ if (!allowedHosts.includes(url.hostname)) {
69
+ return jsonError("Host not allowed", 403);
70
+ }
71
+
72
+ const method = payload.method.toUpperCase();
73
+ const response = await fetch(payload.url, {
74
+ body: method === "GET" ? undefined : payload.body,
75
+ headers: payload.headers,
76
+ method,
77
+ });
78
+
79
+ const text = await response.text();
80
+ return new NextResponse(text, {
81
+ headers: {
82
+ "content-type": response.headers.get("content-type") ?? "text/plain",
83
+ },
84
+ status: response.status,
85
+ });
86
+ };
@@ -0,0 +1,24 @@
1
+ "use client";
2
+
3
+ const Error = ({
4
+ reset,
5
+ }: {
6
+ error: Error & { digest?: string };
7
+ reset: () => void;
8
+ }) => (
9
+ <div className="flex min-h-[60vh] flex-col items-center justify-center gap-4 px-4 text-center">
10
+ <h1 className="text-4xl font-bold tracking-tight">Something went wrong</h1>
11
+ <p className="max-w-md text-muted-foreground">
12
+ An error occurred while loading this page.
13
+ </p>
14
+ <button
15
+ className="mt-2 rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90"
16
+ onClick={reset}
17
+ type="button"
18
+ >
19
+ Try again
20
+ </button>
21
+ </div>
22
+ );
23
+
24
+ export default Error;
Binary file
@@ -0,0 +1,4 @@
1
+ @import "../../docs/app/globals.css";
2
+
3
+ @source "../";
4
+ @source "../../docs";
@@ -0,0 +1,38 @@
1
+ import { DevReloadScript } from "@dev/components/dev-reload-script";
2
+ import { Providers } from "@dev/components/providers";
3
+ import { GeistMono } from "geist/font/mono";
4
+ import type { Metadata } from "next";
5
+ import localFont from "next/font/local";
6
+
7
+ import "./globals.css";
8
+
9
+ const glide = localFont({
10
+ display: "swap",
11
+ src: [{ path: "../public/glide-variable.woff2" }],
12
+ variable: "--font-glide",
13
+ weight: "400 900",
14
+ });
15
+
16
+ export const metadata: Metadata = {
17
+ description: "Local docs preview for blodemd dev.",
18
+ title: "blodemd dev",
19
+ };
20
+
21
+ export default function RootLayout({
22
+ children,
23
+ }: Readonly<{
24
+ children: React.ReactNode;
25
+ }>) {
26
+ return (
27
+ <html
28
+ lang="en"
29
+ className={`${glide.variable} ${GeistMono.variable}`}
30
+ suppressHydrationWarning
31
+ >
32
+ <body className="relative flex w-full flex-col justify-center overflow-x-hidden scroll-smooth bg-background font-sans antialiased [--header-height:calc(var(--spacing)*14)]">
33
+ <DevReloadScript />
34
+ <Providers>{children}</Providers>
35
+ </body>
36
+ </html>
37
+ );
38
+ }
@@ -0,0 +1,18 @@
1
+ import Link from "next/link";
2
+
3
+ const NotFound = () => (
4
+ <div className="flex min-h-[60vh] flex-col items-center justify-center gap-4 px-4 text-center">
5
+ <h1 className="text-4xl font-bold tracking-tight">Page not found</h1>
6
+ <p className="max-w-md text-muted-foreground">
7
+ The page you are looking for does not exist or has been moved.
8
+ </p>
9
+ <Link
10
+ className="mt-2 rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90"
11
+ href="/"
12
+ >
13
+ Go home
14
+ </Link>
15
+ </div>
16
+ );
17
+
18
+ export default NotFound;
@@ -0,0 +1,17 @@
1
+ import { getSearchItems } from "@dev/lib/local-runtime";
2
+ import { NextResponse } from "next/server";
3
+
4
+ export const dynamic = "force-dynamic";
5
+
6
+ export const GET = async (): Promise<Response> => {
7
+ const items = await getSearchItems();
8
+
9
+ return NextResponse.json(
10
+ { items },
11
+ {
12
+ headers: {
13
+ "Cache-Control": "no-store",
14
+ },
15
+ }
16
+ );
17
+ };
@@ -0,0 +1,86 @@
1
+ "use client";
2
+
3
+ import { useRouter } from "next/navigation";
4
+ import { startTransition, useEffect, useRef } from "react";
5
+
6
+ const POLL_INTERVAL_MS = 1000;
7
+
8
+ const readVersion = async (): Promise<number | null> => {
9
+ try {
10
+ const response = await fetch("/blodemd-dev/version", {
11
+ cache: "no-store",
12
+ headers: {
13
+ accept: "application/json",
14
+ },
15
+ });
16
+
17
+ if (!response.ok) {
18
+ return null;
19
+ }
20
+
21
+ const payload = (await response.json()) as { version?: number };
22
+ return typeof payload.version === "number" ? payload.version : null;
23
+ } catch {
24
+ return null;
25
+ }
26
+ };
27
+
28
+ export const DevReloadScript = () => {
29
+ const router = useRouter();
30
+ const currentVersionRef = useRef<number | null>(null);
31
+ const refreshInFlightRef = useRef(false);
32
+
33
+ useEffect(() => {
34
+ let cancelled = false;
35
+
36
+ const poll = async () => {
37
+ if (document.visibilityState !== "visible") {
38
+ return;
39
+ }
40
+
41
+ const version = await readVersion();
42
+ if (cancelled || version === null) {
43
+ return;
44
+ }
45
+
46
+ if (currentVersionRef.current === null) {
47
+ currentVersionRef.current = version;
48
+ return;
49
+ }
50
+
51
+ if (version === currentVersionRef.current || refreshInFlightRef.current) {
52
+ return;
53
+ }
54
+
55
+ currentVersionRef.current = version;
56
+ refreshInFlightRef.current = true;
57
+
58
+ startTransition(() => {
59
+ router.refresh();
60
+ window.setTimeout(() => {
61
+ refreshInFlightRef.current = false;
62
+ }, 150);
63
+ });
64
+ };
65
+
66
+ const pollSafely = async () => {
67
+ try {
68
+ await poll();
69
+ } catch {
70
+ // Ignore transient polling errors during local dev.
71
+ }
72
+ };
73
+
74
+ pollSafely();
75
+ const interval = window.setInterval(() => {
76
+ pollSafely();
77
+ }, POLL_INTERVAL_MS);
78
+
79
+ return () => {
80
+ cancelled = true;
81
+ window.clearInterval(interval);
82
+ };
83
+ }, [router]);
84
+
85
+ return null;
86
+ };
@@ -0,0 +1,15 @@
1
+ "use client";
2
+
3
+ import { ThemeProvider } from "next-themes";
4
+
5
+ export const Providers = ({ children }: { children: React.ReactNode }) => (
6
+ <ThemeProvider
7
+ attribute="class"
8
+ defaultTheme="system"
9
+ disableTransitionOnChange
10
+ enableColorScheme
11
+ storageKey="theme"
12
+ >
13
+ {children}
14
+ </ThemeProvider>
15
+ );
@@ -0,0 +1,8 @@
1
+ let version = 0;
2
+
3
+ export const getDevVersion = () => version;
4
+
5
+ export const bumpDevVersion = () => {
6
+ version += 1;
7
+ return version;
8
+ };
@@ -0,0 +1,103 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ import { normalizePath } from "@repo/common";
5
+ import type { ContentSource } from "@repo/previewing";
6
+ import { createFsSource } from "@repo/previewing";
7
+
8
+ const BINARY_CONTENT_TYPES: Record<string, string> = {
9
+ ".avif": "image/avif",
10
+ ".gif": "image/gif",
11
+ ".ico": "image/x-icon",
12
+ ".jpeg": "image/jpeg",
13
+ ".jpg": "image/jpeg",
14
+ ".otf": "font/otf",
15
+ ".png": "image/png",
16
+ ".svg": "image/svg+xml",
17
+ ".ttf": "font/ttf",
18
+ ".webp": "image/webp",
19
+ ".woff": "font/woff",
20
+ ".woff2": "font/woff2",
21
+ };
22
+
23
+ const TEXT_CONTENT_TYPES: Record<string, string> = {
24
+ ".css": "text/css; charset=utf-8",
25
+ ".html": "text/html; charset=utf-8",
26
+ ".js": "text/javascript; charset=utf-8",
27
+ ".json": "application/json; charset=utf-8",
28
+ ".md": "text/markdown; charset=utf-8",
29
+ ".mdx": "text/markdown; charset=utf-8",
30
+ ".txt": "text/plain; charset=utf-8",
31
+ ".yaml": "application/yaml; charset=utf-8",
32
+ ".yml": "application/yaml; charset=utf-8",
33
+ };
34
+
35
+ const isWithinRoot = (root: string, candidate: string) =>
36
+ candidate === root || candidate.startsWith(`${root}${path.sep}`);
37
+
38
+ const getDocsRoot = () => {
39
+ const root = process.env.DOCS_ROOT?.trim();
40
+
41
+ if (!root) {
42
+ throw new Error("DOCS_ROOT is required for the local dev server.");
43
+ }
44
+
45
+ return path.resolve(root);
46
+ };
47
+
48
+ const resolveDocsPath = (relativePath: string) => {
49
+ const root = getDocsRoot();
50
+ const normalized = normalizePath(relativePath);
51
+ const absolutePath = path.resolve(root, normalized);
52
+
53
+ if (!isWithinRoot(root, absolutePath)) {
54
+ throw new Error(`Path "${relativePath}" escapes DOCS_ROOT.`);
55
+ }
56
+
57
+ return absolutePath;
58
+ };
59
+
60
+ const toStaticAssetUrl = (relativePath: string) => {
61
+ const normalized = normalizePath(relativePath);
62
+
63
+ if (!normalized || normalized === ".") {
64
+ return "/blodemd-dev/static";
65
+ }
66
+
67
+ return `/blodemd-dev/static/${normalized
68
+ .split("/")
69
+ .map((segment) => encodeURIComponent(segment))
70
+ .join("/")}`;
71
+ };
72
+
73
+ export const createPreviewContentSource = (): ContentSource => {
74
+ const source = createFsSource(getDocsRoot());
75
+
76
+ return {
77
+ exists(relativePath) {
78
+ return source.exists(relativePath);
79
+ },
80
+ listFiles(directory) {
81
+ return source.listFiles(directory);
82
+ },
83
+ readFile(relativePath) {
84
+ return source.readFile(relativePath);
85
+ },
86
+ resolveUrl(relativePath) {
87
+ return toStaticAssetUrl(relativePath);
88
+ },
89
+ };
90
+ };
91
+
92
+ export const readStaticAsset = async (relativePath: string) =>
93
+ await fs.readFile(resolveDocsPath(relativePath));
94
+
95
+ export const getStaticAssetContentType = (relativePath: string) => {
96
+ const extension = path.extname(relativePath).toLowerCase();
97
+
98
+ return (
99
+ TEXT_CONTENT_TYPES[extension] ??
100
+ BINARY_CONTENT_TYPES[extension] ??
101
+ "application/octet-stream"
102
+ );
103
+ };