@aerobuilt/content 0.2.6 → 0.2.7
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-5EPOOVMT.js +67 -0
- package/dist/{chunk-3IPQCQIC.js → chunk-DHKNQV3I.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 +50 -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-BxvX8bzG.d.ts} +13 -8
- package/dist/vite.js +6 -1
- package/package.json +13 -3
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/processor.ts
|
|
2
|
+
import { remark } from "remark";
|
|
3
|
+
import remarkHtml from "remark-html";
|
|
4
|
+
if (!globalThis.__aeroProcessorState) {
|
|
5
|
+
globalThis.__aeroProcessorState = {
|
|
6
|
+
processor: null,
|
|
7
|
+
initialized: false
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function createPlainProcessor() {
|
|
11
|
+
return remark().use(remarkHtml);
|
|
12
|
+
}
|
|
13
|
+
function extractThemeOptions(config) {
|
|
14
|
+
if ("theme" in config && config.theme) {
|
|
15
|
+
return { theme: config.theme };
|
|
16
|
+
}
|
|
17
|
+
if ("themes" in config && config.themes) {
|
|
18
|
+
const opts = { themes: config.themes };
|
|
19
|
+
if ("defaultColor" in config && config.defaultColor !== void 0) {
|
|
20
|
+
opts.defaultColor = config.defaultColor;
|
|
21
|
+
}
|
|
22
|
+
if ("cssVariablePrefix" in config && config.cssVariablePrefix !== void 0) {
|
|
23
|
+
opts.cssVariablePrefix = config.cssVariablePrefix;
|
|
24
|
+
}
|
|
25
|
+
if ("colorsRendering" in config && config.colorsRendering !== void 0) {
|
|
26
|
+
opts.colorsRendering = config.colorsRendering;
|
|
27
|
+
}
|
|
28
|
+
return opts;
|
|
29
|
+
}
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
async function createShikiProcessor(config) {
|
|
33
|
+
const { getHighlighter } = await import("@aerobuilt/highlight");
|
|
34
|
+
const remarkRehype = (await import("remark-rehype")).default;
|
|
35
|
+
const rehypeShikiFromHighlighter = (await import("@shikijs/rehype/core")).default;
|
|
36
|
+
const rehypeStringify = (await import("rehype-stringify")).default;
|
|
37
|
+
const highlighter = await getHighlighter(config);
|
|
38
|
+
return remark().use(remarkRehype).use(rehypeShikiFromHighlighter, highlighter, {
|
|
39
|
+
...extractThemeOptions(config),
|
|
40
|
+
transformers: config.transformers ?? []
|
|
41
|
+
}).use(rehypeStringify);
|
|
42
|
+
}
|
|
43
|
+
async function initProcessor(shikiConfig) {
|
|
44
|
+
if (shikiConfig) {
|
|
45
|
+
globalThis.__aeroProcessorState.processor = await createShikiProcessor(shikiConfig);
|
|
46
|
+
} else {
|
|
47
|
+
globalThis.__aeroProcessorState.processor = createPlainProcessor();
|
|
48
|
+
}
|
|
49
|
+
globalThis.__aeroProcessorState.initialized = true;
|
|
50
|
+
}
|
|
51
|
+
function getProcessor() {
|
|
52
|
+
if (!globalThis.__aeroProcessorState.processor) {
|
|
53
|
+
globalThis.__aeroProcessorState.processor = createPlainProcessor();
|
|
54
|
+
globalThis.__aeroProcessorState.initialized = true;
|
|
55
|
+
}
|
|
56
|
+
return globalThis.__aeroProcessorState.processor;
|
|
57
|
+
}
|
|
58
|
+
function resetProcessor() {
|
|
59
|
+
globalThis.__aeroProcessorState.processor = null;
|
|
60
|
+
globalThis.__aeroProcessorState.initialized = false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
initProcessor,
|
|
65
|
+
getProcessor,
|
|
66
|
+
resetProcessor
|
|
67
|
+
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getProcessor
|
|
3
|
+
} from "./chunk-5EPOOVMT.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, d as defineCollection, e as defineConfig } from './types-BxvX8bzG.js';
|
|
2
|
+
export { ShikiConfig } from '@aerobuilt/highlight';
|
|
2
3
|
export { render } from './render.js';
|
|
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-BxvX8bzG.js';
|
|
2
|
+
import '@aerobuilt/highlight';
|
|
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-5EPOOVMT.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,50 @@
|
|
|
1
|
+
import { ShikiConfig } from '@aerobuilt/highlight';
|
|
2
|
+
import { Processor } from 'unified';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shared markdown processor: remark pipeline with optional Shiki syntax highlighting.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Both `compileMarkdown` (eager, for transforms) and `render` (lazy, for pages) delegate to
|
|
9
|
+
* this module. Call `initProcessor(shikiConfig)` once at startup (from the Vite plugin) to
|
|
10
|
+
* enable Shiki; omit the config for plain `remark-html` output (backward compatible).
|
|
11
|
+
*
|
|
12
|
+
* The processor is created lazily on first use if `initProcessor` was never called.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
declare global {
|
|
16
|
+
var __aeroProcessorState: {
|
|
17
|
+
processor: Processor | null;
|
|
18
|
+
initialized: boolean;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Initialize the shared markdown processor.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Call once at startup (typically from the Vite plugin's configResolved hook) before any
|
|
26
|
+
* markdown compilation occurs. If `shikiConfig` is provided, code blocks in markdown
|
|
27
|
+
* will be syntax-highlighted. If omitted, plain `<pre><code>` output is produced.
|
|
28
|
+
*
|
|
29
|
+
* Safe to call multiple times — subsequent calls replace the processor.
|
|
30
|
+
*
|
|
31
|
+
* @param shikiConfig - Optional Shiki configuration. Omit for plain HTML output.
|
|
32
|
+
*/
|
|
33
|
+
declare function initProcessor(shikiConfig?: ShikiConfig): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Get the shared markdown processor.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Returns the processor created by `initProcessor`. If `initProcessor` was never called,
|
|
39
|
+
* lazily creates the plain remark-html fallback (backward compat for direct imports of
|
|
40
|
+
* `compileMarkdown` or `render` without going through the Vite plugin).
|
|
41
|
+
*
|
|
42
|
+
* @returns The unified processor instance.
|
|
43
|
+
*/
|
|
44
|
+
declare function getProcessor(): Processor;
|
|
45
|
+
/**
|
|
46
|
+
* Reset the processor state. Intended for testing only.
|
|
47
|
+
*/
|
|
48
|
+
declare function resetProcessor(): void;
|
|
49
|
+
|
|
50
|
+
export { 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-BxvX8bzG.js';
|
|
2
|
+
import '@aerobuilt/highlight';
|
|
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,12 +1,6 @@
|
|
|
1
|
+
import * as _aerobuilt_highlight from '@aerobuilt/highlight';
|
|
1
2
|
import { ZodType } from 'zod';
|
|
2
3
|
|
|
3
|
-
/**
|
|
4
|
-
* Content package types: document metadata, collection config, and define helpers.
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* Used by the loader (frontmatter + body → ContentDocument), by content.config.ts (defineCollection, defineConfig), and by the Vite plugin.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
4
|
/** Metadata attached to every content document (path, slug, filename, extension). */
|
|
11
5
|
interface ContentMeta {
|
|
12
6
|
/** Path relative to the collection directory (no extension). */
|
|
@@ -42,9 +36,20 @@ interface ContentCollectionConfig<TSchema extends Record<string, any> = Record<s
|
|
|
42
36
|
/** Optional async transform after validation; receives document, returns final shape. */
|
|
43
37
|
transform?: (document: ContentDocument<TSchema>) => TOutput | Promise<TOutput>;
|
|
44
38
|
}
|
|
45
|
-
/** Top-level content config: array of collection definitions. */
|
|
39
|
+
/** Top-level content config: array of collection definitions with optional highlighting. */
|
|
46
40
|
interface ContentConfig {
|
|
47
41
|
collections: ContentCollectionConfig<any, any>[];
|
|
42
|
+
/**
|
|
43
|
+
* Optional syntax highlighting configuration for markdown code blocks.
|
|
44
|
+
* Nest under `highlight.shiki` to use Shiki-powered highlighting.
|
|
45
|
+
* When omitted, plain `<pre><code>` output is produced (backward compatible).
|
|
46
|
+
*
|
|
47
|
+
* @see https://shiki.style/guide
|
|
48
|
+
*/
|
|
49
|
+
highlight?: {
|
|
50
|
+
/** Shiki configuration. Uses Shiki's native `theme`/`themes` options. */
|
|
51
|
+
shiki: _aerobuilt_highlight.ShikiConfig;
|
|
52
|
+
};
|
|
48
53
|
}
|
|
49
54
|
/**
|
|
50
55
|
* Define a content collection (typed helper for content.config.ts).
|
package/dist/vite.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
initProcessor
|
|
3
|
+
} from "./chunk-5EPOOVMT.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.highlight?.shiki);
|
|
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.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jamie Wilson",
|
|
@@ -32,13 +32,22 @@
|
|
|
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-html": "^16.0.1"
|
|
45
|
+
"remark-html": "^16.0.1",
|
|
46
|
+
"remark-rehype": "^11.0.0",
|
|
47
|
+
"rehype-stringify": "^10.0.0",
|
|
48
|
+
"@shikijs/rehype": "^3.0.0",
|
|
49
|
+
"unified": "^11.0.0",
|
|
50
|
+
"@aerobuilt/highlight": "0.2.7"
|
|
42
51
|
},
|
|
43
52
|
"peerDependencies": {
|
|
44
53
|
"vite": "^8.0.0-0",
|
|
@@ -53,6 +62,7 @@
|
|
|
53
62
|
}
|
|
54
63
|
},
|
|
55
64
|
"devDependencies": {
|
|
65
|
+
"@shikijs/transformers": "^3.0.0",
|
|
56
66
|
"@types/node": "^25.3.0",
|
|
57
67
|
"tsup": "^8.5.1",
|
|
58
68
|
"typescript": "^5.9.3",
|
|
@@ -61,7 +71,7 @@
|
|
|
61
71
|
"zod": "^4.3.6"
|
|
62
72
|
},
|
|
63
73
|
"scripts": {
|
|
64
|
-
"build": "tsup src/index.ts src/vite.ts src/markdown.ts src/render.ts --format esm --dts --clean --out-dir dist",
|
|
74
|
+
"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
75
|
"typecheck": "tsc --noEmit",
|
|
66
76
|
"test": "vitest run"
|
|
67
77
|
}
|