Skip to content

Commit

Permalink
feat: seperate CSS bundle from html
Browse files Browse the repository at this point in the history
  • Loading branch information
lino-levan committed Mar 13, 2023
1 parent 82d69de commit ef7e639
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join, resolve } from "std/path/mod.ts";
import { render } from "./lib/render.ts";
import { copySync } from "std/fs/copy.ts";
import { getMagic } from "./lib/magic.ts";
import { CSS } from "./lib/css.ts";

export function build() {
try {
Expand All @@ -15,6 +16,8 @@ export function build() {

copySync("./static", "./build");

Deno.writeTextFileSync("./build/bundle.css", CSS);

const config = JSON.parse(Deno.readTextFileSync("deno.jsonc")).pyro;
const magic = getMagic();

Expand Down
10 changes: 10 additions & 0 deletions src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolve } from "std/path/mod.ts";
import { serveDir } from "std/http/file_server.ts";
import { render } from "./lib/render.ts";
import { getMagic } from "./lib/magic.ts";
import { CSS } from "./lib/css.ts";

export function dev() {
const config = JSON.parse(Deno.readTextFileSync("deno.jsonc")).pyro;
Expand All @@ -11,6 +12,15 @@ export function dev() {
const url = new URL(req.url);
const pathname = url.pathname.slice(1);

// Handle the bundled css
if (pathname === "bundle.css") {
return new Response(CSS, {
headers: {
"Content-Type": "text/css",
},
});
}

// We're supposed to serve a static file
if (pathname.includes(".")) {
try {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CSS as MK_CSS, KATEX_CSS } from "gfm";

export const CSS = (MK_CSS + KATEX_CSS +
".markdown-body ul{list-style:disc}.markdown-body ol{list-style: numeric}.markdown-body table{width: fit-content;}details > summary{list-style: none;}details > summary::marker,details > summary::-webkit-details-marker {display: none;}")
.replaceAll("\n", "");
2 changes: 0 additions & 2 deletions src/lib/magic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ function getBackground() {
}
}

console.log("Brightest color is", brightest_color);

return brightest_color;
} catch {
return "white";
Expand Down
25 changes: 2 additions & 23 deletions src/lib/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CSS, KATEX_CSS, render } from "gfm";
import { render } from "gfm";
import type { RouteMap } from "./route_map.ts";
import type { Config, Magic } from "./types.ts";

Expand Down Expand Up @@ -79,28 +79,7 @@ export function page(options: {
<html lang="en">
<head>
<title>{options.page.title} | {options.config.title}</title>
<style
dangerouslySetInnerHTML={{
__html: CSS + KATEX_CSS + `.markdown-body ul {
list-style: disc
}
.markdown-body ol {
list-style: numeric
}
.markdown-body table {
width: fit-content;
}
details > summary {
list-style: none;
}
details > summary::marker,
details > summary::-webkit-details-marker {
display: none;
}
`,
}}
/>
<link rel="stylesheet" href="/bundle.css" />
<script src="https://cdn.twind.style" />
<meta name="description" content={options.page.description} />
<link rel="icon" type="image/png" href="/icon.png" />
Expand Down

0 comments on commit ef7e639

Please sign in to comment.