@aerobuilt/content 0.2.6 → 0.2.8
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/dist/chunk-3GJWVG5N.js +52 -0
- package/dist/{chunk-3IPQCQIC.js → chunk-VZVJXSM5.js} +5 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/markdown.d.ts +4 -2
- package/dist/markdown.js +5 -4
- package/dist/processor.d.ts +60 -0
- package/dist/processor.js +10 -0
- package/dist/render.d.ts +4 -2
- package/dist/render.js +2 -1
- package/dist/{types-VPBJNne0.d.ts → types-D4g4HdAa.d.ts} +27 -3
- package/dist/vite.js +6 -1
- package/package.json +11 -3
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/processor.ts
|
|
2
|
+
import { remark } from "remark";
|
|
3
|
+
import remarkRehype from "remark-rehype";
|
|
4
|
+
import rehypeStringify from "rehype-stringify";
|
|
5
|
+
if (!globalThis.__aeroProcessorState) {
|
|
6
|
+
globalThis.__aeroProcessorState = {
|
|
7
|
+
processor: null,
|
|
8
|
+
initialized: false
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function applyPlugins(pipeline, plugins) {
|
|
12
|
+
for (const entry of plugins) {
|
|
13
|
+
if (Array.isArray(entry)) {
|
|
14
|
+
const [plugin, ...options] = entry;
|
|
15
|
+
pipeline = pipeline.use(plugin, ...options);
|
|
16
|
+
} else {
|
|
17
|
+
pipeline = pipeline.use(entry);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return pipeline;
|
|
21
|
+
}
|
|
22
|
+
function createProcessor(remarkPlugins = [], rehypePlugins = []) {
|
|
23
|
+
let pipeline = remark();
|
|
24
|
+
pipeline = applyPlugins(pipeline, remarkPlugins);
|
|
25
|
+
pipeline = pipeline.use(remarkRehype);
|
|
26
|
+
pipeline = applyPlugins(pipeline, rehypePlugins);
|
|
27
|
+
return pipeline.use(rehypeStringify);
|
|
28
|
+
}
|
|
29
|
+
async function initProcessor(config) {
|
|
30
|
+
globalThis.__aeroProcessorState.processor = createProcessor(
|
|
31
|
+
config?.remarkPlugins ?? [],
|
|
32
|
+
config?.rehypePlugins ?? []
|
|
33
|
+
);
|
|
34
|
+
globalThis.__aeroProcessorState.initialized = true;
|
|
35
|
+
}
|
|
36
|
+
function getProcessor() {
|
|
37
|
+
if (!globalThis.__aeroProcessorState.processor) {
|
|
38
|
+
globalThis.__aeroProcessorState.processor = createProcessor();
|
|
39
|
+
globalThis.__aeroProcessorState.initialized = true;
|
|
40
|
+
}
|
|
41
|
+
return globalThis.__aeroProcessorState.processor;
|
|
42
|
+
}
|
|
43
|
+
function resetProcessor() {
|
|
44
|
+
globalThis.__aeroProcessorState.processor = null;
|
|
45
|
+
globalThis.__aeroProcessorState.initialized = false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
initProcessor,
|
|
50
|
+
getProcessor,
|
|
51
|
+
resetProcessor
|
|
52
|
+
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getProcessor
|
|
3
|
+
} from "./chunk-3GJWVG5N.js";
|
|
4
|
+
|
|
1
5
|
// src/render.ts
|
|
2
|
-
import { remark } from "remark";
|
|
3
|
-
import remarkHtml from "remark-html";
|
|
4
|
-
var processor = remark().use(remarkHtml);
|
|
5
6
|
async function render(doc) {
|
|
6
7
|
if (!doc) {
|
|
7
8
|
console.warn("[aero] render() received null or undefined document. Returning empty HTML.");
|
|
8
9
|
return { html: "" };
|
|
9
10
|
}
|
|
10
|
-
const result = await
|
|
11
|
+
const result = await getProcessor().process(doc.body);
|
|
11
12
|
return { html: String(result) };
|
|
12
13
|
}
|
|
13
14
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { a as ContentCollectionConfig, b as ContentConfig, C as ContentDocument, c as ContentMeta, d as defineCollection, e as defineConfig } from './types-
|
|
1
|
+
export { a as ContentCollectionConfig, b as ContentConfig, C as ContentDocument, c as ContentMeta, M as MarkdownConfig, d as defineCollection, e as defineConfig } from './types-D4g4HdAa.js';
|
|
2
2
|
export { render } from './render.js';
|
|
3
|
+
import 'unified';
|
|
3
4
|
import 'zod';
|
package/dist/index.js
CHANGED
package/dist/markdown.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { C as ContentDocument } from './types-
|
|
1
|
+
import { C as ContentDocument } from './types-D4g4HdAa.js';
|
|
2
|
+
import 'unified';
|
|
2
3
|
import 'zod';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Eager markdown-to-HTML compilation for use in collection transforms.
|
|
6
7
|
*
|
|
7
8
|
* @remarks
|
|
8
|
-
*
|
|
9
|
+
* Delegates to the shared processor from `./processor`. For lazy rendering in pages,
|
|
10
|
+
* use `render()` from `aero:content` instead.
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
13
|
/**
|
package/dist/markdown.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getProcessor
|
|
3
|
+
} from "./chunk-3GJWVG5N.js";
|
|
4
|
+
|
|
1
5
|
// src/markdown.ts
|
|
2
|
-
import { remark } from "remark";
|
|
3
|
-
import remarkHtml from "remark-html";
|
|
4
|
-
var processor = remark().use(remarkHtml);
|
|
5
6
|
async function compileMarkdown(document) {
|
|
6
|
-
const result = await
|
|
7
|
+
const result = await getProcessor().process(document.body);
|
|
7
8
|
return String(result);
|
|
8
9
|
}
|
|
9
10
|
export {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Processor } from 'unified';
|
|
2
|
+
import { M as MarkdownConfig } from './types-D4g4HdAa.js';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Shared markdown processor: unified rehype pipeline with pluggable remark and rehype plugins.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Both `compileMarkdown` (eager, for transforms) and `render` (lazy, for pages) delegate to
|
|
10
|
+
* this module. Call `initProcessor(config)` once at startup (from the Vite plugin) to
|
|
11
|
+
* configure the pipeline. The pipeline is always rehype-based:
|
|
12
|
+
*
|
|
13
|
+
* `remark` -> `[remarkPlugins]` -> `remark-rehype` -> `[rehypePlugins]` -> `rehype-stringify`
|
|
14
|
+
*
|
|
15
|
+
* The processor is created lazily on first use if `initProcessor` was never called.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Processor config: remark and rehype plugin arrays.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Mirrors the `markdown` slice of `ContentConfig` so that the processor does not
|
|
23
|
+
* depend on the full config shape.
|
|
24
|
+
*/
|
|
25
|
+
type ProcessorConfig = MarkdownConfig;
|
|
26
|
+
declare global {
|
|
27
|
+
var __aeroProcessorState: {
|
|
28
|
+
processor: Processor | null;
|
|
29
|
+
initialized: boolean;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Initialize the shared markdown processor.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* Call once at startup (typically from the Vite plugin's configResolved hook) before any
|
|
37
|
+
* markdown compilation occurs. Pass remark/rehype plugins to extend the pipeline (e.g.
|
|
38
|
+
* add `@shikijs/rehype` or `rehype-pretty-code` for syntax highlighting).
|
|
39
|
+
*
|
|
40
|
+
* Safe to call multiple times — subsequent calls replace the processor.
|
|
41
|
+
*
|
|
42
|
+
* @param config - Optional markdown plugin configuration.
|
|
43
|
+
*/
|
|
44
|
+
declare function initProcessor(config?: ProcessorConfig): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Get the shared markdown processor.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* Returns the processor created by `initProcessor`. If `initProcessor` was never called,
|
|
50
|
+
* lazily creates a default processor (no plugins).
|
|
51
|
+
*
|
|
52
|
+
* @returns The unified processor instance.
|
|
53
|
+
*/
|
|
54
|
+
declare function getProcessor(): Processor;
|
|
55
|
+
/**
|
|
56
|
+
* Reset the processor state. Intended for testing only.
|
|
57
|
+
*/
|
|
58
|
+
declare function resetProcessor(): void;
|
|
59
|
+
|
|
60
|
+
export { type ProcessorConfig, getProcessor, initProcessor, resetProcessor };
|
package/dist/render.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { C as ContentDocument } from './types-
|
|
1
|
+
import { C as ContentDocument } from './types-D4g4HdAa.js';
|
|
2
|
+
import 'unified';
|
|
2
3
|
import 'zod';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Lazy markdown-to-HTML for use in pages (import from `aero:content`).
|
|
6
7
|
*
|
|
7
8
|
* @remarks
|
|
8
|
-
*
|
|
9
|
+
* Delegates to the shared processor from `./processor`. Call from on:build with a document
|
|
10
|
+
* (e.g. from getCollection); returns `{ html }`.
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
13
|
/**
|
package/dist/render.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Pluggable } from 'unified';
|
|
1
2
|
import { ZodType } from 'zod';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -42,9 +43,32 @@ interface ContentCollectionConfig<TSchema extends Record<string, any> = Record<s
|
|
|
42
43
|
/** Optional async transform after validation; receives document, returns final shape. */
|
|
43
44
|
transform?: (document: ContentDocument<TSchema>) => TOutput | Promise<TOutput>;
|
|
44
45
|
}
|
|
45
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Markdown pipeline configuration: custom remark and rehype plugins.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* The pipeline is: `remark` -> `[remarkPlugins]` -> `remark-rehype` -> `[rehypePlugins]` -> `rehype-stringify`.
|
|
51
|
+
* Add syntax highlighting (e.g. `@shikijs/rehype`, `rehype-pretty-code`) as a rehype plugin.
|
|
52
|
+
*/
|
|
53
|
+
interface MarkdownConfig {
|
|
54
|
+
/** Remark plugins to apply before the remark-to-rehype bridge. */
|
|
55
|
+
remarkPlugins?: Pluggable[];
|
|
56
|
+
/** Rehype plugins to apply after remark-rehype and before rehype-stringify. */
|
|
57
|
+
rehypePlugins?: Pluggable[];
|
|
58
|
+
}
|
|
59
|
+
/** Top-level content config: array of collection definitions with optional markdown pipeline plugins. */
|
|
46
60
|
interface ContentConfig {
|
|
47
61
|
collections: ContentCollectionConfig<any, any>[];
|
|
62
|
+
/**
|
|
63
|
+
* Custom remark and rehype plugins for the markdown pipeline.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* The pipeline is always rehype-based:
|
|
67
|
+
* `remark` -> `[remarkPlugins]` -> `remark-rehype` -> `[rehypePlugins]` -> `rehype-stringify`.
|
|
68
|
+
* Without any rehype plugins, code blocks render as plain `<pre><code>`.
|
|
69
|
+
* Add `@shikijs/rehype` or `rehype-pretty-code` as a rehype plugin for syntax highlighting.
|
|
70
|
+
*/
|
|
71
|
+
markdown?: MarkdownConfig;
|
|
48
72
|
}
|
|
49
73
|
/**
|
|
50
74
|
* Define a content collection (typed helper for content.config.ts).
|
|
@@ -56,9 +80,9 @@ declare function defineCollection<TSchema extends Record<string, any> = Record<s
|
|
|
56
80
|
/**
|
|
57
81
|
* Define the content config (typed helper for content.config.ts).
|
|
58
82
|
*
|
|
59
|
-
* @param config - Config with `collections` array.
|
|
83
|
+
* @param config - Config with `collections` array and optional `markdown` pipeline plugins.
|
|
60
84
|
* @returns The same config (unchanged).
|
|
61
85
|
*/
|
|
62
86
|
declare function defineConfig(config: ContentConfig): ContentConfig;
|
|
63
87
|
|
|
64
|
-
export { type ContentDocument as C, type ContentCollectionConfig as a, type ContentConfig as b, type ContentMeta as c, defineCollection as d, defineConfig as e };
|
|
88
|
+
export { type ContentDocument as C, type MarkdownConfig as M, type ContentCollectionConfig as a, type ContentConfig as b, type ContentMeta as c, defineCollection as d, defineConfig as e };
|
package/dist/vite.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
initProcessor
|
|
3
|
+
} from "./chunk-3GJWVG5N.js";
|
|
4
|
+
|
|
1
5
|
// src/loader.ts
|
|
2
6
|
import fg from "fast-glob";
|
|
3
7
|
import matter from "gray-matter";
|
|
@@ -96,7 +100,7 @@ function aeroContent(options = {}) {
|
|
|
96
100
|
let watchedDirs = [];
|
|
97
101
|
return {
|
|
98
102
|
name: "vite-plugin-aero-content",
|
|
99
|
-
/** Load content.config.ts, set contentConfig and watchedDirs;
|
|
103
|
+
/** Load content.config.ts, set contentConfig and watchedDirs; initialize processor early. */
|
|
100
104
|
async configResolved(config) {
|
|
101
105
|
resolvedConfig = config;
|
|
102
106
|
const root = config.root;
|
|
@@ -109,6 +113,7 @@ function aeroContent(options = {}) {
|
|
|
109
113
|
);
|
|
110
114
|
contentConfig = mod.default;
|
|
111
115
|
watchedDirs = getWatchedDirs(contentConfig, root);
|
|
116
|
+
await initProcessor(contentConfig.markdown);
|
|
112
117
|
} catch (err) {
|
|
113
118
|
if (err.code === "ERR_MODULE_NOT_FOUND" || err.code === "ENOENT") {
|
|
114
119
|
config.logger.warn(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aerobuilt/content",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jamie Wilson",
|
|
@@ -32,13 +32,19 @@
|
|
|
32
32
|
"types": "./dist/render.d.ts",
|
|
33
33
|
"default": "./dist/render.js"
|
|
34
34
|
},
|
|
35
|
+
"./processor": {
|
|
36
|
+
"types": "./dist/processor.d.ts",
|
|
37
|
+
"default": "./dist/processor.js"
|
|
38
|
+
},
|
|
35
39
|
"./types": "./dist/types.d.ts"
|
|
36
40
|
},
|
|
37
41
|
"dependencies": {
|
|
38
42
|
"fast-glob": "^3.3.3",
|
|
39
43
|
"gray-matter": "^4.0.3",
|
|
40
44
|
"remark": "^15.0.1",
|
|
41
|
-
"remark-
|
|
45
|
+
"remark-rehype": "^11.0.0",
|
|
46
|
+
"rehype-stringify": "^10.0.0",
|
|
47
|
+
"unified": "^11.0.0"
|
|
42
48
|
},
|
|
43
49
|
"peerDependencies": {
|
|
44
50
|
"vite": "^8.0.0-0",
|
|
@@ -53,6 +59,8 @@
|
|
|
53
59
|
}
|
|
54
60
|
},
|
|
55
61
|
"devDependencies": {
|
|
62
|
+
"@shikijs/rehype": "^3.0.0",
|
|
63
|
+
"@shikijs/transformers": "^3.0.0",
|
|
56
64
|
"@types/node": "^25.3.0",
|
|
57
65
|
"tsup": "^8.5.1",
|
|
58
66
|
"typescript": "^5.9.3",
|
|
@@ -61,7 +69,7 @@
|
|
|
61
69
|
"zod": "^4.3.6"
|
|
62
70
|
},
|
|
63
71
|
"scripts": {
|
|
64
|
-
"build": "tsup src/index.ts src/vite.ts src/markdown.ts src/render.ts --format esm --dts --clean --out-dir dist",
|
|
72
|
+
"build": "tsup src/index.ts src/vite.ts src/markdown.ts src/render.ts src/processor.ts --format esm --dts --clean --out-dir dist",
|
|
65
73
|
"typecheck": "tsc --noEmit",
|
|
66
74
|
"test": "vitest run"
|
|
67
75
|
}
|