Skip to content

Commit

Permalink
refactor: vendor highlight.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Jun 10, 2024
1 parent 1ce0fca commit 0bf6c1f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/build/ssg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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!")
}
2 changes: 1 addition & 1 deletion app/mod.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<link rel="stylesheet" href="/mod.css">
<link rel="apple-touch-icon" sizes="180x180" href="/180x180.png">
<link rel="icon" type="image/png" sizes="32x32" href="/32x32.png">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="/highlight.js"></script>
</head>
<body class="layout-simple">
<header>
Expand Down
4 changes: 3 additions & 1 deletion app/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 })
}
Expand Down
9 changes: 8 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@
"semiColons": false,
"lineWidth": 200,
"exclude": [
"coverage"
"coverage",
".pages"
]
},
"lint": {
"exclude": [
"coverage",
".pages"
]
}
}

0 comments on commit 0bf6c1f

Please sign in to comment.