Skip to content

Commit a754a3d

Browse files
committed
docs
1 parent 574f360 commit a754a3d

File tree

4 files changed

+75
-56
lines changed

4 files changed

+75
-56
lines changed

docs/astro.config.mjs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,7 @@
11
import { defineConfig } from "astro/config";
22
import starlight from "@astrojs/starlight";
3-
import { ExpressiveCodeTheme } from "@astrojs/starlight/expressive-code";
4-
import fs from "node:fs";
5-
import path from "node:path";
63
import starlightImageZoom from "starlight-image-zoom";
74

8-
// Define allowed paths relative to project root
9-
const ALLOWED_PATHS = ["src/themes/expressive-code"];
10-
11-
function readFileSyncSafe(url) {
12-
if (url.protocol !== "file:") {
13-
throw new Error("Invalid URL protocol");
14-
}
15-
16-
// Convert URL to filesystem path and normalize
17-
const filePath = path.normalize(url.pathname);
18-
19-
// Ensure path is within allowed directories
20-
const isAllowed = ALLOWED_PATHS.some((allowedPath) =>
21-
filePath.includes(path.normalize(allowedPath))
22-
);
23-
24-
if (!isAllowed) {
25-
throw new Error("Access to this directory is not allowed");
26-
}
27-
28-
return fs.readFileSync(url, "utf-8");
29-
}
30-
31-
const jsoncStringLight = readFileSyncSafe(
32-
new URL(
33-
"./src/themes/expressive-code/Snazzy-Light-color-theme.json",
34-
import.meta.url
35-
)
36-
);
37-
38-
const jsoncStringDark = readFileSyncSafe(
39-
new URL(
40-
"./src/themes/expressive-code/aura-soft-dark-soft-text-color-theme.json",
41-
import.meta.url
42-
)
43-
);
44-
45-
const darkMode = ExpressiveCodeTheme.fromJSONString(jsoncStringDark);
46-
const lightMode = ExpressiveCodeTheme.fromJSONString(jsoncStringLight);
47-
485
// https://astro.build/config
496
export default defineConfig({
507
site: "https://userdocs.github.io",
@@ -59,19 +16,6 @@ export default defineConfig({
5916
components: {
6017
Header: "./src/components/Header.astro",
6118
},
62-
expressiveCode: {
63-
themes: [darkMode, lightMode],
64-
tabWidth: 0,
65-
styleOverrides: {
66-
borderRadius: "0.1rem",
67-
frames: {
68-
shadowColor: "none",
69-
},
70-
},
71-
defaultProps: {
72-
frame: "none",
73-
},
74-
},
7519

7620
social: {
7721
github: "https://github.com/userdocs/qbittorrent-nox-static",

docs/ec.config.mjs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { pluginCollapsibleSections } from "@expressive-code/plugin-collapsible-sections";
2+
import { ExpressiveCodeTheme } from "@astrojs/starlight/expressive-code";
3+
import fs from "node:fs";
4+
import path from "node:path";
5+
6+
// Define allowed paths relative to project root
7+
const ALLOWED_PATHS = ["src/themes/expressive-code"];
8+
9+
function readFileSyncSafe(url) {
10+
if (url.protocol !== "file:") {
11+
throw new Error("Invalid URL protocol");
12+
}
13+
14+
// Convert URL to filesystem path and normalize
15+
const filePath = path.normalize(url.pathname);
16+
17+
// Ensure path is within allowed directories
18+
const isAllowed = ALLOWED_PATHS.some((allowedPath) =>
19+
filePath.includes(path.normalize(allowedPath))
20+
);
21+
22+
if (!isAllowed) {
23+
throw new Error("Access to this directory is not allowed");
24+
}
25+
26+
return fs.readFileSync(url, "utf-8");
27+
}
28+
29+
const jsoncStringLight = readFileSyncSafe(
30+
new URL(
31+
"./src/themes/expressive-code/Snazzy-Light-color-theme.json",
32+
import.meta.url
33+
)
34+
);
35+
36+
const jsoncStringDark = readFileSyncSafe(
37+
new URL(
38+
"./src/themes/expressive-code/aura-soft-dark-soft-text-color-theme.json",
39+
import.meta.url
40+
)
41+
);
42+
43+
const darkMode = ExpressiveCodeTheme.fromJSONString(jsoncStringDark);
44+
const lightMode = ExpressiveCodeTheme.fromJSONString(jsoncStringLight);
45+
46+
/** @type {import('@astrojs/starlight/expressive-code').StarlightExpressiveCodeOptions} */
47+
export default {
48+
// Example: Using a custom plugin (which makes this `ec.config.mjs` file necessary)
49+
plugins: [pluginCollapsibleSections()],
50+
defaultProps: {
51+
collapseStyle: "collapsible-start",
52+
frame: "none",
53+
},
54+
themes: [darkMode, lightMode],
55+
tabWidth: 0,
56+
styleOverrides: {
57+
borderRadius: "0.1rem",
58+
frames: {
59+
shadowColor: "none",
60+
},
61+
},
62+
};

docs/package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
},
1212
"dependencies": {
1313
"@astrojs/starlight": "^0.31.0",
14+
"@expressive-code/plugin-collapsible-sections": "^0.40.0",
1415
"astro": "^5.1.7",
16+
"expressive-code": "^0.40.0",
1517
"gray-matter": "^4.0.3",
1618
"sharp": "^0.32.5",
1719
"starlight-image-zoom": "^0.9.0",

0 commit comments

Comments
 (0)