-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add versioning in output file and to loaded urls
- Loading branch information
1 parent
dd1449f
commit addc87e
Showing
3 changed files
with
12 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import { bundle } from "jsr:@libs/bundle@5/css" | ||
import { banner as _banner } from "../app/build/css.ts" | ||
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/[email protected]" | ||
import { version } from "../app/build/version.ts" | ||
|
||
/** API: Minify css */ | ||
export default async function (request: Request) { | ||
|
@@ -14,7 +15,7 @@ export default async function (request: Request) { | |
} | ||
try { | ||
const body = await request.text() | ||
const banner = _banner.replace("matcha.css\n", `matcha.css — Custom build (${new Date().toDateString()})\n`) | ||
const banner = _banner.replace(`matcha.css — ${version}\n`, `matcha.css — ${version} — Custom build (${new Date().toDateString()})\n`) | ||
const bundled = await bundle(body, { minify: true, banner, rules: { "no-descending-specificity": false, "no-duplicate-selectors": false, "declaration-no-important": false } }) | ||
return new Response(bundled, { headers: { "Content-Type": "text/css" } }) | ||
} catch (error) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ import { expandGlob } from "jsr:@std/[email protected]" | |
import { fromFileUrl } from "jsr:@std/[email protected]" | ||
import { bundle } from "jsr:@libs/bundle@5/css" | ||
import { root as _root } from "./root.ts" | ||
import { version } from "./version.ts" | ||
|
||
/** Banner */ | ||
export const banner = [ | ||
"matcha.css", | ||
`matcha.css — ${version}`, | ||
`Copyright © ${new Date().getFullYear()} Lecoq Simon (@lowlighter)`, | ||
"MIT license — https://github.com/lowlighter/matcha", | ||
].join("\n") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { default as hlmd } from "https://esm.sh/[email protected]/lib/language | |
import { default as hlsh } from "https://esm.sh/[email protected]/lib/languages/diff" | ||
import { DOMParser, type HTMLDocument } from "https://deno.land/x/[email protected]/deno-dom-wasm.ts" | ||
import { gzipSize } from "https://deno.land/x/[email protected]/mod.ts" | ||
import { version } from "./version.ts" | ||
syntax.registerLanguage("xml", hlxml) | ||
syntax.registerLanguage("css", hlcss) | ||
syntax.registerLanguage("lisp", hllisp) | ||
|
@@ -187,6 +188,13 @@ async function template({ remove }: { remove?: { parent?: string[]; selectors?: | |
} | ||
const document = new DOMParser().parseFromString(html, "text/html")! | ||
highlight(document) | ||
// Force uncached resources on version changes | ||
document.querySelectorAll('link[rel="stylesheet"]').forEach((element) => { | ||
const link = element as unknown as HTMLLinkElement | ||
if (link.getAttribute("href")?.startsWith("/")) { | ||
link.setAttribute("href", `${link.getAttribute("href")}?v=${version}`) | ||
} | ||
}) | ||
// Include scripts | ||
await Promise.all( | ||
Array.from(document.querySelectorAll("script[data-script]")).map(async (_element) => { | ||
|