Skip to content

Commit dc6400a

Browse files
WIP
1 parent 5230832 commit dc6400a

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

www/routes/docs/[...slug].tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ export const handler = define.handlers<Data>({
120120
}
121121

122122
// Parse markdown front matter
123-
const url = new URL(`../../../${entry.file}`, import.meta.url);
123+
// deno-lint-ignore no-explicit-any
124+
const url = (import.meta as any).env.PROD
125+
? new URL(`../${entry.file}`, import.meta.url)
126+
: new URL(`../../../${entry.file}`, import.meta.url);
124127
const fileContent = await Deno.readTextFile(url);
125128
const { body, attrs } = frontMatter<Record<string, unknown>>(fileContent);
126129

www/vite.config.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,51 @@
1-
import { defineConfig } from "vite";
1+
import { defineConfig, type Plugin } from "vite";
22
import { fresh } from "@fresh/plugin-vite";
33
import tailwindcss from "@tailwindcss/vite";
44
import inspect from "vite-plugin-inspect";
5+
import { copy } from "@std/fs";
6+
import * as path from "@std/path";
57

68
export default defineConfig({
79
plugins: [
810
fresh(),
911
tailwindcss(),
1012
inspect(),
13+
copyDocs(),
1114
],
1215
});
16+
17+
function copyDocs(): Plugin {
18+
let serverOutDir = "";
19+
20+
return {
21+
name: "fresh:copy-docs",
22+
configResolved(config) {
23+
serverOutDir = config.environments.ssr.build.outDir;
24+
},
25+
async writeBundle() {
26+
const branches = ["canary", "latest"];
27+
28+
for (const branch of branches) {
29+
const source = path.join(import.meta.dirname!, "..", "docs", branch);
30+
const target = path.join(serverOutDir, "docs", branch);
31+
32+
try {
33+
await Deno.remove(target, { recursive: true });
34+
} catch (err) {
35+
if (!(err instanceof Deno.errors.NotFound)) {
36+
throw err;
37+
}
38+
}
39+
40+
try {
41+
await Deno.mkdir(path.dirname(target), { recursive: true });
42+
} catch {
43+
// Ignore
44+
}
45+
46+
// await new Promise((r) => setTimeout(r, 2220000));
47+
await copy(source, target);
48+
}
49+
},
50+
};
51+
}

0 commit comments

Comments
 (0)