@theholocron/docs-theme 0.1.0 → 1.1.0
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/README.md +34 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.mjs +13 -0
- package/dist/loader.d.mts +34 -0
- package/dist/loader.mjs +88 -0
- package/dist/styles.css +21 -0
- package/package.json +13 -4
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @theholocron/docs-theme
|
|
2
|
+
|
|
3
|
+
Starlight plugin that injects the shared `@theholocron` docs CSS theme.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @theholocron/docs-theme
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// astro.config.ts
|
|
15
|
+
import { docsTheme } from "@theholocron/docs-theme";
|
|
16
|
+
import starlight from "@astrojs/starlight";
|
|
17
|
+
import { defineConfig } from "astro/config";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
integrations: [
|
|
21
|
+
starlight({
|
|
22
|
+
plugins: [docsTheme()],
|
|
23
|
+
title: "My Docs",
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Peer dependencies
|
|
30
|
+
|
|
31
|
+
| Package | Version |
|
|
32
|
+
| -------------------- | ---------- |
|
|
33
|
+
| `astro` | `>=5.0.0` |
|
|
34
|
+
| `@astrojs/starlight` | `>=0.30.0` |
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface SetupOptions {
|
|
3
|
+
config: {
|
|
4
|
+
customCss?: string[];
|
|
5
|
+
};
|
|
6
|
+
updateConfig(newConfig: {
|
|
7
|
+
customCss: string[];
|
|
8
|
+
}): void;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
interface StarlightPlugin {
|
|
12
|
+
name: string;
|
|
13
|
+
hooks: {
|
|
14
|
+
setup(options: SetupOptions): void | Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
declare function docsTheme(): StarlightPlugin;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { docsTheme as default, docsTheme };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
const styles = fileURLToPath(new URL("./styles.css", import.meta.url));
|
|
4
|
+
function docsTheme() {
|
|
5
|
+
return {
|
|
6
|
+
name: "@theholocron/docs-theme",
|
|
7
|
+
hooks: { setup({ config, updateConfig }) {
|
|
8
|
+
updateConfig({ customCss: [styles, ...config.customCss ?? []] });
|
|
9
|
+
} }
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { docsTheme as default, docsTheme };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Loader } from "astro/loaders";
|
|
2
|
+
//#region src/loader.d.ts
|
|
3
|
+
type DocsSource = {
|
|
4
|
+
dir: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
} | {
|
|
7
|
+
package: string;
|
|
8
|
+
slug: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Loads Markdown/MDX files from local directories or installed npm content
|
|
12
|
+
* packages into a Starlight docs collection.
|
|
13
|
+
*
|
|
14
|
+
* Each source is either a local directory path or an npm package name whose
|
|
15
|
+
* published `content/` directory will be resolved at build time.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // content.config.ts
|
|
19
|
+
* import { createDocsLoader } from "@theholocron/docs-theme/loader";
|
|
20
|
+
* import { fileURLToPath } from "node:url";
|
|
21
|
+
*
|
|
22
|
+
* export const collections = {
|
|
23
|
+
* docs: defineCollection({
|
|
24
|
+
* loader: createDocsLoader([
|
|
25
|
+
* { dir: fileURLToPath(new URL("content/docs", import.meta.url)), slug: "" },
|
|
26
|
+
* { package: "@theholocron/clients-docs", slug: "projects/clients" },
|
|
27
|
+
* ]),
|
|
28
|
+
* schema: docsSchema(),
|
|
29
|
+
* }),
|
|
30
|
+
* };
|
|
31
|
+
*/
|
|
32
|
+
declare function createDocsLoader(sources: DocsSource[]): Loader;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { DocsSource, createDocsLoader };
|
package/dist/loader.mjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
5
|
+
import { dirname, extname, join, relative } from "node:path";
|
|
6
|
+
import matter from "gray-matter";
|
|
7
|
+
//#region src/loader.ts
|
|
8
|
+
const EXTENSIONS = /* @__PURE__ */ new Set([".md", ".mdx"]);
|
|
9
|
+
async function* walk(dir) {
|
|
10
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
11
|
+
if (entry.name.startsWith("_")) continue;
|
|
12
|
+
const full = join(dir, entry.name);
|
|
13
|
+
if (entry.isDirectory()) yield* walk(full);
|
|
14
|
+
else if (EXTENSIONS.has(extname(entry.name))) yield full;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function computeId(filePath, baseDir, slugPrefix) {
|
|
18
|
+
const noIndex = relative(baseDir, filePath).replace(/\\/g, "/").replace(/\.(mdx?)$/, "").replace(/\/index$/, "").replace(/^index$/, "");
|
|
19
|
+
if (noIndex) return slugPrefix ? `${slugPrefix}/${noIndex}` : noIndex;
|
|
20
|
+
return slugPrefix || "index";
|
|
21
|
+
}
|
|
22
|
+
function resolvePackageContentDir(packageName, root) {
|
|
23
|
+
let dir = dirname(createRequire(root).resolve(packageName));
|
|
24
|
+
while (dir !== dirname(dir)) {
|
|
25
|
+
if (existsSync(join(dir, "package.json"))) return join(dir, "content");
|
|
26
|
+
dir = dirname(dir);
|
|
27
|
+
}
|
|
28
|
+
throw new Error(`Could not resolve content directory for ${packageName}`);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Loads Markdown/MDX files from local directories or installed npm content
|
|
32
|
+
* packages into a Starlight docs collection.
|
|
33
|
+
*
|
|
34
|
+
* Each source is either a local directory path or an npm package name whose
|
|
35
|
+
* published `content/` directory will be resolved at build time.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // content.config.ts
|
|
39
|
+
* import { createDocsLoader } from "@theholocron/docs-theme/loader";
|
|
40
|
+
* import { fileURLToPath } from "node:url";
|
|
41
|
+
*
|
|
42
|
+
* export const collections = {
|
|
43
|
+
* docs: defineCollection({
|
|
44
|
+
* loader: createDocsLoader([
|
|
45
|
+
* { dir: fileURLToPath(new URL("content/docs", import.meta.url)), slug: "" },
|
|
46
|
+
* { package: "@theholocron/clients-docs", slug: "projects/clients" },
|
|
47
|
+
* ]),
|
|
48
|
+
* schema: docsSchema(),
|
|
49
|
+
* }),
|
|
50
|
+
* };
|
|
51
|
+
*/
|
|
52
|
+
function createDocsLoader(sources) {
|
|
53
|
+
return {
|
|
54
|
+
name: "docs-loader",
|
|
55
|
+
async load(ctx) {
|
|
56
|
+
ctx.store.clear();
|
|
57
|
+
const siteRoot = fileURLToPath(ctx.config.root);
|
|
58
|
+
const resolved = sources.map((s) => "package" in s ? {
|
|
59
|
+
dir: resolvePackageContentDir(s.package, ctx.config.root),
|
|
60
|
+
slug: s.slug
|
|
61
|
+
} : s);
|
|
62
|
+
for (const { dir, slug: slugPrefix } of resolved) for await (const absPath of walk(dir)) {
|
|
63
|
+
const id = computeId(absPath, dir, slugPrefix);
|
|
64
|
+
const raw = await readFile(absPath, "utf-8");
|
|
65
|
+
const { data: frontmatter, content: body } = matter(raw);
|
|
66
|
+
const digest = ctx.generateDigest(raw);
|
|
67
|
+
const filePath = relative(siteRoot, absPath);
|
|
68
|
+
const data = await ctx.parseData({
|
|
69
|
+
id,
|
|
70
|
+
data: frontmatter,
|
|
71
|
+
filePath
|
|
72
|
+
});
|
|
73
|
+
const rendered = await ctx.renderMarkdown(body, { fileURL: pathToFileURL(absPath) });
|
|
74
|
+
ctx.store.set({
|
|
75
|
+
id,
|
|
76
|
+
data,
|
|
77
|
+
body,
|
|
78
|
+
filePath,
|
|
79
|
+
digest,
|
|
80
|
+
rendered
|
|
81
|
+
});
|
|
82
|
+
ctx.watcher?.add(absPath);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { createDocsLoader };
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The Holocron — Starlight theme
|
|
3
|
+
*
|
|
4
|
+
* Overrides Starlight CSS custom properties.
|
|
5
|
+
* @see https://starlight.astro.build/guides/css-and-tailwind/
|
|
6
|
+
*
|
|
7
|
+
* Only accent colors are set here. All other values inherit Starlight defaults.
|
|
8
|
+
* Consumer sites may add their own customCss entries after this to override further.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
:root[data-theme="dark"] {
|
|
12
|
+
--sl-color-accent-low: #1d1204;
|
|
13
|
+
--sl-color-accent: #c89b3c;
|
|
14
|
+
--sl-color-accent-high: #f5d07a;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
:root[data-theme="light"] {
|
|
18
|
+
--sl-color-accent-low: #f5e8c8;
|
|
19
|
+
--sl-color-accent: #9b6f2a;
|
|
20
|
+
--sl-color-accent-high: #5c3d0e;
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/docs-theme",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Starlight plugin providing the shared docs theme.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -29,27 +29,36 @@
|
|
|
29
29
|
"types": "./dist/index.d.mts",
|
|
30
30
|
"import": "./dist/index.mjs",
|
|
31
31
|
"default": "./dist/index.mjs"
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
|
+
"./loader": {
|
|
34
|
+
"types": "./dist/loader.d.mts",
|
|
35
|
+
"import": "./dist/loader.mjs",
|
|
36
|
+
"default": "./dist/loader.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./styles.css": "./dist/styles.css"
|
|
33
39
|
},
|
|
34
40
|
"main": "./dist/index.mjs",
|
|
35
41
|
"files": [
|
|
36
42
|
"dist",
|
|
37
43
|
"README.md"
|
|
38
44
|
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"gray-matter": "^4.0.3"
|
|
47
|
+
},
|
|
39
48
|
"devDependencies": {
|
|
40
49
|
"@astrojs/starlight": "^0.41.5",
|
|
41
50
|
"@theholocron/eslint-config": "^7.6.0",
|
|
42
51
|
"@theholocron/tsconfig": "^7.4.1",
|
|
43
52
|
"@theholocron/tsdown-config": "^7.4.1",
|
|
44
53
|
"@theholocron/vitest-config": "^7.4.1",
|
|
45
|
-
"@types/node": "^26.1.
|
|
54
|
+
"@types/node": "^26.1.2",
|
|
46
55
|
"@vitest/coverage-v8": "^4.1.10",
|
|
47
56
|
"@vitest/eslint-plugin": "^1.6.23",
|
|
48
57
|
"astro": "^7.1.5",
|
|
49
58
|
"eslint": "^10.7.0",
|
|
50
59
|
"eslint-plugin-n": "^18.2.2",
|
|
51
60
|
"eslint-plugin-simple-import-sort": "^14.0.0",
|
|
52
|
-
"globals": "^17.
|
|
61
|
+
"globals": "^17.8.0",
|
|
53
62
|
"tsdown": "^0.22.13",
|
|
54
63
|
"typescript": "^5.9.3",
|
|
55
64
|
"vitest": "^4.1.10"
|