@jsnchn/buntastic 0.0.9 → 0.0.10
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 +42 -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,16 @@ 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 file = Bun.file(distPath);
|
|
293
|
+
const mimeType = getMimeType(distPath);
|
|
294
|
+
return new Response(file, {
|
|
295
|
+
headers: { "Content-Type": mimeType },
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
267
299
|
if (path === "/") {
|
|
268
300
|
path = "/index";
|
|
269
301
|
}
|
|
@@ -337,6 +369,16 @@ async function preview(): Promise<void> {
|
|
|
337
369
|
const url = new URL(req.url);
|
|
338
370
|
let path = url.pathname;
|
|
339
371
|
|
|
372
|
+
const distPath = join(DIST_DIR, path);
|
|
373
|
+
|
|
374
|
+
if (await exists(distPath)) {
|
|
375
|
+
const file = Bun.file(distPath);
|
|
376
|
+
const mimeType = getMimeType(distPath);
|
|
377
|
+
return new Response(file, {
|
|
378
|
+
headers: { "Content-Type": mimeType },
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
340
382
|
if (path === "/") {
|
|
341
383
|
path = "/index";
|
|
342
384
|
}
|