ework-web 0.10.92 → 0.10.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +7 -3
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
1
2
|
import { buildPiSessionPage } from "./pi-sessions";
|
|
2
3
|
import { join, dirname } from "path";
|
|
3
4
|
import { fileURLToPath } from "url";
|
|
@@ -220,8 +221,10 @@ function buildCsp(cfg: Config): string {
|
|
|
220
221
|
const hlCss = loadHighlightCss();
|
|
221
222
|
|
|
222
223
|
function loadHighlightCss(): string {
|
|
223
|
-
|
|
224
|
-
|
|
224
|
+
let dir: string | null = null;
|
|
225
|
+
try { dir = dirname(createRequire(import.meta.url).resolve("highlight.js/package.json")); } catch { dir = null; }
|
|
226
|
+
const light = readFileSafe(dir ? join(dir, "styles", "github.css") : null) || readFileSafe(join(__dirname, "..", "node_modules", "highlight.js", "styles", "github.css"));
|
|
227
|
+
const dark = readFileSafe(dir ? join(dir, "styles", "github-dark.css") : null) || readFileSafe(join(__dirname, "..", "node_modules", "highlight.js", "styles", "github-dark.css"));
|
|
225
228
|
if (!light && !dark) return "";
|
|
226
229
|
const darkRule = dark
|
|
227
230
|
? `@media (prefers-color-scheme:dark){${stripAtMedia(dark)}}`
|
|
@@ -229,7 +232,8 @@ function loadHighlightCss(): string {
|
|
|
229
232
|
return `${light}${darkRule}`;
|
|
230
233
|
}
|
|
231
234
|
|
|
232
|
-
function readFileSafe(p: string): string {
|
|
235
|
+
function readFileSafe(p: string | null): string {
|
|
236
|
+
if (!p) return "";
|
|
233
237
|
try {
|
|
234
238
|
return readFileSync(p, "utf8");
|
|
235
239
|
} catch {
|