starlight-dot-md 0.1.0 → 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/LICENSE +21 -0
- package/README.md +2 -71
- 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 +52 -51
- package/dist/utils-DLGmXZ1G.mjs +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shinya Fujino
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,74 +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
|
-
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install starlight-dot-md
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
// astro.config.mjs
|
|
15
|
-
import starlight from "@astrojs/starlight";
|
|
16
|
-
import { defineConfig } from "astro/config";
|
|
17
|
-
import starlightDotMd from "starlight-dot-md";
|
|
18
|
-
|
|
19
|
-
export default defineConfig({
|
|
20
|
-
integrations: [
|
|
21
|
-
starlight({ ... }),
|
|
22
|
-
starlightDotMd(),
|
|
23
|
-
],
|
|
24
|
-
});
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
After build, access any page's source by appending `.md` to its URL (e.g., `/guides/example.md`).
|
|
28
|
-
|
|
29
|
-
> **Note**: By default, both `.md` and `.mdx` files are served with the `.md` extension. Use the `preserveExtension` option to keep the original extension.
|
|
30
|
-
|
|
31
|
-
## Options
|
|
32
|
-
|
|
33
|
-
### `excludePatterns`
|
|
34
|
-
|
|
35
|
-
An array of glob patterns to exclude pages from being served as `.md` files.
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
starlightDotMd({
|
|
39
|
-
excludePatterns: ["private/**", "**/draft-*"],
|
|
40
|
-
});
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### `includePatterns`
|
|
44
|
-
|
|
45
|
-
An array of glob patterns to include pages for being served as `.md` files. When specified, only pages matching these patterns will be served.
|
|
46
|
-
|
|
47
|
-
```js
|
|
48
|
-
starlightDotMd({
|
|
49
|
-
includePatterns: ["guides/**"],
|
|
50
|
-
});
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
You can use both options together. Pages must match `includePatterns` (if specified) and not match `excludePatterns`.
|
|
54
|
-
|
|
55
|
-
```js
|
|
56
|
-
starlightDotMd({
|
|
57
|
-
includePatterns: ["guides/**"],
|
|
58
|
-
excludePatterns: ["guides/internal/**"],
|
|
59
|
-
});
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### `preserveExtension`
|
|
63
|
-
|
|
64
|
-
When set to `true`, `.mdx` files are served with their original `.mdx` extension instead of being normalized to `.md`.
|
|
65
|
-
|
|
66
|
-
```js
|
|
67
|
-
starlightDotMd({
|
|
68
|
-
preserveExtension: true,
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
With this option enabled:
|
|
73
|
-
- `.md` files are served at `.md` URLs (e.g., `/guides/example.md`)
|
|
74
|
-
- `.mdx` files are served at `.mdx` URLs (e.g., `/index.mdx`)
|
|
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,52 +1,53 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
2
|
+
"name": "starlight-dot-md",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "A Starlight plugin that exposes raw markdown files at `.md` URLs.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"astro",
|
|
7
|
+
"withastro",
|
|
8
|
+
"astro-component",
|
|
9
|
+
"astro-integration",
|
|
10
|
+
"starlight",
|
|
11
|
+
"ai"
|
|
12
|
+
],
|
|
13
|
+
"author": "Shinya Fujino <shf0811@gmail.com> (https://github.com/morinokami)",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/morinokami/starlight-dot-md.git",
|
|
19
|
+
"directory": "packages/starlight-dot-md"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/morinokami/starlight-dot-md/issues"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./dist/index.mjs",
|
|
26
|
+
"./slug.md": "./dist/slug.md.mjs",
|
|
27
|
+
"./slug.mdx": "./dist/slug.mdx.mjs",
|
|
28
|
+
"./slug.mdoc": "./dist/slug.mdoc.mjs"
|
|
29
|
+
},
|
|
30
|
+
"main": "./dist/index.mjs",
|
|
31
|
+
"module": "./dist/index.mjs",
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"picomatch": "4.0.3"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@astrojs/starlight": "0.37.3",
|
|
41
|
+
"@types/node": "25.0.9",
|
|
42
|
+
"@types/picomatch": "4.0.2",
|
|
43
|
+
"astro": "5.16.11",
|
|
44
|
+
"tsdown": "0.18.3",
|
|
45
|
+
"typescript": "5.9.3"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"astro": ">=5.0.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsdown"
|
|
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};
|