starlight-dot-md 0.1.1 → 0.1.2
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 +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +83 -2
- package/dist/slug.md.mjs +26 -1
- package/dist/slug.mdoc.mjs +23 -1
- package/dist/slug.mdx.mjs +23 -1
- package/dist/utils-BJKtrfbz.mjs +22 -0
- package/package.json +6 -5
- package/dist/utils-DLGmXZ1G.mjs +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# starlight-dot-md
|
|
2
2
|
|
|
3
|
-
A Starlight
|
|
3
|
+
A Starlight plugin that exposes raw markdown files at `.md` URLs.
|
|
4
4
|
|
|
5
|
-
For installation, usage, and configuration options, see the [documentation](https://starlight-dot-md.
|
|
5
|
+
For installation, usage, and configuration options, see the [documentation](https://starlight-dot-md.shf0811.workers.dev/).
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StarlightPlugin } from "@astrojs/starlight/types";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
type StarlightDotMdOptions = {
|
|
@@ -8,6 +8,6 @@ type StarlightDotMdOptions = {
|
|
|
8
8
|
};
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/index.d.ts
|
|
11
|
-
declare function starlightDotMd(options?: StarlightDotMdOptions):
|
|
11
|
+
declare function starlightDotMd(options?: StarlightDotMdOptions): StarlightPlugin;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { starlightDotMd as default };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,83 @@
|
|
|
1
|
-
import{readdirSync
|
|
2
|
-
|
|
1
|
+
import { readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { join, relative } from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
function findFilesByExtension(dir, baseDir, extension) {
|
|
6
|
+
const results = [];
|
|
7
|
+
try {
|
|
8
|
+
const entries = readdirSync(dir);
|
|
9
|
+
for (const entry of entries) {
|
|
10
|
+
const fullPath = join(dir, entry);
|
|
11
|
+
if (statSync(fullPath).isDirectory()) results.push(...findFilesByExtension(fullPath, baseDir, extension));
|
|
12
|
+
else if (entry.endsWith(extension)) {
|
|
13
|
+
const relativePath = relative(baseDir, fullPath);
|
|
14
|
+
results.push(relativePath.replace(extension, ""));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
} catch {}
|
|
18
|
+
return results;
|
|
19
|
+
}
|
|
20
|
+
function vitePluginStarlightDotMdContext(context, preserveExtension) {
|
|
21
|
+
const contextModuleId = "virtual:starlight-dot-md/context";
|
|
22
|
+
const resolvedContextModuleId = `\0${contextModuleId}`;
|
|
23
|
+
const filesModuleId = "virtual:starlight-dot-md/files";
|
|
24
|
+
const resolvedFilesModuleId = `\0${filesModuleId}`;
|
|
25
|
+
let root = "";
|
|
26
|
+
return {
|
|
27
|
+
name: "vite-plugin-starlight-dot-md-context",
|
|
28
|
+
configResolved(config) {
|
|
29
|
+
root = config.root;
|
|
30
|
+
},
|
|
31
|
+
resolveId(id) {
|
|
32
|
+
if (id === contextModuleId) return resolvedContextModuleId;
|
|
33
|
+
if (id === filesModuleId) return resolvedFilesModuleId;
|
|
34
|
+
},
|
|
35
|
+
load(id) {
|
|
36
|
+
if (id === resolvedContextModuleId) return `export const context = ${JSON.stringify(context)};`;
|
|
37
|
+
if (id === resolvedFilesModuleId) {
|
|
38
|
+
if (!preserveExtension) return `export const mdocSlugs = new Set();\nexport const mdxSlugs = new Set();`;
|
|
39
|
+
const docsDir = join(root, "src/content/docs");
|
|
40
|
+
const mdxSlugs = findFilesByExtension(docsDir, docsDir, ".mdx");
|
|
41
|
+
const mdocSlugs = findFilesByExtension(docsDir, docsDir, ".mdoc");
|
|
42
|
+
return `export const mdocSlugs = new Set(${JSON.stringify(mdocSlugs)});\nexport const mdxSlugs = new Set(${JSON.stringify(mdxSlugs)});`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function starlightDotMd(options = {}) {
|
|
48
|
+
return {
|
|
49
|
+
name: "starlight-dot-md",
|
|
50
|
+
hooks: { setup({ addIntegration }) {
|
|
51
|
+
addIntegration({
|
|
52
|
+
name: "starlight-dot-md",
|
|
53
|
+
hooks: { "astro:config:setup": ({ injectRoute, updateConfig }) => {
|
|
54
|
+
injectRoute({
|
|
55
|
+
pattern: "/[...slug].md",
|
|
56
|
+
entrypoint: "starlight-dot-md/slug.md",
|
|
57
|
+
prerender: true
|
|
58
|
+
});
|
|
59
|
+
if (options.preserveExtension) {
|
|
60
|
+
injectRoute({
|
|
61
|
+
pattern: "/[...slug].mdx",
|
|
62
|
+
entrypoint: "starlight-dot-md/slug.mdx",
|
|
63
|
+
prerender: true
|
|
64
|
+
});
|
|
65
|
+
injectRoute({
|
|
66
|
+
pattern: "/[...slug].mdoc",
|
|
67
|
+
entrypoint: "starlight-dot-md/slug.mdoc",
|
|
68
|
+
prerender: true
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
updateConfig({ vite: { plugins: [vitePluginStarlightDotMdContext({
|
|
72
|
+
excludePatterns: options.excludePatterns ?? [],
|
|
73
|
+
includePatterns: options.includePatterns ?? [],
|
|
74
|
+
preserveExtension: options.preserveExtension ?? false
|
|
75
|
+
}, options.preserveExtension ?? false)] } });
|
|
76
|
+
} }
|
|
77
|
+
});
|
|
78
|
+
} }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { starlightDotMd as default };
|
package/dist/slug.md.mjs
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
import{i as
|
|
1
|
+
import { i as isMdx, n as isIncluded, r as isMdoc, t as isExcluded } from "./utils-BJKtrfbz.mjs";
|
|
2
|
+
import { getCollection, getEntry } from "astro:content";
|
|
3
|
+
import { context } from "virtual:starlight-dot-md/context";
|
|
4
|
+
|
|
5
|
+
//#region src/slug.md.ts
|
|
6
|
+
function shouldServe(slug) {
|
|
7
|
+
if (!isIncluded(slug) || isExcluded(slug)) return false;
|
|
8
|
+
if (context.preserveExtension && (isMdx(slug) || isMdoc(slug))) return false;
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
const getStaticPaths = async () => {
|
|
12
|
+
return (await getCollection("docs")).filter((entry) => shouldServe(entry.id)).map((entry) => ({ params: { slug: entry.id } }));
|
|
13
|
+
};
|
|
14
|
+
const GET = async ({ params }) => {
|
|
15
|
+
const slug = params.slug;
|
|
16
|
+
if (!slug || !shouldServe(slug)) return new Response("Not found", { status: 404 });
|
|
17
|
+
const entry = await getEntry("docs", slug);
|
|
18
|
+
if (!entry) return new Response("Not found", { status: 404 });
|
|
19
|
+
return new Response(entry.body, {
|
|
20
|
+
status: 200,
|
|
21
|
+
headers: { "Content-Type": "text/markdown; charset=utf-8" }
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { GET, getStaticPaths };
|
package/dist/slug.mdoc.mjs
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
import{n as
|
|
1
|
+
import { n as isIncluded, r as isMdoc, t as isExcluded } from "./utils-BJKtrfbz.mjs";
|
|
2
|
+
import { getCollection, getEntry } from "astro:content";
|
|
3
|
+
|
|
4
|
+
//#region src/slug.mdoc.ts
|
|
5
|
+
function shouldServe(slug) {
|
|
6
|
+
return isMdoc(slug) && isIncluded(slug) && !isExcluded(slug);
|
|
7
|
+
}
|
|
8
|
+
const getStaticPaths = async () => {
|
|
9
|
+
return (await getCollection("docs")).filter((entry) => shouldServe(entry.id)).map((entry) => ({ params: { slug: entry.id } }));
|
|
10
|
+
};
|
|
11
|
+
const GET = async ({ params }) => {
|
|
12
|
+
const slug = params.slug;
|
|
13
|
+
if (!slug || !shouldServe(slug)) return new Response("Not found", { status: 404 });
|
|
14
|
+
const entry = await getEntry("docs", slug);
|
|
15
|
+
if (!entry) return new Response("Not found", { status: 404 });
|
|
16
|
+
return new Response(entry.body, {
|
|
17
|
+
status: 200,
|
|
18
|
+
headers: { "Content-Type": "text/markdown; charset=utf-8" }
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { GET, getStaticPaths };
|
package/dist/slug.mdx.mjs
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
import{i as
|
|
1
|
+
import { i as isMdx, n as isIncluded, t as isExcluded } from "./utils-BJKtrfbz.mjs";
|
|
2
|
+
import { getCollection, getEntry } from "astro:content";
|
|
3
|
+
|
|
4
|
+
//#region src/slug.mdx.ts
|
|
5
|
+
function shouldServe(slug) {
|
|
6
|
+
return isMdx(slug) && isIncluded(slug) && !isExcluded(slug);
|
|
7
|
+
}
|
|
8
|
+
const getStaticPaths = async () => {
|
|
9
|
+
return (await getCollection("docs")).filter((entry) => shouldServe(entry.id)).map((entry) => ({ params: { slug: entry.id } }));
|
|
10
|
+
};
|
|
11
|
+
const GET = async ({ params }) => {
|
|
12
|
+
const slug = params.slug;
|
|
13
|
+
if (!slug || !shouldServe(slug)) return new Response("Not found", { status: 404 });
|
|
14
|
+
const entry = await getEntry("docs", slug);
|
|
15
|
+
if (!entry) return new Response("Not found", { status: 404 });
|
|
16
|
+
return new Response(entry.body, {
|
|
17
|
+
status: 200,
|
|
18
|
+
headers: { "Content-Type": "text/markdown; charset=utf-8" }
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { GET, getStaticPaths };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { context } from "virtual:starlight-dot-md/context";
|
|
2
|
+
import { mdocSlugs, mdxSlugs } from "virtual:starlight-dot-md/files";
|
|
3
|
+
import picomatch from "picomatch";
|
|
4
|
+
|
|
5
|
+
//#region src/utils.ts
|
|
6
|
+
function isMdx(slug) {
|
|
7
|
+
return mdxSlugs.has(slug);
|
|
8
|
+
}
|
|
9
|
+
function isMdoc(slug) {
|
|
10
|
+
return mdocSlugs.has(slug);
|
|
11
|
+
}
|
|
12
|
+
function isExcluded(slug) {
|
|
13
|
+
if (!context.excludePatterns || context.excludePatterns.length === 0) return false;
|
|
14
|
+
return picomatch.isMatch(slug, context.excludePatterns);
|
|
15
|
+
}
|
|
16
|
+
function isIncluded(slug) {
|
|
17
|
+
if (!context.includePatterns || context.includePatterns.length === 0) return true;
|
|
18
|
+
return picomatch.isMatch(slug, context.includePatterns);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { isMdx as i, isIncluded as n, isMdoc as r, isExcluded as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-dot-md",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "A Starlight
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "A Starlight plugin that exposes raw markdown files at `.md` URLs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
7
7
|
"withastro",
|
|
@@ -37,8 +37,10 @@
|
|
|
37
37
|
"picomatch": "4.0.3"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
+
"@astrojs/starlight": "0.37.3",
|
|
41
|
+
"@types/node": "25.0.9",
|
|
40
42
|
"@types/picomatch": "4.0.2",
|
|
41
|
-
"astro": "5.16.
|
|
43
|
+
"astro": "5.16.11",
|
|
42
44
|
"tsdown": "0.18.3",
|
|
43
45
|
"typescript": "5.9.3"
|
|
44
46
|
},
|
|
@@ -46,7 +48,6 @@
|
|
|
46
48
|
"astro": ">=5.0.0"
|
|
47
49
|
},
|
|
48
50
|
"scripts": {
|
|
49
|
-
"build": "tsdown"
|
|
50
|
-
"typecheck": "tsc --noEmit"
|
|
51
|
+
"build": "tsdown"
|
|
51
52
|
}
|
|
52
53
|
}
|
package/dist/utils-DLGmXZ1G.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{context as e}from"virtual:starlight-dot-md/context";import{mdocSlugs as t,mdxSlugs as n}from"virtual:starlight-dot-md/files";import r from"picomatch";function i(e){return n.has(e)}function a(e){return t.has(e)}function o(t){return!e.excludePatterns||e.excludePatterns.length===0?!1:r.isMatch(t,e.excludePatterns)}function s(t){return!e.includePatterns||e.includePatterns.length===0?!0:r.isMatch(t,e.includePatterns)}export{i,s as n,a as r,o as t};
|