@jsnchn/buntastic 0.0.9 → 0.0.11
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.
- package/package.json +1 -1
- package/src/index.ts +48 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -9,6 +9,28 @@ const LAYOUTS_DIR = join(process.cwd(), "src/layouts");
|
|
|
9
9
|
const PUBLIC_DIR = join(process.cwd(), "public");
|
|
10
10
|
const DIST_DIR = join(process.cwd(), "dist");
|
|
11
11
|
|
|
12
|
+
const MIME_TYPES: Record<string, string> = {
|
|
13
|
+
".html": "text/html",
|
|
14
|
+
".css": "text/css",
|
|
15
|
+
".js": "application/javascript",
|
|
16
|
+
".json": "application/json",
|
|
17
|
+
".png": "image/png",
|
|
18
|
+
".jpg": "image/jpeg",
|
|
19
|
+
".jpeg": "image/jpeg",
|
|
20
|
+
".gif": "image/gif",
|
|
21
|
+
".svg": "image/svg+xml",
|
|
22
|
+
".ico": "image/x-icon",
|
|
23
|
+
".woff": "font/woff",
|
|
24
|
+
".woff2": "font/woff2",
|
|
25
|
+
".ttf": "font/ttf",
|
|
26
|
+
".eot": "application/vnd.ms-fontobject",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function getMimeType(filePath: string): string {
|
|
30
|
+
const ext = extname(filePath).toLowerCase();
|
|
31
|
+
return MIME_TYPES[ext] || "application/octet-stream";
|
|
32
|
+
}
|
|
33
|
+
|
|
12
34
|
interface Frontmatter {
|
|
13
35
|
title?: string;
|
|
14
36
|
date?: string;
|
|
@@ -264,6 +286,19 @@ async function dev(): Promise<void> {
|
|
|
264
286
|
const url = new URL(req.url);
|
|
265
287
|
let path = url.pathname;
|
|
266
288
|
|
|
289
|
+
const distPath = join(DIST_DIR, path);
|
|
290
|
+
|
|
291
|
+
if (await exists(distPath)) {
|
|
292
|
+
const stat = await import("fs").then(fs => fs.statSync(distPath));
|
|
293
|
+
if (stat.isFile()) {
|
|
294
|
+
const file = Bun.file(distPath);
|
|
295
|
+
const mimeType = getMimeType(distPath);
|
|
296
|
+
return new Response(file, {
|
|
297
|
+
headers: { "Content-Type": mimeType },
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
267
302
|
if (path === "/") {
|
|
268
303
|
path = "/index";
|
|
269
304
|
}
|
|
@@ -337,6 +372,19 @@ async function preview(): Promise<void> {
|
|
|
337
372
|
const url = new URL(req.url);
|
|
338
373
|
let path = url.pathname;
|
|
339
374
|
|
|
375
|
+
const distPath = join(DIST_DIR, path);
|
|
376
|
+
|
|
377
|
+
if (await exists(distPath)) {
|
|
378
|
+
const stat = await import("fs").then(fs => fs.statSync(distPath));
|
|
379
|
+
if (stat.isFile()) {
|
|
380
|
+
const file = Bun.file(distPath);
|
|
381
|
+
const mimeType = getMimeType(distPath);
|
|
382
|
+
return new Response(file, {
|
|
383
|
+
headers: { "Content-Type": mimeType },
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
340
388
|
if (path === "/") {
|
|
341
389
|
path = "/index";
|
|
342
390
|
}
|