@docspack/sheaf-astro 0.0.1
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 +33 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/render.d.ts +43 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +26 -0
- package/dist/render.js.map +1 -0
- package/package.json +56 -0
- package/src/index.ts +6 -0
- package/src/render.ts +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 docspack contributors
|
|
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
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @docspack/sheaf-astro
|
|
2
|
+
|
|
3
|
+
Renders a [Sheaf](../sheaf) content graph with Astro's own Markdown pipeline.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { graphFromSources } from "@docspack/sheaf";
|
|
7
|
+
import { createPageRenderer } from "@docspack/sheaf-astro";
|
|
8
|
+
|
|
9
|
+
const renderPage = createPageRenderer({ syntaxHighlight: false });
|
|
10
|
+
|
|
11
|
+
const { html, headings } = await renderPage(page);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Why a binding rather than a renderer
|
|
15
|
+
|
|
16
|
+
`createPageRenderer` wraps `@astrojs/markdown-remark` — the same processor Astro uses for a
|
|
17
|
+
`.md` file in `src/pages`. Your Markdown configuration keeps applying, and a document reaches
|
|
18
|
+
a reader through one pipeline whichever route served it.
|
|
19
|
+
|
|
20
|
+
## The part that matters
|
|
21
|
+
|
|
22
|
+
A table of contents is built from the graph's heading slugs; the anchors it links to are the
|
|
23
|
+
`id`s this renderer stamps. When those disagree the failure is silent — the browser scrolls to
|
|
24
|
+
the top instead of erroring. This package asserts they agree for every page it renders.
|
|
25
|
+
|
|
26
|
+
## Options
|
|
27
|
+
|
|
28
|
+
| | |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| `syntaxHighlight` | `false`, `"shiki"` or `"prism"`. Turn it off if your site paints its own code blocks. |
|
|
31
|
+
| `gfm` | GitHub-flavoured Markdown. On by default. |
|
|
32
|
+
|
|
33
|
+
MIT © docspack
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAInB,MAAM,aAAa,CAAC"}
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Heading, Page } from "@docspack/sheaf";
|
|
2
|
+
/**
|
|
3
|
+
* Rendering a graph's pages with Astro's own Markdown pipeline.
|
|
4
|
+
*
|
|
5
|
+
* This is the layer that owns rendering, and it is deliberately the *host's* renderer rather
|
|
6
|
+
* than one of ours: it is the same processor that renders a `.md` file in `src/pages`, so a
|
|
7
|
+
* document reaches a reader through one pipeline no matter which route served it. Sheaf's
|
|
8
|
+
* graph carries no HTML precisely so this choice stays the host's.
|
|
9
|
+
*
|
|
10
|
+
* The seam this package is responsible for is heading ids. The graph's slugs drive a table of
|
|
11
|
+
* contents; the ids in this HTML are what a browser scrolls to. They are produced by different
|
|
12
|
+
* code, and a mismatch fails silently — a bad fragment scrolls to the top rather than erroring.
|
|
13
|
+
* `tests/render.test.ts` asserts they agree for the whole corpus.
|
|
14
|
+
*/
|
|
15
|
+
export interface RenderedPage {
|
|
16
|
+
readonly html: string;
|
|
17
|
+
/**
|
|
18
|
+
* The headings the renderer found, which is what actually got an `id`.
|
|
19
|
+
*
|
|
20
|
+
* Prefer the graph's `page.headings` for a table of contents — it is available without
|
|
21
|
+
* rendering. This is here so a caller can assert the two agree, and so a host that wants the
|
|
22
|
+
* renderer's typographic text (`It’s` rather than `It's`) can reach it.
|
|
23
|
+
*/
|
|
24
|
+
readonly headings: readonly Heading[];
|
|
25
|
+
}
|
|
26
|
+
/** Options passed through to Astro's processor. */
|
|
27
|
+
export interface RendererOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Astro highlights code by default. A site that paints its own code-block style should turn
|
|
30
|
+
* this off, or it ships a second theme's colours over the top of its own.
|
|
31
|
+
*/
|
|
32
|
+
readonly syntaxHighlight?: false | "shiki" | "prism";
|
|
33
|
+
readonly gfm?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export type PageRenderer = (page: Page) => Promise<RenderedPage>;
|
|
36
|
+
/**
|
|
37
|
+
* Builds one processor and returns a function that renders pages with it.
|
|
38
|
+
*
|
|
39
|
+
* Building a processor compiles a plugin pipeline, which is slow enough that doing it per page
|
|
40
|
+
* is noticeable on a corpus of any size — so it is built once, lazily, and shared.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createPageRenderer(options?: RendererOptions): PageRenderer;
|
|
43
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;CACvC;AAED,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC;IACrD,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,eAAoB,GAAG,YAAY,CAoB9E"}
|
package/dist/render.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createMarkdownProcessor } from "@astrojs/markdown-remark";
|
|
2
|
+
/**
|
|
3
|
+
* Builds one processor and returns a function that renders pages with it.
|
|
4
|
+
*
|
|
5
|
+
* Building a processor compiles a plugin pipeline, which is slow enough that doing it per page
|
|
6
|
+
* is noticeable on a corpus of any size — so it is built once, lazily, and shared.
|
|
7
|
+
*/
|
|
8
|
+
export function createPageRenderer(options = {}) {
|
|
9
|
+
let pending;
|
|
10
|
+
const renderer = () => {
|
|
11
|
+
pending ??= createMarkdownProcessor({
|
|
12
|
+
gfm: options.gfm ?? true,
|
|
13
|
+
...(options.syntaxHighlight === undefined
|
|
14
|
+
? {}
|
|
15
|
+
: { syntaxHighlight: options.syntaxHighlight }),
|
|
16
|
+
});
|
|
17
|
+
return pending;
|
|
18
|
+
};
|
|
19
|
+
return async (page) => {
|
|
20
|
+
// `page.content` rather than `page.body`: the shell renders the title itself, and a second
|
|
21
|
+
// `<h1>` from the body would be a duplicate in the document outline.
|
|
22
|
+
const { code, metadata } = await (await renderer()).render(page.content);
|
|
23
|
+
return { html: code, headings: metadata.headings };
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAyB,MAAM,0BAA0B,CAAC;AAyC1F;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAA2B,EAAE;IAC9D,IAAI,OAA8C,CAAC;IAEnD,MAAM,QAAQ,GAAG,GAA8B,EAAE;QAC/C,OAAO,KAAK,uBAAuB,CAAC;YAClC,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,IAAI;YACxB,GAAG,CAAC,OAAO,CAAC,eAAe,KAAK,SAAS;gBACvC,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,eAAe,EAAE,OAAO,CAAC,eAAe,EAAE,CAAC;SAClD,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAEF,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;QACpB,2FAA2F;QAC3F,qEAAqE;QACrE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,MAAM,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEzE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@docspack/sheaf-astro",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Renders a Sheaf content graph with Astro's own Markdown pipeline, so a docs site and its agent index come from one parse.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=22.5.0"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/docspack/docspack.git",
|
|
27
|
+
"directory": "packages/sheaf-astro"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@astrojs/markdown-remark": "7.2.0",
|
|
31
|
+
"@docspack/sheaf": "^0.0.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "26.2.0",
|
|
35
|
+
"typescript": "6.0.3",
|
|
36
|
+
"vitest": "4.1.10",
|
|
37
|
+
"@docspack/config": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"sheaf",
|
|
44
|
+
"docspack",
|
|
45
|
+
"astro",
|
|
46
|
+
"documentation",
|
|
47
|
+
"markdown"
|
|
48
|
+
],
|
|
49
|
+
"homepage": "https://docspack.dev",
|
|
50
|
+
"bugs": "https://github.com/docspack/docspack/issues",
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsc -p tsconfig.json",
|
|
53
|
+
"check-types": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json",
|
|
54
|
+
"test": "vitest run"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/index.ts
ADDED
package/src/render.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createMarkdownProcessor, type MarkdownRenderer } from "@astrojs/markdown-remark";
|
|
2
|
+
import type { Heading, Page } from "@docspack/sheaf";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Rendering a graph's pages with Astro's own Markdown pipeline.
|
|
6
|
+
*
|
|
7
|
+
* This is the layer that owns rendering, and it is deliberately the *host's* renderer rather
|
|
8
|
+
* than one of ours: it is the same processor that renders a `.md` file in `src/pages`, so a
|
|
9
|
+
* document reaches a reader through one pipeline no matter which route served it. Sheaf's
|
|
10
|
+
* graph carries no HTML precisely so this choice stays the host's.
|
|
11
|
+
*
|
|
12
|
+
* The seam this package is responsible for is heading ids. The graph's slugs drive a table of
|
|
13
|
+
* contents; the ids in this HTML are what a browser scrolls to. They are produced by different
|
|
14
|
+
* code, and a mismatch fails silently — a bad fragment scrolls to the top rather than erroring.
|
|
15
|
+
* `tests/render.test.ts` asserts they agree for the whole corpus.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export interface RenderedPage {
|
|
19
|
+
readonly html: string;
|
|
20
|
+
/**
|
|
21
|
+
* The headings the renderer found, which is what actually got an `id`.
|
|
22
|
+
*
|
|
23
|
+
* Prefer the graph's `page.headings` for a table of contents — it is available without
|
|
24
|
+
* rendering. This is here so a caller can assert the two agree, and so a host that wants the
|
|
25
|
+
* renderer's typographic text (`It’s` rather than `It's`) can reach it.
|
|
26
|
+
*/
|
|
27
|
+
readonly headings: readonly Heading[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Options passed through to Astro's processor. */
|
|
31
|
+
export interface RendererOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Astro highlights code by default. A site that paints its own code-block style should turn
|
|
34
|
+
* this off, or it ships a second theme's colours over the top of its own.
|
|
35
|
+
*/
|
|
36
|
+
readonly syntaxHighlight?: false | "shiki" | "prism";
|
|
37
|
+
readonly gfm?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type PageRenderer = (page: Page) => Promise<RenderedPage>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Builds one processor and returns a function that renders pages with it.
|
|
44
|
+
*
|
|
45
|
+
* Building a processor compiles a plugin pipeline, which is slow enough that doing it per page
|
|
46
|
+
* is noticeable on a corpus of any size — so it is built once, lazily, and shared.
|
|
47
|
+
*/
|
|
48
|
+
export function createPageRenderer(options: RendererOptions = {}): PageRenderer {
|
|
49
|
+
let pending: Promise<MarkdownRenderer> | undefined;
|
|
50
|
+
|
|
51
|
+
const renderer = (): Promise<MarkdownRenderer> => {
|
|
52
|
+
pending ??= createMarkdownProcessor({
|
|
53
|
+
gfm: options.gfm ?? true,
|
|
54
|
+
...(options.syntaxHighlight === undefined
|
|
55
|
+
? {}
|
|
56
|
+
: { syntaxHighlight: options.syntaxHighlight }),
|
|
57
|
+
});
|
|
58
|
+
return pending;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return async (page) => {
|
|
62
|
+
// `page.content` rather than `page.body`: the shell renders the title itself, and a second
|
|
63
|
+
// `<h1>` from the body would be a duplicate in the document outline.
|
|
64
|
+
const { code, metadata } = await (await renderer()).render(page.content);
|
|
65
|
+
|
|
66
|
+
return { html: code, headings: metadata.headings };
|
|
67
|
+
};
|
|
68
|
+
}
|