From 0bf6c1feff0532c306aece1994e04c377bbfc7ee Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Mon, 10 Jun 2024 04:32:28 +0200 Subject: [PATCH] refactor: vendor highlight.js --- app/build/ssg.ts | 6 ++++++ app/mod.html | 2 +- app/mod.ts | 4 +++- deno.jsonc | 9 ++++++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/build/ssg.ts b/app/build/ssg.ts index 6c38e29..7281daa 100644 --- a/app/build/ssg.ts +++ b/app/build/ssg.ts @@ -5,6 +5,9 @@ import { root } from "./root.ts" import { html, html_builder, html_builder_demo } from "./html.ts" import { compatibility } from "jsr:@libs/bundle@5/css" +/** Highlight.js CDN */ +export const highlight = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" + /** Static site generation */ export async function ssg() { await emptyDir(new URL(".pages", root)) @@ -52,5 +55,8 @@ export async function ssg() { console.log(`Created .pages/${alias}`) } } + // Download highlight.js + await Deno.writeTextFile(new URL(".pages/highlight.js", root), await fetch(highlight).then((response) => response.text())) + console.log("Created .pages/highlight.js") console.log("Done!") } diff --git a/app/mod.html b/app/mod.html index 709c086..7151e6f 100644 --- a/app/mod.html +++ b/app/mod.html @@ -13,7 +13,7 @@ - +
diff --git a/app/mod.ts b/app/mod.ts index 772d5a0..122397f 100644 --- a/app/mod.ts +++ b/app/mod.ts @@ -2,7 +2,7 @@ // Imports import { css } from "./build/css.ts" import { html, html_builder, html_builder_demo } from "./build/html.ts" -import { ssg } from "./build/ssg.ts" +import { highlight, ssg } from "./build/ssg.ts" import { dist } from "./build/dist.ts" import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http@0.224.1" import { root } from "./build/root.ts" @@ -38,6 +38,8 @@ switch (Deno.args[0]) { return api_minify(request) case new URLPattern("/api/preview", url.origin).test(url.href.replace(url.search, "")): return api_preview(request) + case new URLPattern("/highlight.js", url.origin).test(url.href): + return fetch(highlight) default: return new Response(STATUS_TEXT[STATUS_CODE.NotFound], { status: STATUS_CODE.NotFound }) } diff --git a/deno.jsonc b/deno.jsonc index 7985c47..9b20433 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -39,7 +39,14 @@ "semiColons": false, "lineWidth": 200, "exclude": [ - "coverage" + "coverage", + ".pages" + ] + }, + "lint": { + "exclude": [ + "coverage", + ".pages" ] } }