starlight-dot-md 0.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 +74 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.mjs +2 -0
- package/dist/slug.md.d.mts +7 -0
- package/dist/slug.md.mjs +1 -0
- package/dist/slug.mdoc.d.mts +7 -0
- package/dist/slug.mdoc.mjs +1 -0
- package/dist/slug.mdx.d.mts +7 -0
- package/dist/slug.mdx.mjs +1 -0
- package/dist/utils-DLGmXZ1G.mjs +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# starlight-dot-md
|
|
2
|
+
|
|
3
|
+
A Starlight integration that exposes raw markdown files at `.md` URLs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
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`)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AstroIntegration } from "astro";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type StarlightDotMdOptions = {
|
|
5
|
+
excludePatterns?: string[];
|
|
6
|
+
includePatterns?: string[];
|
|
7
|
+
preserveExtension?: boolean;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/index.d.ts
|
|
11
|
+
declare function starlightDotMd(options?: StarlightDotMdOptions): AstroIntegration;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { starlightDotMd as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{readdirSync as e,statSync as t}from"node:fs";import{join as n,relative as r}from"node:path";function i(a,o,s){let c=[];try{let l=e(a);for(let e of l){let l=n(a,e);if(t(l).isDirectory())c.push(...i(l,o,s));else if(e.endsWith(s)){let e=r(o,l);c.push(e.replace(s,``))}}}catch{}return c}function a(e,t){let r=`virtual:starlight-dot-md/context`,a=`\0${r}`,o=`virtual:starlight-dot-md/files`,s=`\0${o}`,c=``;return{name:`vite-plugin-starlight-dot-md-context`,configResolved(e){c=e.root},resolveId(e){if(e===r)return a;if(e===o)return s},load(r){if(r===a)return`export const context = ${JSON.stringify(e)};`;if(r===s){if(!t)return`export const mdocSlugs = new Set();
|
|
2
|
+
export const mdxSlugs = new Set();`;let e=n(c,`src/content/docs`),r=i(e,e,`.mdx`),a=i(e,e,`.mdoc`);return`export const mdocSlugs = new Set(${JSON.stringify(a)});\nexport const mdxSlugs = new Set(${JSON.stringify(r)});`}}}}function o(e={}){return{name:`starlight-dot-md`,hooks:{"astro:config:setup":({injectRoute:t,updateConfig:n})=>{t({pattern:`/[...slug].md`,entrypoint:`starlight-dot-md/slug.md`,prerender:!0}),e.preserveExtension&&(t({pattern:`/[...slug].mdx`,entrypoint:`starlight-dot-md/slug.mdx`,prerender:!0}),t({pattern:`/[...slug].mdoc`,entrypoint:`starlight-dot-md/slug.mdoc`,prerender:!0})),n({vite:{plugins:[a({excludePatterns:e.excludePatterns??[],includePatterns:e.includePatterns??[],preserveExtension:e.preserveExtension??!1},e.preserveExtension??!1)]}})}}}}export{o as default};
|
package/dist/slug.md.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./utils-DLGmXZ1G.mjs";import{getCollection as i,getEntry as a}from"astro:content";import{context as o}from"virtual:starlight-dot-md/context";function s(i){return!(!t(i)||r(i)||o.preserveExtension&&(e(i)||n(i)))}const c=async()=>(await i(`docs`)).filter(e=>s(e.id)).map(e=>({params:{slug:e.id}})),l=async({params:e})=>{let t=e.slug;if(!t||!s(t))return new Response(`Not found`,{status:404});let n=await a(`docs`,t);return n?new Response(n.body,{status:200,headers:{"Content-Type":`text/markdown; charset=utf-8`}}):new Response(`Not found`,{status:404})};export{l as GET,c as getStaticPaths};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,r as t,t as n}from"./utils-DLGmXZ1G.mjs";import{getCollection as r,getEntry as i}from"astro:content";function a(r){return t(r)&&e(r)&&!n(r)}const o=async()=>(await r(`docs`)).filter(e=>a(e.id)).map(e=>({params:{slug:e.id}})),s=async({params:e})=>{let t=e.slug;if(!t||!a(t))return new Response(`Not found`,{status:404});let n=await i(`docs`,t);return n?new Response(n.body,{status:200,headers:{"Content-Type":`text/markdown; charset=utf-8`}}):new Response(`Not found`,{status:404})};export{s as GET,o as getStaticPaths};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e,n as t,t as n}from"./utils-DLGmXZ1G.mjs";import{getCollection as r,getEntry as i}from"astro:content";function a(r){return e(r)&&t(r)&&!n(r)}const o=async()=>(await r(`docs`)).filter(e=>a(e.id)).map(e=>({params:{slug:e.id}})),s=async({params:e})=>{let t=e.slug;if(!t||!a(t))return new Response(`Not found`,{status:404});let n=await i(`docs`,t);return n?new Response(n.body,{status:200,headers:{"Content-Type":`text/markdown; charset=utf-8`}}):new Response(`Not found`,{status:404})};export{s as GET,o as getStaticPaths};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "starlight-dot-md",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A Starlight integration 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
|
+
"scripts": {
|
|
37
|
+
"build": "tsdown",
|
|
38
|
+
"typecheck": "tsc --noEmit"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"picomatch": "catalog:"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/picomatch": "catalog:",
|
|
45
|
+
"astro": "catalog:",
|
|
46
|
+
"tsdown": "catalog:",
|
|
47
|
+
"typescript": "catalog:"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"astro": ">=5.0.0"
|
|
51
|
+
}
|
|
52
|
+
}
|