Skip to content

Commit b2ffe8e

Browse files
committed
Embed CSS files as TS
denoland/deno#25354 (comment)
1 parent dd8d9c9 commit b2ffe8e

27 files changed

+2778
-20
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"phensley",
6565
"pico",
6666
"Pixelfed",
67+
"smallweb",
6768
"Tailscale",
6869
"unfollow",
6970
"unfollowed",

deno.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"@phensley/language-tag": "npm:@phensley/language-tag@^1.9.2",
2525
"@std/assert": "jsr:@std/assert@^1.0.10",
2626
"@std/html": "jsr:@std/html@^1.0.3",
27-
"@std/path": "jsr:@std/path@^1.0.8",
2827
"@std/uuid": "jsr:@std/uuid@^1.0.4",
2928
"markdown-it": "npm:markdown-it@^14.1.0",
3029
"xss": "npm:xss@^1.0.15"
@@ -33,15 +32,17 @@
3332
"exclude": [
3433
".github",
3534
".vscode",
36-
"docs"
35+
"docs",
36+
"src/css"
3737
],
3838
"fmt": {
3939
"exclude": [
40-
"src/css/*.css",
41-
"*.md"
40+
"*.md",
41+
"src/static/*.ts"
4242
]
4343
},
4444
"tasks": {
45+
"embed-css": "deno run -A jsr:@smallweb/embed src/css src/static",
4546
"check": "deno check src/ && deno lint && deno fmt --check && deno publish --dry-run --allow-dirty",
4647
"test": "deno test --allow-net=hollo.social",
4748
"test-all": "deno task check && deno task test",

src/css/pico.azure.min.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/css/pico.azure.min.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/css/pico.min.css

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/pages.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import {
2424
PUBLIC_COLLECTION,
2525
} from "@fedify/fedify/vocab";
2626
import { Hono } from "@hono/hono";
27-
import { join } from "@std/path/join";
2827
import type { BotImpl } from "./bot-impl.ts";
2928
import { Layout } from "./components/Layout.tsx";
3029
import { Message } from "./components/Message.tsx";
3130
import { getMessageClass, isMessageObject } from "./message-impl.ts";
3231
import type { MessageClass } from "./message.ts";
3332
import type { Uuid } from "./repository.ts";
33+
import staticFiles from "./static/mod.ts";
3434

3535
export interface Bindings {
3636
readonly bot: BotImpl<unknown>;
@@ -44,16 +44,10 @@ export interface Env {
4444
export const app = new Hono<Env>();
4545

4646
app.get("/css/:filename", async (c) => {
47-
let data: string;
48-
try {
49-
data = await Deno.readTextFile(
50-
join(import.meta.dirname ?? ".", "css", c.req.param("filename")),
51-
);
52-
} catch (e) {
53-
console.error(e);
54-
return c.notFound();
55-
}
56-
return c.body(data, 200, { "Content-Type": "text/css" });
47+
const file = await staticFiles.get(c.req.param("filename"));
48+
if (file == null) return c.notFound();
49+
const bytes = await file.bytes();
50+
return c.body(bytes, 200, { "Content-Type": "text/css" });
5751
});
5852

5953
const WINDOW = 15;

src/static/.gitattributes

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/static/_pico.amber.min.css.ts

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/static/_pico.azure.min.css.ts

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)