@ecopages/content-processor 0.2.0-beta.22 → 0.2.0-beta.24
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 +23 -13
- package/package.json +4 -4
- package/src/codegen.d.ts +2 -1
- package/src/codegen.js +35 -21
- package/src/constants.d.ts +3 -1
- package/src/constants.js +2 -0
- package/src/content-plugins.d.ts +10 -5
- package/src/content-plugins.js +65 -24
- package/src/content-server-boundary-plugin.d.ts +9 -0
- package/src/content-server-boundary-plugin.js +15 -0
- package/src/index.d.ts +0 -1
- package/src/index.js +1 -4
- package/src/plugin.d.ts +5 -1
- package/src/plugin.js +29 -7
- package/src/types.d.ts +7 -2
package/README.md
CHANGED
|
@@ -4,12 +4,22 @@ Build-time content collections for Ecopages. Scans MDX (or other configured exte
|
|
|
4
4
|
|
|
5
5
|
## Mental model
|
|
6
6
|
|
|
7
|
-
1. **
|
|
8
|
-
2. **
|
|
9
|
-
3. **
|
|
10
|
-
4. **
|
|
7
|
+
1. **Declare collections** in `eco.config.ts` — content directory, frontmatter schema, and sort order.
|
|
8
|
+
2. **Scan at build time** — the processor validates frontmatter and writes generated modules under `.eco/cache/`.
|
|
9
|
+
3. **Import the virtual module** — pages and layouts use `ecopages:content/<collection>` for `entries`, metadata, and MDX components.
|
|
10
|
+
4. **Own your frontmatter** — define fields with any [Standard Schema](https://standardschema.dev)-compatible library (Zod, Valibot, ArkType, etc.). The processor adds `slug` and `segments` from the file path.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
### What this package owns vs. what your app owns
|
|
13
|
+
|
|
14
|
+
| Layer | Owned by |
|
|
15
|
+
| :-------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------- |
|
|
16
|
+
| File discovery, frontmatter validation, manifest sort | `@ecopages/content-processor` |
|
|
17
|
+
| Generated `ecopages:content/*` modules (`entries`, `getComponent`, …) | `@ecopages/content-processor` |
|
|
18
|
+
| `ContentScanner` for build scripts (for example `llms.txt`) | `@ecopages/content-processor` |
|
|
19
|
+
| Routes (`eco.page`), layouts, metadata, URL shape | Your app |
|
|
20
|
+
| Sidebar, breadcrumbs, pagination | Your app — derive from `entries` and frontmatter fields such as `title`, `group`, and `order` |
|
|
21
|
+
|
|
22
|
+
The processor gives you a typed manifest and MDX components at build time. Wire them into Ecopages routing and UI the same way you would any other data source.
|
|
13
23
|
|
|
14
24
|
## Features
|
|
15
25
|
|
|
@@ -156,7 +166,7 @@ import type { Entry } from 'ecopages:content/docs';
|
|
|
156
166
|
|
|
157
167
|
## Page usage
|
|
158
168
|
|
|
159
|
-
|
|
169
|
+
Define a catch-all or per-entry route with `eco.page`. Import the collection manifest and MDX components from the virtual module:
|
|
160
170
|
|
|
161
171
|
```typescript
|
|
162
172
|
import { eco } from '@ecopages/core';
|
|
@@ -191,18 +201,18 @@ export default eco.page<{ entry: Entry }>({
|
|
|
191
201
|
|
|
192
202
|
## Navigation (app-side)
|
|
193
203
|
|
|
194
|
-
|
|
204
|
+
Navigation is app code. Map `entries` to links using the frontmatter and path fields the processor already validated:
|
|
195
205
|
|
|
196
206
|
```typescript
|
|
197
207
|
import { entries } from 'ecopages:content/docs';
|
|
198
208
|
|
|
199
|
-
export const docsNav =
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
});
|
|
209
|
+
export const docsNav = entries.map((entry) => ({
|
|
210
|
+
title: entry.title,
|
|
211
|
+
href: `/docs/${entry.segments.join('/')}`,
|
|
212
|
+
}));
|
|
203
213
|
```
|
|
204
214
|
|
|
205
|
-
|
|
215
|
+
Group or sort in your app — for example by a `group` frontmatter field and an `order` number. See `apps/docs` (`src/lib/content-nav.ts`) and `examples/docs-starter` (`src/content-nav.ts`) for full layouts with sections and sidebars.
|
|
206
216
|
|
|
207
217
|
## Build scripts
|
|
208
218
|
|
|
@@ -227,7 +237,7 @@ const raw = await scanner.getRawContent('getting-started/intro');
|
|
|
227
237
|
|
|
228
238
|
| Import | Purpose |
|
|
229
239
|
| :----------------------------------- | :------------------------------------------------------------ |
|
|
230
|
-
| `@ecopages/content-processor` | `ContentScanner`, sort helpers,
|
|
240
|
+
| `@ecopages/content-processor` | `ContentScanner`, sort helpers, shared types. |
|
|
231
241
|
| `@ecopages/content-processor/plugin` | `contentProcessorPlugin()` for `eco.config.ts`. |
|
|
232
242
|
| `@ecopages/content-processor/types` | `ContentEntry`, `ContentCollectionModule`, `EntryComparator`. |
|
|
233
243
|
| `@ecopages/content-processor/mdx` | `remarkFrontmatter`, `withContentMdxPlugins()`. |
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/content-processor",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0-beta.24",
|
|
4
|
+
"description": "Scan MDX collections at build time and expose typed ecopages:content/* virtual modules for pages and scripts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"content",
|
|
7
7
|
"mdx",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"directory": "packages/processors/content-processor"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@ecopages/core": "0.2.0-beta.
|
|
20
|
+
"@ecopages/core": "0.2.0-beta.24"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@ecopages/file-system": "0.2.0-beta.
|
|
23
|
+
"@ecopages/file-system": "0.2.0-beta.24",
|
|
24
24
|
"@ecopages/logger": "^0.2.3",
|
|
25
25
|
"remark-frontmatter": "^5.0.0",
|
|
26
26
|
"unified": "^11.0.5",
|
package/src/codegen.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ContentEntry } from './types.js';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function renderCollectionEntriesModule(collectionName: string, manifest: ContentEntry[]): string;
|
|
3
|
+
export declare function renderCollectionComponentsModule(collectionName: string, outputDir: string, entrySources: Array<{
|
|
3
4
|
entry: ContentEntry;
|
|
4
5
|
filePath: string;
|
|
5
6
|
}>): string;
|
package/src/codegen.js
CHANGED
|
@@ -12,25 +12,13 @@ function parseEntryTypeImport(entryType) {
|
|
|
12
12
|
}
|
|
13
13
|
return { module, name };
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const importLines = [];
|
|
17
|
-
const componentMapLines = [];
|
|
15
|
+
function renderCollectionEntriesModule(collectionName, manifest) {
|
|
18
16
|
const entriesBySlugLines = [];
|
|
19
|
-
for (const { entry, filePath } of entrySources) {
|
|
20
|
-
const identifier = slugToIdentifier(collectionName, entry.slug);
|
|
21
|
-
const importPath = relative(outputDir, filePath).split("\\").join("/");
|
|
22
|
-
importLines.push(`import ${identifier} from '${importPath}';`);
|
|
23
|
-
componentMapLines.push(` '${entry.slug}': ${identifier},`);
|
|
24
|
-
}
|
|
25
17
|
for (const [index, entry] of manifest.entries()) {
|
|
26
18
|
entriesBySlugLines.push(` '${entry.slug}': entries[${index}],`);
|
|
27
19
|
}
|
|
28
20
|
return `// This file is auto-generated by @ecopages/content-processor. Do not edit.
|
|
29
21
|
|
|
30
|
-
import type { EcoComponent } from '@ecopages/core';
|
|
31
|
-
|
|
32
|
-
${importLines.join("\n")}
|
|
33
|
-
|
|
34
22
|
export const entries = [
|
|
35
23
|
${manifest.map((entry) => ` ${serializeEntry(entry)},`).join("\n")}
|
|
36
24
|
] as const;
|
|
@@ -39,10 +27,6 @@ const entriesBySlug: Record<string, (typeof entries)[number]> = {
|
|
|
39
27
|
${entriesBySlugLines.join("\n")}
|
|
40
28
|
};
|
|
41
29
|
|
|
42
|
-
const componentsBySlug: Record<string, EcoComponent<Record<string, unknown>>> = {
|
|
43
|
-
${componentMapLines.join("\n")}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
30
|
export function getEntry(slug: string) {
|
|
47
31
|
const entry = entriesBySlug[slug];
|
|
48
32
|
if (!entry) throw new Error(\`Unknown content entry: \${slug}\`);
|
|
@@ -52,6 +36,26 @@ export function getEntry(slug: string) {
|
|
|
52
36
|
export function getEntryBySegments(segments: string[]) {
|
|
53
37
|
return getEntry(segments.join('/'));
|
|
54
38
|
}
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
function renderCollectionComponentsModule(collectionName, outputDir, entrySources) {
|
|
42
|
+
const importLines = [];
|
|
43
|
+
const componentMapLines = [];
|
|
44
|
+
for (const { entry, filePath } of entrySources) {
|
|
45
|
+
const identifier = slugToIdentifier(collectionName, entry.slug);
|
|
46
|
+
const importPath = relative(outputDir, filePath).split("\\").join("/");
|
|
47
|
+
importLines.push(`import ${identifier} from '${importPath}';`);
|
|
48
|
+
componentMapLines.push(` '${entry.slug}': ${identifier},`);
|
|
49
|
+
}
|
|
50
|
+
return `// This file is auto-generated by @ecopages/content-processor. Do not edit.
|
|
51
|
+
|
|
52
|
+
import type { EcoComponent } from '@ecopages/core';
|
|
53
|
+
|
|
54
|
+
${importLines.join("\n")}
|
|
55
|
+
|
|
56
|
+
const componentsBySlug: Record<string, EcoComponent<Record<string, unknown>>> = {
|
|
57
|
+
${componentMapLines.join("\n")}
|
|
58
|
+
};
|
|
55
59
|
|
|
56
60
|
export function getComponent(slug: string): EcoComponent<Record<string, unknown>> {
|
|
57
61
|
const component = componentsBySlug[slug];
|
|
@@ -74,7 +78,7 @@ function resolveEntryTypeImport(entryType, rootDir, typesOutputFile) {
|
|
|
74
78
|
}
|
|
75
79
|
return { module: relativeModule, name };
|
|
76
80
|
}
|
|
77
|
-
function
|
|
81
|
+
function renderCollectionEntriesTypesModule(collectionName, entryType, typeResolution) {
|
|
78
82
|
const entryDeclaration = entryType ? (() => {
|
|
79
83
|
const { module, name } = typeResolution ? resolveEntryTypeImport(entryType, typeResolution.rootDir, typeResolution.typesOutputFile) : parseEntryTypeImport(entryType);
|
|
80
84
|
return `import type { ContentEntry } from '@ecopages/content-processor/types';
|
|
@@ -84,16 +88,25 @@ function renderCollectionTypesModule(collectionName, entryType, typeResolution)
|
|
|
84
88
|
|
|
85
89
|
export type Entry = ContentEntry<Record<string, unknown>>;`;
|
|
86
90
|
return `declare module "ecopages:content/${collectionName}" {
|
|
87
|
-
import type { EcoComponent } from '@ecopages/core';
|
|
88
|
-
|
|
89
91
|
${entryDeclaration}
|
|
90
92
|
|
|
91
93
|
export const entries: readonly Entry[];
|
|
92
94
|
export function getEntry(slug: string): Entry;
|
|
93
95
|
export function getEntryBySegments(segments: string[]): Entry;
|
|
96
|
+
}`;
|
|
97
|
+
}
|
|
98
|
+
function renderCollectionComponentsTypesModule(collectionName) {
|
|
99
|
+
return `declare module "ecopages:content/${collectionName}/server" {
|
|
100
|
+
import type { EcoComponent } from '@ecopages/core';
|
|
101
|
+
|
|
94
102
|
export function getComponent(slug: string): EcoComponent<Record<string, unknown>>;
|
|
95
103
|
}`;
|
|
96
104
|
}
|
|
105
|
+
function renderCollectionTypesModule(collectionName, entryType, typeResolution) {
|
|
106
|
+
return `${renderCollectionEntriesTypesModule(collectionName, entryType, typeResolution)}
|
|
107
|
+
|
|
108
|
+
${renderCollectionComponentsTypesModule(collectionName)}`;
|
|
109
|
+
}
|
|
97
110
|
function renderVirtualModuleTypes(collections, typeResolution) {
|
|
98
111
|
return `/**
|
|
99
112
|
* Do not edit manually. This file is auto-generated.
|
|
@@ -104,7 +117,8 @@ ${Object.entries(collections).map(([name, definition]) => renderCollectionTypesM
|
|
|
104
117
|
`;
|
|
105
118
|
}
|
|
106
119
|
export {
|
|
107
|
-
|
|
120
|
+
renderCollectionComponentsModule,
|
|
121
|
+
renderCollectionEntriesModule,
|
|
108
122
|
renderCollectionTypesModule,
|
|
109
123
|
renderVirtualModuleTypes
|
|
110
124
|
};
|
package/src/constants.d.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
export declare const CONTENT_PROCESSOR_NAME = "ecopages-content-processor";
|
|
3
3
|
/** Virtual module prefix for collection imports, e.g. `ecopages:content/docs`. */
|
|
4
4
|
export declare const CONTENT_VIRTUAL_MODULE_PREFIX = "ecopages:content";
|
|
5
|
-
/** Matches `ecopages:content/<collection>`
|
|
5
|
+
/** Matches `ecopages:content/<collection>` metadata specifiers (no MDX imports). */
|
|
6
6
|
export declare const CONTENT_VIRTUAL_MODULE_PATTERN: RegExp;
|
|
7
|
+
/** Matches `ecopages:content/<collection>/server` component resolver specifiers (MDX imports). */
|
|
8
|
+
export declare const CONTENT_SERVER_VIRTUAL_MODULE_PATTERN: RegExp;
|
|
7
9
|
/** Validates collection keys used in processor options and virtual module paths. */
|
|
8
10
|
export declare const COLLECTION_NAME_PATTERN: RegExp;
|
package/src/constants.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
const CONTENT_PROCESSOR_NAME = "ecopages-content-processor";
|
|
2
2
|
const CONTENT_VIRTUAL_MODULE_PREFIX = "ecopages:content";
|
|
3
3
|
const CONTENT_VIRTUAL_MODULE_PATTERN = /^ecopages:content\/[a-z][a-z0-9-]*$/;
|
|
4
|
+
const CONTENT_SERVER_VIRTUAL_MODULE_PATTERN = /^ecopages:content\/[a-z][a-z0-9-]+\/server$/;
|
|
4
5
|
const COLLECTION_NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
5
6
|
export {
|
|
6
7
|
COLLECTION_NAME_PATTERN,
|
|
7
8
|
CONTENT_PROCESSOR_NAME,
|
|
9
|
+
CONTENT_SERVER_VIRTUAL_MODULE_PATTERN,
|
|
8
10
|
CONTENT_VIRTUAL_MODULE_PATTERN,
|
|
9
11
|
CONTENT_VIRTUAL_MODULE_PREFIX
|
|
10
12
|
};
|
package/src/content-plugins.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { EcoBuildPlugin } from '@ecopages/core/plugins/processor';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export type ParsedCollectionSpecifier = {
|
|
3
|
+
collectionName: string;
|
|
4
|
+
variant: 'entries' | 'server';
|
|
5
|
+
};
|
|
6
|
+
export declare function parseCollectionName(specifier: string): string | null;
|
|
7
|
+
export declare function parseCollectionSpecifier(specifier: string): ParsedCollectionSpecifier | null;
|
|
8
|
+
export declare function resolveCollectionPath(specifier: string, collectionModules: Record<string, string>, collectionServerModules: Record<string, string>): string | null;
|
|
9
|
+
export declare function createContentPlugin(collectionModules: Record<string, string>, collectionServerModules: Record<string, string>): EcoBuildPlugin;
|
|
10
|
+
export declare function createContentPluginBundler(collectionModules: Record<string, string>, collectionServerModules: Record<string, string>): EcoBuildPlugin;
|
|
6
11
|
export declare function getCollectionCachePath(cacheDir: string, collectionName: string): string;
|
|
7
|
-
export
|
|
12
|
+
export declare function getCollectionServerCachePath(cacheDir: string, collectionName: string): string;
|
package/src/content-plugins.js
CHANGED
|
@@ -1,50 +1,86 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { fileSystem } from "@ecopages/file-system";
|
|
3
|
-
import { CONTENT_VIRTUAL_MODULE_PATTERN } from "./constants.js";
|
|
3
|
+
import { CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN } from "./constants.js";
|
|
4
4
|
function parseCollectionName(specifier) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const parsed = parseCollectionSpecifier(specifier);
|
|
6
|
+
return parsed?.collectionName ?? null;
|
|
7
|
+
}
|
|
8
|
+
function parseCollectionSpecifier(specifier) {
|
|
9
|
+
const normalized = specifier.startsWith("ecopages:content/") ? specifier.slice("ecopages:content/".length) : specifier.startsWith("content/") ? specifier.slice("content/".length) : null;
|
|
10
|
+
if (!normalized) {
|
|
11
|
+
return null;
|
|
7
12
|
}
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
13
|
+
if (normalized.endsWith("/server")) {
|
|
14
|
+
return {
|
|
15
|
+
collectionName: normalized.slice(0, -"/server".length),
|
|
16
|
+
variant: "server"
|
|
17
|
+
};
|
|
10
18
|
}
|
|
11
|
-
return
|
|
19
|
+
return {
|
|
20
|
+
collectionName: normalized,
|
|
21
|
+
variant: "entries"
|
|
22
|
+
};
|
|
12
23
|
}
|
|
13
|
-
function resolveCollectionPath(specifier, collectionModules) {
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
24
|
+
function resolveCollectionPath(specifier, collectionModules, collectionServerModules) {
|
|
25
|
+
const parsed = parseCollectionSpecifier(specifier);
|
|
26
|
+
if (!parsed) {
|
|
16
27
|
return null;
|
|
17
28
|
}
|
|
18
|
-
|
|
29
|
+
if (parsed.variant === "server") {
|
|
30
|
+
return collectionServerModules[parsed.collectionName] ?? null;
|
|
31
|
+
}
|
|
32
|
+
return collectionModules[parsed.collectionName] ?? null;
|
|
19
33
|
}
|
|
20
|
-
function
|
|
34
|
+
function createContentResolvePlugin(collectionModules, collectionServerModules, options) {
|
|
21
35
|
return {
|
|
22
36
|
name: "ecopages:content",
|
|
23
37
|
setup(build) {
|
|
38
|
+
const resolveCollection = (specifier) => resolveCollectionPath(specifier, collectionModules, collectionServerModules);
|
|
24
39
|
build.onResolve({ filter: CONTENT_VIRTUAL_MODULE_PATTERN }, (args) => {
|
|
25
|
-
const modulePath =
|
|
40
|
+
const modulePath = resolveCollection(args.path);
|
|
26
41
|
if (!modulePath) {
|
|
27
42
|
return void 0;
|
|
28
43
|
}
|
|
44
|
+
if (options.namespace) {
|
|
45
|
+
return {
|
|
46
|
+
namespace: options.namespace,
|
|
47
|
+
path: modulePath
|
|
48
|
+
};
|
|
49
|
+
}
|
|
29
50
|
return { path: modulePath };
|
|
30
51
|
});
|
|
52
|
+
if (options.includeServerModules !== false) {
|
|
53
|
+
build.onResolve({ filter: CONTENT_SERVER_VIRTUAL_MODULE_PATTERN }, (args) => {
|
|
54
|
+
const modulePath = resolveCollection(args.path);
|
|
55
|
+
if (!modulePath) {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
if (options.namespace) {
|
|
59
|
+
return {
|
|
60
|
+
namespace: options.namespace,
|
|
61
|
+
path: modulePath
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return { path: modulePath };
|
|
65
|
+
});
|
|
66
|
+
}
|
|
31
67
|
}
|
|
32
68
|
};
|
|
33
69
|
}
|
|
34
|
-
function
|
|
70
|
+
function createContentPlugin(collectionModules, collectionServerModules) {
|
|
71
|
+
return createContentResolvePlugin(collectionModules, collectionServerModules, {
|
|
72
|
+
includeServerModules: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function createContentPluginBundler(collectionModules, collectionServerModules) {
|
|
76
|
+
const plugin = createContentResolvePlugin(collectionModules, collectionServerModules, {
|
|
77
|
+
namespace: "ecopages-content",
|
|
78
|
+
includeServerModules: false
|
|
79
|
+
});
|
|
35
80
|
return {
|
|
36
|
-
name:
|
|
81
|
+
name: plugin.name,
|
|
37
82
|
setup(build) {
|
|
38
|
-
|
|
39
|
-
const modulePath = resolveCollectionPath(args.path, collectionModules);
|
|
40
|
-
if (!modulePath) {
|
|
41
|
-
return void 0;
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
namespace: "ecopages-content",
|
|
45
|
-
path: modulePath
|
|
46
|
-
};
|
|
47
|
-
});
|
|
83
|
+
plugin.setup?.(build);
|
|
48
84
|
build.onLoad({ filter: /.*/, namespace: "ecopages-content" }, async (args) => {
|
|
49
85
|
const contents = await fileSystem.readFile(args.path);
|
|
50
86
|
return { contents, loader: "ts" };
|
|
@@ -55,10 +91,15 @@ function createContentPluginBundler(collectionModules) {
|
|
|
55
91
|
function getCollectionCachePath(cacheDir, collectionName) {
|
|
56
92
|
return path.join(cacheDir, `${collectionName}.ts`);
|
|
57
93
|
}
|
|
94
|
+
function getCollectionServerCachePath(cacheDir, collectionName) {
|
|
95
|
+
return path.join(cacheDir, `${collectionName}.server.ts`);
|
|
96
|
+
}
|
|
58
97
|
export {
|
|
59
98
|
createContentPlugin,
|
|
60
99
|
createContentPluginBundler,
|
|
61
100
|
getCollectionCachePath,
|
|
101
|
+
getCollectionServerCachePath,
|
|
62
102
|
parseCollectionName,
|
|
103
|
+
parseCollectionSpecifier,
|
|
63
104
|
resolveCollectionPath
|
|
64
105
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EcoBuildPlugin } from '@ecopages/core/plugins/processor';
|
|
2
|
+
/**
|
|
3
|
+
* Keeps `ecopages:content/<collection>/server` out of browser bundles.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Server modules static-import every MDX entry for `getComponent`. Browser builds
|
|
7
|
+
* must never follow that graph — highlighted MDX output belongs in SSR HTML only.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createContentServerBoundaryPlugin(): EcoBuildPlugin;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CONTENT_SERVER_VIRTUAL_MODULE_PATTERN } from "./constants.js";
|
|
2
|
+
function createContentServerBoundaryPlugin() {
|
|
3
|
+
return {
|
|
4
|
+
name: "ecopages:content-server-boundary",
|
|
5
|
+
setup(build) {
|
|
6
|
+
build.onResolve({ filter: CONTENT_SERVER_VIRTUAL_MODULE_PATTERN }, (args) => ({
|
|
7
|
+
path: args.path,
|
|
8
|
+
external: true
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
createContentServerBoundaryPlugin
|
|
15
|
+
};
|
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { ContentScanner } from './content-scanner.js';
|
|
2
2
|
export type { ContentScannerConfig } from './content-scanner.js';
|
|
3
3
|
export { CONTENT_PROCESSOR_NAME, CONTENT_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PREFIX, COLLECTION_NAME_PATTERN, } from './constants.js';
|
|
4
|
-
export { contentProcessorPlugin, ContentProcessorPlugin } from './plugin.js';
|
|
5
4
|
export { compareEntriesByField, compareEntriesBySlug, type EntryComparator } from './sort.js';
|
|
6
5
|
export type { ContentCollectionDefinition, ContentCollectionsConfig, ContentProcessorConfig, } from './collection-types.js';
|
|
7
6
|
export type { StandardSchema } from '@ecopages/core';
|
package/src/index.js
CHANGED
|
@@ -5,16 +5,13 @@ import {
|
|
|
5
5
|
CONTENT_VIRTUAL_MODULE_PREFIX,
|
|
6
6
|
COLLECTION_NAME_PATTERN
|
|
7
7
|
} from "./constants.js";
|
|
8
|
-
import { contentProcessorPlugin, ContentProcessorPlugin } from "./plugin.js";
|
|
9
8
|
import { compareEntriesByField, compareEntriesBySlug } from "./sort.js";
|
|
10
9
|
export {
|
|
11
10
|
COLLECTION_NAME_PATTERN,
|
|
12
11
|
CONTENT_PROCESSOR_NAME,
|
|
13
12
|
CONTENT_VIRTUAL_MODULE_PATTERN,
|
|
14
13
|
CONTENT_VIRTUAL_MODULE_PREFIX,
|
|
15
|
-
ContentProcessorPlugin,
|
|
16
14
|
ContentScanner,
|
|
17
15
|
compareEntriesByField,
|
|
18
|
-
compareEntriesBySlug
|
|
19
|
-
contentProcessorPlugin
|
|
16
|
+
compareEntriesBySlug
|
|
20
17
|
};
|
package/src/plugin.d.ts
CHANGED
|
@@ -12,10 +12,14 @@ export declare class ContentProcessorPlugin extends Processor<ContentProcessorCo
|
|
|
12
12
|
private collectionsGenerated;
|
|
13
13
|
private readonly scanners;
|
|
14
14
|
/**
|
|
15
|
-
* Absolute paths to generated collection modules, keyed by collection name.
|
|
15
|
+
* Absolute paths to generated collection entry modules, keyed by collection name.
|
|
16
16
|
* Virtual-module plugins close over this object so mutations stay live.
|
|
17
17
|
*/
|
|
18
18
|
readonly collectionModules: Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* Absolute paths to generated server-only component resolver modules.
|
|
21
|
+
*/
|
|
22
|
+
readonly collectionServerModules: Record<string, string>;
|
|
19
23
|
constructor(config: Omit<ProcessorConfig<ContentProcessorConfig>, 'name' | 'description'>);
|
|
20
24
|
get buildPlugins(): EcoBuildPlugin[];
|
|
21
25
|
get plugins(): EcoBuildPlugin[];
|
package/src/plugin.js
CHANGED
|
@@ -6,10 +6,20 @@ import {
|
|
|
6
6
|
resolveGeneratedPath
|
|
7
7
|
} from "@ecopages/core/plugins/processor";
|
|
8
8
|
import { Logger } from "@ecopages/logger";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
renderCollectionComponentsModule,
|
|
11
|
+
renderCollectionEntriesModule,
|
|
12
|
+
renderVirtualModuleTypes
|
|
13
|
+
} from "./codegen.js";
|
|
10
14
|
import { compareEntriesBySlug } from "./sort.js";
|
|
11
15
|
import { ContentScanner } from "./content-scanner.js";
|
|
12
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
createContentPlugin,
|
|
18
|
+
createContentPluginBundler,
|
|
19
|
+
getCollectionCachePath,
|
|
20
|
+
getCollectionServerCachePath
|
|
21
|
+
} from "./content-plugins.js";
|
|
22
|
+
import { createContentServerBoundaryPlugin } from "./content-server-boundary-plugin.js";
|
|
13
23
|
import { COLLECTION_NAME_PATTERN, CONTENT_PROCESSOR_NAME } from "./constants.js";
|
|
14
24
|
const logger = new Logger("[@ecopages/content-processor]", {
|
|
15
25
|
debug: process.env.ECOPAGES_LOGGER_DEBUG === "true"
|
|
@@ -25,10 +35,14 @@ class ContentProcessorPlugin extends Processor {
|
|
|
25
35
|
collectionsGenerated = false;
|
|
26
36
|
scanners = /* @__PURE__ */ new Map();
|
|
27
37
|
/**
|
|
28
|
-
* Absolute paths to generated collection modules, keyed by collection name.
|
|
38
|
+
* Absolute paths to generated collection entry modules, keyed by collection name.
|
|
29
39
|
* Virtual-module plugins close over this object so mutations stay live.
|
|
30
40
|
*/
|
|
31
41
|
collectionModules = {};
|
|
42
|
+
/**
|
|
43
|
+
* Absolute paths to generated server-only component resolver modules.
|
|
44
|
+
*/
|
|
45
|
+
collectionServerModules = {};
|
|
32
46
|
constructor(config) {
|
|
33
47
|
const defaultWatchConfig = {
|
|
34
48
|
paths: [],
|
|
@@ -45,10 +59,13 @@ class ContentProcessorPlugin extends Processor {
|
|
|
45
59
|
});
|
|
46
60
|
}
|
|
47
61
|
get buildPlugins() {
|
|
48
|
-
return [
|
|
62
|
+
return [
|
|
63
|
+
createContentServerBoundaryPlugin(),
|
|
64
|
+
createContentPluginBundler(this.collectionModules, this.collectionServerModules)
|
|
65
|
+
];
|
|
49
66
|
}
|
|
50
67
|
get plugins() {
|
|
51
|
-
return [createContentPlugin(this.collectionModules)];
|
|
68
|
+
return [createContentPlugin(this.collectionModules, this.collectionServerModules)];
|
|
52
69
|
}
|
|
53
70
|
getCollectionsConfig() {
|
|
54
71
|
if (!this.options?.collections) {
|
|
@@ -101,13 +118,18 @@ class ContentProcessorPlugin extends Processor {
|
|
|
101
118
|
const entrySources = await scanner.getEntrySources();
|
|
102
119
|
const manifest = entrySources.map(({ entry }) => entry);
|
|
103
120
|
const outputFile = getCollectionCachePath(this.context.cache, collectionName);
|
|
121
|
+
const serverOutputFile = getCollectionServerCachePath(this.context.cache, collectionName);
|
|
104
122
|
const outputDir = path.dirname(outputFile);
|
|
105
|
-
const
|
|
106
|
-
|
|
123
|
+
const entriesOutput = renderCollectionEntriesModule(collectionName, manifest);
|
|
124
|
+
const componentsOutput = renderCollectionComponentsModule(collectionName, outputDir, entrySources);
|
|
125
|
+
this.writeGeneratedFile(outputFile, entriesOutput);
|
|
126
|
+
this.writeGeneratedFile(serverOutputFile, componentsOutput);
|
|
107
127
|
this.collectionModules[collectionName] = outputFile;
|
|
128
|
+
this.collectionServerModules[collectionName] = serverOutputFile;
|
|
108
129
|
logger.debug("Generated content collection module", {
|
|
109
130
|
collectionName,
|
|
110
131
|
outputFile,
|
|
132
|
+
serverOutputFile,
|
|
111
133
|
entryCount: manifest.length
|
|
112
134
|
});
|
|
113
135
|
}
|
package/src/types.d.ts
CHANGED
|
@@ -13,10 +13,15 @@ export type ContentEntry<T extends Record<string, unknown> = Record<string, unkn
|
|
|
13
13
|
};
|
|
14
14
|
/** @deprecated Use {@link EntryComparator} instead. */
|
|
15
15
|
export type OrderBy<T extends Record<string, unknown> = Record<string, unknown>> = EntryComparator<T>;
|
|
16
|
-
/** Runtime shape of a generated `ecopages:content/<collection>` module. */
|
|
17
|
-
export type
|
|
16
|
+
/** Runtime shape of a generated `ecopages:content/<collection>` entries module. */
|
|
17
|
+
export type ContentCollectionEntriesModule<TEntry extends Record<string, unknown> = Record<string, unknown>> = {
|
|
18
18
|
readonly entries: readonly ContentEntry<TEntry>[];
|
|
19
19
|
getEntry(slug: string): ContentEntry<TEntry>;
|
|
20
20
|
getEntryBySegments(segments: string[]): ContentEntry<TEntry>;
|
|
21
|
+
};
|
|
22
|
+
/** Runtime shape of a generated `ecopages:content/<collection>/server` module. */
|
|
23
|
+
export type ContentCollectionComponentsModule = {
|
|
21
24
|
getComponent(slug: string): EcoComponent<Record<string, unknown>>;
|
|
22
25
|
};
|
|
26
|
+
/** @deprecated Import entries and server modules separately. */
|
|
27
|
+
export type ContentCollectionModule<TEntry extends Record<string, unknown> = Record<string, unknown>> = ContentCollectionEntriesModule<TEntry> & ContentCollectionComponentsModule;
|