@ecopages/content-processor 0.2.0-beta.22

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Andrea Zanenghi
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,277 @@
1
+ # @ecopages/content-processor
2
+
3
+ Build-time content collections for Ecopages. Scans MDX (or other configured extensions) at build time, validates frontmatter, and exposes each collection as a typed virtual module: `ecopages:content/<collection>`.
4
+
5
+ ## Mental model
6
+
7
+ 1. **You declare collections** in `eco.config.ts` (content directory, schema, sort order).
8
+ 2. **The processor scans files at build time** and writes generated modules under `.eco/cache/`.
9
+ 3. **Pages import a virtual module** (`ecopages:content/docs`) for entries, metadata, and MDX components.
10
+ 4. **Frontmatter is yours; routing fields are not.** You define and validate frontmatter with any [Standard Schema](https://standardschema.dev)-compatible library (Zod, Valibot, ArkType, etc.). The processor adds `slug` and `segments` from the file path.
11
+
12
+ The processor does **not** ship page factories or navigation builders. You write `eco.page` routes and build nav from `entries` in app code.
13
+
14
+ ## Features
15
+
16
+ - **Build-time scanning** — content metadata and MDX imports are resolved before page bundles ship.
17
+ - **Standard Schema validation** — frontmatter schemas stay in your app; the library validates through the Standard Schema interface.
18
+ - **Typed virtual modules** — `ecopages:content/<collection>` with generated `Entry` types.
19
+ - **Multiple collections** — docs, blog, changelog, or any keyed collection you configure.
20
+ - **`ContentScanner`** — reuse the same scan logic in one-off build scripts (for example, `llms.txt` generation).
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ bun add @ecopages/content-processor
26
+ ```
27
+
28
+ Peer dependency: `@ecopages/core`.
29
+
30
+ ## Configuration
31
+
32
+ Register the processor in `eco.config.ts`:
33
+
34
+ ```typescript
35
+ import { ConfigBuilder } from '@ecopages/core/config-builder';
36
+ import { contentProcessorPlugin } from '@ecopages/content-processor/plugin';
37
+ import { compareEntriesByField } from '@ecopages/content-processor';
38
+ import { docsFrontmatterSchema } from './src/content/docs-schema';
39
+
40
+ export default await new ConfigBuilder()
41
+ .setRootDir(import.meta.dir)
42
+ .setProcessors([
43
+ contentProcessorPlugin({
44
+ options: {
45
+ collections: {
46
+ docs: {
47
+ contentDir: 'content/docs',
48
+ orderBy: compareEntriesByField('order'),
49
+ schema: docsFrontmatterSchema,
50
+ entryType: './src/content/docs-schema#DocsFrontmatter',
51
+ },
52
+ blog: {
53
+ contentDir: 'content/blog',
54
+ orderBy: compareEntriesByField('title'),
55
+ schema: blogFrontmatterSchema,
56
+ entryType: './src/content/blog-schema#BlogFrontmatter',
57
+ extensions: ['.mdx', '.md'],
58
+ },
59
+ },
60
+ },
61
+ }),
62
+ ])
63
+ .build();
64
+ ```
65
+
66
+ ### Collection options
67
+
68
+ | Option | Required | Description |
69
+ | :----------- | :------: | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
70
+ | `contentDir` | yes | Directory relative to app `srcDir`, e.g. `content/docs`. |
71
+ | `schema` | yes | Standard Schema validator for frontmatter. |
72
+ | `entryType` | no | Frontmatter type for generated virtual-module types. Format: `./path/to/schema#TypeName`. The processor wraps it as `ContentEntry<YourFrontmatter>`. |
73
+ | `orderBy` | no | Comparator function for manifest sort. Default: {@link compareEntriesBySlug}. Use {@link compareEntriesByField} for frontmatter fields. |
74
+ | `extensions` | no | File extensions to scan. Default: `['.mdx']`. |
75
+
76
+ Collection keys must be kebab-case (`docs`, `api-reference`). Each key becomes `ecopages:content/<key>`.
77
+
78
+ ## Frontmatter schema (app-owned)
79
+
80
+ Define schema and frontmatter types in your app. Zod 4 is a common choice:
81
+
82
+ ```typescript
83
+ // src/content/docs-schema.ts
84
+ import { z } from 'zod';
85
+
86
+ export const docsFrontmatterSchema = z.object({
87
+ title: z.string(),
88
+ description: z.string(),
89
+ group: z.string().optional(),
90
+ order: z.coerce.number().optional(),
91
+ });
92
+
93
+ export type DocsFrontmatter = z.infer<typeof docsFrontmatterSchema>;
94
+ ```
95
+
96
+ **Important:** Do not add `slug` or `segments` to your schema. The processor derives them from the file path and exposes them through `ContentEntry<T>`:
97
+
98
+ ```typescript
99
+ import type { ContentEntry } from '@ecopages/content-processor';
100
+
101
+ type DocsEntry = ContentEntry<DocsFrontmatter>;
102
+ // DocsEntry includes: title, description, group?, order?, slug, segments
103
+ ```
104
+
105
+ Point `entryType` at the **frontmatter type** (`DocsFrontmatter`), not a hand-rolled entry type.
106
+
107
+ ## TypeScript setup
108
+
109
+ Virtual-module types are generated at build/dev time into:
110
+
111
+ ```text
112
+ node_modules/@types/ecopages-content-processor/virtual-module.d.ts
113
+ ```
114
+
115
+ Add a root `modules.d.ts` (same pattern as `@ecopages/image-processor`):
116
+
117
+ ```typescript
118
+ /// <reference types="ecopages-content-processor" />
119
+
120
+ import '@ecopages/core/declarations';
121
+ import '@ecopages/content-processor/types';
122
+ ```
123
+
124
+ Recommended `tsconfig.json` additions:
125
+
126
+ ```json
127
+ {
128
+ "compilerOptions": {
129
+ "baseUrl": ".",
130
+ "types": ["bun", "ecopages-content-processor"]
131
+ },
132
+ "include": ["src", "eco.config.ts", "modules.d.ts", "node_modules/@types/ecopages-content-processor"]
133
+ }
134
+ ```
135
+
136
+ Run `ecopages dev` or `ecopages build` before expecting IDE types. Restart the TypeScript server if types look stale after changing schema or collection config.
137
+
138
+ ## Virtual module API
139
+
140
+ Each collection exposes `ecopages:content/<collection>`:
141
+
142
+ ```typescript
143
+ import { entries, getEntry, getEntryBySegments, getComponent } from 'ecopages:content/docs';
144
+ import type { Entry } from 'ecopages:content/docs';
145
+ ```
146
+
147
+ | Export | Description |
148
+ | :----------------------------- | :---------------------------------------------------------------------------------------------- |
149
+ | `entries` | Readonly manifest of all entries, sorted by `orderBy`. |
150
+ | `getEntry(slug)` | Lookup by joined slug, e.g. `'getting-started/intro'`. |
151
+ | `getEntryBySegments(segments)` | Lookup by segment array, e.g. `['getting-started', 'intro']`. |
152
+ | `getComponent(slug)` | MDX component for the entry. |
153
+ | `Entry` | **Type only.** `ContentEntry<YourFrontmatter>` — frontmatter fields plus `slug` and `segments`. |
154
+
155
+ **Important:** `Entry` exists only in generated `.d.ts` files, not in the runtime cache module. Keep type imports on a separate `import type` line in page files that get bundled. Mixed imports like `import { entries, type Entry }` can cause the bundler to treat `Entry` as a runtime export and fail with `MISSING_EXPORT`.
156
+
157
+ ## Page usage
158
+
159
+ Write routes with `eco.page`. The processor does not provide a `createContentPage` helper.
160
+
161
+ ```typescript
162
+ import { eco } from '@ecopages/core';
163
+ import { entries, getComponent, getEntryBySegments } from 'ecopages:content/docs';
164
+ import type { Entry } from 'ecopages:content/docs';
165
+
166
+ export default eco.page<{ entry: Entry }>({
167
+ staticPaths: async () => ({
168
+ paths: entries.map((post) => ({
169
+ params: { slug: post.segments },
170
+ })),
171
+ }),
172
+ staticProps: async ({ pathname }) => {
173
+ const segments = Array.isArray(pathname.params.slug)
174
+ ? pathname.params.slug
175
+ : [pathname.params.slug];
176
+
177
+ return {
178
+ props: { entry: getEntryBySegments(segments) },
179
+ };
180
+ },
181
+ metadata: ({ props: { entry } }) => ({
182
+ title: entry.title,
183
+ description: entry.description,
184
+ }),
185
+ render: async ({ entry }) => {
186
+ const Content = getComponent(entry.slug);
187
+ return <Content />;
188
+ },
189
+ });
190
+ ```
191
+
192
+ ## Navigation (app-side)
193
+
194
+ Build navigation from `entries` in your app. The processor does not generate nav trees.
195
+
196
+ ```typescript
197
+ import { entries } from 'ecopages:content/docs';
198
+
199
+ export const docsNav = buildGroupedNav(entries, {
200
+ rootDir: '/docs',
201
+ groupOrder: groupOrderIndex,
202
+ });
203
+ ```
204
+
205
+ Use `entry.group`, `entry.segments`, and `entry.title` from the manifest.
206
+
207
+ ## Build scripts
208
+
209
+ Use `ContentScanner` when a script needs the manifest outside page bundles:
210
+
211
+ ```typescript
212
+ import { join } from 'node:path';
213
+ import { ContentScanner, compareEntriesByField } from '@ecopages/content-processor';
214
+ import { docsFrontmatterSchema } from '../src/content/docs-schema';
215
+
216
+ const scanner = new ContentScanner({
217
+ contentRoot: join(srcDir, 'content/docs'),
218
+ orderBy: compareEntriesByField('order'),
219
+ schema: docsFrontmatterSchema,
220
+ });
221
+
222
+ const manifest = await scanner.getManifest();
223
+ const raw = await scanner.getRawContent('getting-started/intro');
224
+ ```
225
+
226
+ ## Package exports
227
+
228
+ | Import | Purpose |
229
+ | :----------------------------------- | :------------------------------------------------------------ |
230
+ | `@ecopages/content-processor` | `ContentScanner`, sort helpers, plugin factory, shared types. |
231
+ | `@ecopages/content-processor/plugin` | `contentProcessorPlugin()` for `eco.config.ts`. |
232
+ | `@ecopages/content-processor/types` | `ContentEntry`, `ContentCollectionModule`, `EntryComparator`. |
233
+ | `@ecopages/content-processor/mdx` | `remarkFrontmatter`, `withContentMdxPlugins()`. |
234
+
235
+ ## Generated artifacts
236
+
237
+ | Path | Purpose |
238
+ | :------------------------------------------------------------------- | :----------------------------------------------------- |
239
+ | `.eco/cache/ecopages-content-processor/<collection>.ts` | Generated collection module (manifest + MDX imports). |
240
+ | `node_modules/@types/ecopages-content-processor/virtual-module.d.ts` | Generated TypeScript declarations for virtual modules. |
241
+
242
+ Do not edit generated files manually.
243
+
244
+ ## Validation errors
245
+
246
+ Invalid frontmatter throws `SchemaError` from `@standard-schema/utils` during scan/build. Fix the MDX frontmatter or relax the schema in your app.
247
+
248
+ ## MDX integration
249
+
250
+ Content files are MDX components. Ensure your JSX/MDX integration (for example, `@ecopages/ecopages-jsx`) is configured in `eco.config.ts` so `getComponent()` returns a renderable component.
251
+
252
+ Content collections with YAML frontmatter need `remark-frontmatter` in the **MDX compile pipeline**. The processor validates frontmatter at scan time (`vfile-matter`); MDX render time needs the remark plugin so `---` blocks are not emitted as content.
253
+
254
+ Use `@ecopages/content-processor/mdx`:
255
+
256
+ ```typescript
257
+ import { withContentMdxPlugins } from '@ecopages/content-processor/mdx';
258
+ import remarkGfm from 'remark-gfm';
259
+
260
+ ecopagesJsxPlugin({
261
+ mdx: {
262
+ enabled: true,
263
+ ...withContentMdxPlugins({
264
+ remarkPlugins: [remarkGfm],
265
+ rehypePlugins: [/* app-specific rehype plugins */],
266
+ }),
267
+ },
268
+ });
269
+ ```
270
+
271
+ `withContentMdxPlugins()` prepends `remarkFrontmatter`. Import it directly when you need finer control:
272
+
273
+ ```typescript
274
+ import { remarkFrontmatter } from '@ecopages/content-processor/mdx';
275
+ ```
276
+
277
+ App-specific presentation plugins (syntax highlighting, GFM, table wrappers) stay in your app — for example `src/mdx/plugins.ts`.
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@ecopages/content-processor",
3
+ "version": "0.2.0-beta.22",
4
+ "description": "Build-time content collections exposed as ecopages:content/* virtual modules",
5
+ "keywords": [
6
+ "content",
7
+ "mdx",
8
+ "processor",
9
+ "collections"
10
+ ],
11
+ "license": "MIT",
12
+ "main": "./src/index.js",
13
+ "type": "module",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/ecopages/ecopages.git",
17
+ "directory": "packages/processors/content-processor"
18
+ },
19
+ "peerDependencies": {
20
+ "@ecopages/core": "0.2.0-beta.22"
21
+ },
22
+ "dependencies": {
23
+ "@ecopages/file-system": "0.2.0-beta.22",
24
+ "@ecopages/logger": "^0.2.3",
25
+ "remark-frontmatter": "^5.0.0",
26
+ "unified": "^11.0.5",
27
+ "vfile": "^6.0.3",
28
+ "vfile-matter": "^5.0.1"
29
+ },
30
+ "exports": {
31
+ ".": {
32
+ "default": "./src/index.js",
33
+ "types": "./src/index.d.ts"
34
+ },
35
+ "./plugin": {
36
+ "default": "./src/plugin.js",
37
+ "types": "./src/plugin.d.ts"
38
+ },
39
+ "./types": {
40
+ "types": "./src/types.d.ts"
41
+ },
42
+ "./mdx": {
43
+ "default": "./src/mdx.js",
44
+ "types": "./src/mdx.d.ts"
45
+ },
46
+ "./plugin.ts": {
47
+ "default": "./src/plugin.js",
48
+ "types": "./src/plugin.d.ts"
49
+ },
50
+ "./types.ts": {
51
+ "types": "./src/types.d.ts"
52
+ },
53
+ "./mdx.ts": {
54
+ "default": "./src/mdx.js",
55
+ "types": "./src/mdx.d.ts"
56
+ }
57
+ },
58
+ "typesVersions": {
59
+ "*": {
60
+ "ecopages:content/*": [
61
+ "./virtual-module.d.ts"
62
+ ]
63
+ }
64
+ },
65
+ "types": "./src/index.d.ts"
66
+ }
@@ -0,0 +1,15 @@
1
+ import type { ContentEntry } from './types.js';
2
+ export declare function renderCollectionModule(collectionName: string, outputDir: string, manifest: ContentEntry[], entrySources: Array<{
3
+ entry: ContentEntry;
4
+ filePath: string;
5
+ }>): string;
6
+ export declare function renderCollectionTypesModule(collectionName: string, entryType?: string, typeResolution?: {
7
+ rootDir: string;
8
+ typesOutputFile: string;
9
+ }): string;
10
+ export declare function renderVirtualModuleTypes(collections: Record<string, {
11
+ entryType?: string;
12
+ }>, typeResolution?: {
13
+ rootDir: string;
14
+ typesOutputFile: string;
15
+ }): string;
package/src/codegen.js ADDED
@@ -0,0 +1,110 @@
1
+ import { relative, resolve, dirname, join } from "node:path";
2
+ function slugToIdentifier(collectionName, slug) {
3
+ return `${collectionName}_${slug.replace(/[^a-zA-Z0-9]/g, "_")}`;
4
+ }
5
+ function serializeEntry(entry) {
6
+ return JSON.stringify(entry);
7
+ }
8
+ function parseEntryTypeImport(entryType) {
9
+ const [module, name = "Entry"] = entryType.split("#");
10
+ if (!module) {
11
+ throw new Error(`Invalid entryType "${entryType}". Expected format: "./path/to/file#TypeName"`);
12
+ }
13
+ return { module, name };
14
+ }
15
+ function renderCollectionModule(collectionName, outputDir, manifest, entrySources) {
16
+ const importLines = [];
17
+ const componentMapLines = [];
18
+ 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
+ for (const [index, entry] of manifest.entries()) {
26
+ entriesBySlugLines.push(` '${entry.slug}': entries[${index}],`);
27
+ }
28
+ return `// This file is auto-generated by @ecopages/content-processor. Do not edit.
29
+
30
+ import type { EcoComponent } from '@ecopages/core';
31
+
32
+ ${importLines.join("\n")}
33
+
34
+ export const entries = [
35
+ ${manifest.map((entry) => ` ${serializeEntry(entry)},`).join("\n")}
36
+ ] as const;
37
+
38
+ const entriesBySlug: Record<string, (typeof entries)[number]> = {
39
+ ${entriesBySlugLines.join("\n")}
40
+ };
41
+
42
+ const componentsBySlug: Record<string, EcoComponent<Record<string, unknown>>> = {
43
+ ${componentMapLines.join("\n")}
44
+ };
45
+
46
+ export function getEntry(slug: string) {
47
+ const entry = entriesBySlug[slug];
48
+ if (!entry) throw new Error(\`Unknown content entry: \${slug}\`);
49
+ return entry;
50
+ }
51
+
52
+ export function getEntryBySegments(segments: string[]) {
53
+ return getEntry(segments.join('/'));
54
+ }
55
+
56
+ export function getComponent(slug: string): EcoComponent<Record<string, unknown>> {
57
+ const component = componentsBySlug[slug];
58
+ if (!component) throw new Error(\`Unknown content entry: \${slug}\`);
59
+ return component;
60
+ }
61
+ `;
62
+ }
63
+ function resolveEntryTypeImport(entryType, rootDir, typesOutputFile) {
64
+ const { module, name } = parseEntryTypeImport(entryType);
65
+ const absoluteModule = resolve(rootDir, module);
66
+ const srcDir = join(rootDir, "src");
67
+ const relativeToSrc = relative(srcDir, absoluteModule).split("\\").join("/");
68
+ if (!relativeToSrc.startsWith("..") && !relativeToSrc.startsWith("/")) {
69
+ return { module: `@/${relativeToSrc}`, name };
70
+ }
71
+ let relativeModule = relative(dirname(typesOutputFile), absoluteModule).split("\\").join("/");
72
+ if (!relativeModule.startsWith(".")) {
73
+ relativeModule = `./${relativeModule}`;
74
+ }
75
+ return { module: relativeModule, name };
76
+ }
77
+ function renderCollectionTypesModule(collectionName, entryType, typeResolution) {
78
+ const entryDeclaration = entryType ? (() => {
79
+ const { module, name } = typeResolution ? resolveEntryTypeImport(entryType, typeResolution.rootDir, typeResolution.typesOutputFile) : parseEntryTypeImport(entryType);
80
+ return `import type { ContentEntry } from '@ecopages/content-processor/types';
81
+ import type { ${name} } from '${module}';
82
+ export type Entry = ContentEntry<${name}>;`;
83
+ })() : `import type { ContentEntry } from '@ecopages/content-processor/types';
84
+
85
+ export type Entry = ContentEntry<Record<string, unknown>>;`;
86
+ return `declare module "ecopages:content/${collectionName}" {
87
+ import type { EcoComponent } from '@ecopages/core';
88
+
89
+ ${entryDeclaration}
90
+
91
+ export const entries: readonly Entry[];
92
+ export function getEntry(slug: string): Entry;
93
+ export function getEntryBySegments(segments: string[]): Entry;
94
+ export function getComponent(slug: string): EcoComponent<Record<string, unknown>>;
95
+ }`;
96
+ }
97
+ function renderVirtualModuleTypes(collections, typeResolution) {
98
+ return `/**
99
+ * Do not edit manually. This file is auto-generated.
100
+ * Virtual module types for ecopages:content/* imports.
101
+ */
102
+
103
+ ${Object.entries(collections).map(([name, definition]) => renderCollectionTypesModule(name, definition.entryType, typeResolution)).join("\n\n")}
104
+ `;
105
+ }
106
+ export {
107
+ renderCollectionModule,
108
+ renderCollectionTypesModule,
109
+ renderVirtualModuleTypes
110
+ };
@@ -0,0 +1,28 @@
1
+ import type { StandardSchema } from '@ecopages/core';
2
+ import type { EntryComparator } from './sort.js';
3
+ /**
4
+ * Declares one content collection scanned at build time.
5
+ * Collection keys become virtual module paths: `ecopages:content/<key>`.
6
+ */
7
+ export type ContentCollectionDefinition<TFrontmatter extends Record<string, unknown> = Record<string, unknown>> = {
8
+ /** Directory relative to the app `srcDir`, e.g. `content/docs`. */
9
+ contentDir: string;
10
+ /** Standard Schema validator for frontmatter (Zod, Valibot, ArkType, etc.). */
11
+ schema: StandardSchema<unknown, TFrontmatter>;
12
+ orderBy?: EntryComparator<TFrontmatter>;
13
+ /** File extensions treated as content. Defaults to `['.mdx']`. */
14
+ extensions?: string[];
15
+ /**
16
+ * Frontmatter type for generated `ecopages:content/<collection>` modules.
17
+ * The processor wraps it with {@link ContentEntry} (`slug` and `segments` come from the library).
18
+ * Format: `./path/to/schema-file#ExportedTypeName`
19
+ */
20
+ entryType?: string;
21
+ };
22
+ /**
23
+ * Collection registry keyed by collection name.
24
+ */
25
+ export type ContentCollectionsConfig = Record<string, ContentCollectionDefinition>;
26
+ export type ContentProcessorConfig = {
27
+ collections: ContentCollectionsConfig;
28
+ };
File without changes
@@ -0,0 +1,8 @@
1
+ /** Processor registry name and generated artifact namespace. */
2
+ export declare const CONTENT_PROCESSOR_NAME = "ecopages-content-processor";
3
+ /** Virtual module prefix for collection imports, e.g. `ecopages:content/docs`. */
4
+ export declare const CONTENT_VIRTUAL_MODULE_PREFIX = "ecopages:content";
5
+ /** Matches `ecopages:content/<collection>` collection specifiers. */
6
+ export declare const CONTENT_VIRTUAL_MODULE_PATTERN: RegExp;
7
+ /** Validates collection keys used in processor options and virtual module paths. */
8
+ export declare const COLLECTION_NAME_PATTERN: RegExp;
@@ -0,0 +1,10 @@
1
+ const CONTENT_PROCESSOR_NAME = "ecopages-content-processor";
2
+ const CONTENT_VIRTUAL_MODULE_PREFIX = "ecopages:content";
3
+ const CONTENT_VIRTUAL_MODULE_PATTERN = /^ecopages:content\/[a-z][a-z0-9-]*$/;
4
+ const COLLECTION_NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
5
+ export {
6
+ COLLECTION_NAME_PATTERN,
7
+ CONTENT_PROCESSOR_NAME,
8
+ CONTENT_VIRTUAL_MODULE_PATTERN,
9
+ CONTENT_VIRTUAL_MODULE_PREFIX
10
+ };
@@ -0,0 +1,7 @@
1
+ import type { EcoBuildPlugin } from '@ecopages/core/plugins/processor';
2
+ declare function parseCollectionName(specifier: string): string | null;
3
+ declare function resolveCollectionPath(specifier: string, collectionModules: Record<string, string>): string | null;
4
+ export declare function createContentPlugin(collectionModules: Record<string, string>): EcoBuildPlugin;
5
+ export declare function createContentPluginBundler(collectionModules: Record<string, string>): EcoBuildPlugin;
6
+ export declare function getCollectionCachePath(cacheDir: string, collectionName: string): string;
7
+ export { parseCollectionName, resolveCollectionPath };
@@ -0,0 +1,64 @@
1
+ import path from "node:path";
2
+ import { fileSystem } from "@ecopages/file-system";
3
+ import { CONTENT_VIRTUAL_MODULE_PATTERN } from "./constants.js";
4
+ function parseCollectionName(specifier) {
5
+ if (specifier.startsWith("ecopages:content/")) {
6
+ return specifier.slice("ecopages:content/".length);
7
+ }
8
+ if (specifier.startsWith("content/")) {
9
+ return specifier.slice("content/".length);
10
+ }
11
+ return null;
12
+ }
13
+ function resolveCollectionPath(specifier, collectionModules) {
14
+ const collectionName = parseCollectionName(specifier);
15
+ if (!collectionName) {
16
+ return null;
17
+ }
18
+ return collectionModules[collectionName] ?? null;
19
+ }
20
+ function createContentPlugin(collectionModules) {
21
+ return {
22
+ name: "ecopages:content",
23
+ setup(build) {
24
+ build.onResolve({ filter: CONTENT_VIRTUAL_MODULE_PATTERN }, (args) => {
25
+ const modulePath = resolveCollectionPath(args.path, collectionModules);
26
+ if (!modulePath) {
27
+ return void 0;
28
+ }
29
+ return { path: modulePath };
30
+ });
31
+ }
32
+ };
33
+ }
34
+ function createContentPluginBundler(collectionModules) {
35
+ return {
36
+ name: "ecopages:content",
37
+ setup(build) {
38
+ build.onResolve({ filter: CONTENT_VIRTUAL_MODULE_PATTERN }, (args) => {
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
+ });
48
+ build.onLoad({ filter: /.*/, namespace: "ecopages-content" }, async (args) => {
49
+ const contents = await fileSystem.readFile(args.path);
50
+ return { contents, loader: "ts" };
51
+ });
52
+ }
53
+ };
54
+ }
55
+ function getCollectionCachePath(cacheDir, collectionName) {
56
+ return path.join(cacheDir, `${collectionName}.ts`);
57
+ }
58
+ export {
59
+ createContentPlugin,
60
+ createContentPluginBundler,
61
+ getCollectionCachePath,
62
+ parseCollectionName,
63
+ resolveCollectionPath
64
+ };
@@ -0,0 +1,33 @@
1
+ import { type StandardSchema } from '@ecopages/core';
2
+ import { type EntryComparator } from './sort.js';
3
+ import type { ContentEntry } from './types.js';
4
+ export type ContentScannerConfig<T extends Record<string, unknown> = Record<string, unknown>> = {
5
+ /** Absolute directory scanned for content files. */
6
+ contentRoot: string;
7
+ /** Standard Schema validator for frontmatter. */
8
+ schema: StandardSchema<unknown, T>;
9
+ orderBy?: EntryComparator<T>;
10
+ extensions?: string[];
11
+ };
12
+ /**
13
+ * Scans a content directory and exposes manifest metadata plus source file paths.
14
+ * Used by the content processor at build time; it does not belong in page bundles.
15
+ */
16
+ export declare class ContentScanner<T extends Record<string, unknown> = Record<string, unknown>> {
17
+ private readonly config;
18
+ private readonly extensions;
19
+ private readonly orderBy;
20
+ private readonly schema;
21
+ private cachePromise?;
22
+ constructor(config: ContentScannerConfig<T>);
23
+ clearCache(): void;
24
+ private parseFrontmatter;
25
+ private loadCache;
26
+ private getCache;
27
+ getManifest(): Promise<ContentEntry<T>[]>;
28
+ getRawContent(slug: string): Promise<string>;
29
+ getEntrySources(): Promise<Array<{
30
+ entry: ContentEntry<T>;
31
+ filePath: string;
32
+ }>>;
33
+ }
@@ -0,0 +1,88 @@
1
+ import { join, sep } from "node:path";
2
+ import { validateStandardSchema } from "@ecopages/core";
3
+ import { VFile } from "vfile";
4
+ import { matter } from "vfile-matter";
5
+ import { fileSystem } from "@ecopages/file-system";
6
+ import { compareEntriesBySlug } from "./sort.js";
7
+ function slugFromRelativePath(relativePath, extensions) {
8
+ for (const ext of extensions) {
9
+ if (relativePath.endsWith(ext)) {
10
+ return relativePath.slice(0, -ext.length).split(sep).join("/");
11
+ }
12
+ }
13
+ return relativePath.split(sep).join("/");
14
+ }
15
+ class ContentScanner {
16
+ constructor(config) {
17
+ this.config = config;
18
+ this.extensions = config.extensions ?? [".mdx"];
19
+ this.orderBy = config.orderBy ?? compareEntriesBySlug;
20
+ this.schema = config.schema;
21
+ }
22
+ config;
23
+ extensions;
24
+ orderBy;
25
+ schema;
26
+ cachePromise;
27
+ clearCache() {
28
+ this.cachePromise = void 0;
29
+ }
30
+ async parseFrontmatter(raw) {
31
+ const file = new VFile({ value: raw });
32
+ matter(file);
33
+ return validateStandardSchema(this.schema, file.data.matter);
34
+ }
35
+ async loadCache() {
36
+ const patterns = this.extensions.map((ext) => `**/*${ext}`);
37
+ const relativePaths = await fileSystem.glob(patterns, { cwd: this.config.contentRoot });
38
+ const files = await Promise.all(
39
+ relativePaths.map(async (relativePath) => {
40
+ const filePath = join(this.config.contentRoot, relativePath);
41
+ const slug = slugFromRelativePath(relativePath, this.extensions);
42
+ const raw = await fileSystem.readFile(filePath);
43
+ const entry = {
44
+ ...await this.parseFrontmatter(raw),
45
+ slug,
46
+ segments: slug.split("/")
47
+ };
48
+ return { filePath, entry };
49
+ })
50
+ );
51
+ files.sort((a, b) => this.orderBy(a.entry, b.entry));
52
+ const filePathsBySlug = /* @__PURE__ */ new Map();
53
+ for (const { entry, filePath } of files) {
54
+ filePathsBySlug.set(entry.slug, filePath);
55
+ }
56
+ return {
57
+ manifest: files.map((file) => file.entry),
58
+ filePathsBySlug
59
+ };
60
+ }
61
+ async getCache() {
62
+ if (!this.cachePromise) {
63
+ this.cachePromise = this.loadCache();
64
+ }
65
+ return this.cachePromise;
66
+ }
67
+ async getManifest() {
68
+ return (await this.getCache()).manifest;
69
+ }
70
+ async getRawContent(slug) {
71
+ const cache = await this.getCache();
72
+ const filePath = cache.filePathsBySlug.get(slug);
73
+ if (!filePath) {
74
+ throw new Error(`Unknown content entry: ${slug}`);
75
+ }
76
+ return fileSystem.readFile(filePath);
77
+ }
78
+ async getEntrySources() {
79
+ const cache = await this.getCache();
80
+ return cache.manifest.map((entry) => ({
81
+ entry,
82
+ filePath: cache.filePathsBySlug.get(entry.slug)
83
+ }));
84
+ }
85
+ }
86
+ export {
87
+ ContentScanner
88
+ };
package/src/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { ContentScanner } from './content-scanner.js';
2
+ export type { ContentScannerConfig } from './content-scanner.js';
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
+ export { compareEntriesByField, compareEntriesBySlug, type EntryComparator } from './sort.js';
6
+ export type { ContentCollectionDefinition, ContentCollectionsConfig, ContentProcessorConfig, } from './collection-types.js';
7
+ export type { StandardSchema } from '@ecopages/core';
8
+ export type { ContentCollectionModule, ContentEntry, EntryComparator as OrderBy } from './types.js';
package/src/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import { ContentScanner } from "./content-scanner.js";
2
+ import {
3
+ CONTENT_PROCESSOR_NAME,
4
+ CONTENT_VIRTUAL_MODULE_PATTERN,
5
+ CONTENT_VIRTUAL_MODULE_PREFIX,
6
+ COLLECTION_NAME_PATTERN
7
+ } from "./constants.js";
8
+ import { contentProcessorPlugin, ContentProcessorPlugin } from "./plugin.js";
9
+ import { compareEntriesByField, compareEntriesBySlug } from "./sort.js";
10
+ export {
11
+ COLLECTION_NAME_PATTERN,
12
+ CONTENT_PROCESSOR_NAME,
13
+ CONTENT_VIRTUAL_MODULE_PATTERN,
14
+ CONTENT_VIRTUAL_MODULE_PREFIX,
15
+ ContentProcessorPlugin,
16
+ ContentScanner,
17
+ compareEntriesByField,
18
+ compareEntriesBySlug,
19
+ contentProcessorPlugin
20
+ };
package/src/mdx.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import remarkFrontmatter from 'remark-frontmatter';
2
+ import type { PluggableList } from 'unified';
3
+ export { default as remarkFrontmatter } from 'remark-frontmatter';
4
+ export type ContentMdxPluginsOptions = {
5
+ /** Remark plugins appended after `remark-frontmatter`. */
6
+ remarkPlugins?: PluggableList;
7
+ /** Rehype plugins for the MDX pipeline. */
8
+ rehypePlugins?: PluggableList;
9
+ };
10
+ /**
11
+ * Builds MDX plugin options for content collections that use YAML frontmatter.
12
+ *
13
+ * Prepends `remark-frontmatter` so `---` blocks are consumed at compile time
14
+ * instead of rendering as thematic breaks. Pair this with
15
+ * `contentProcessorPlugin()` — the processor validates frontmatter at scan time;
16
+ * this helper wires the matching MDX remark plugin for render time.
17
+ */
18
+ export declare function withContentMdxPlugins(options?: ContentMdxPluginsOptions): {
19
+ remarkPlugins: (typeof remarkFrontmatter | import("unified").Pluggable)[];
20
+ rehypePlugins: PluggableList;
21
+ };
package/src/mdx.js ADDED
@@ -0,0 +1,12 @@
1
+ import remarkFrontmatter from "remark-frontmatter";
2
+ import { default as default2 } from "remark-frontmatter";
3
+ function withContentMdxPlugins(options = {}) {
4
+ return {
5
+ remarkPlugins: [remarkFrontmatter, ...options.remarkPlugins ?? []],
6
+ rehypePlugins: options.rehypePlugins ?? []
7
+ };
8
+ }
9
+ export {
10
+ default2 as remarkFrontmatter,
11
+ withContentMdxPlugins
12
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * ContentProcessorPlugin
3
+ * @module @ecopages/content-processor
4
+ */
5
+ import { Processor, type EcoBuildPlugin, type ProcessorConfig } from '@ecopages/core/plugins/processor';
6
+ import type { ContentProcessorConfig } from './collection-types.js';
7
+ /**
8
+ * Build-time processor that scans configured content collections and exposes
9
+ * each one as `ecopages:content/<collection>` virtual modules.
10
+ */
11
+ export declare class ContentProcessorPlugin extends Processor<ContentProcessorConfig> {
12
+ private collectionsGenerated;
13
+ private readonly scanners;
14
+ /**
15
+ * Absolute paths to generated collection modules, keyed by collection name.
16
+ * Virtual-module plugins close over this object so mutations stay live.
17
+ */
18
+ readonly collectionModules: Record<string, string>;
19
+ constructor(config: Omit<ProcessorConfig<ContentProcessorConfig>, 'name' | 'description'>);
20
+ get buildPlugins(): EcoBuildPlugin[];
21
+ get plugins(): EcoBuildPlugin[];
22
+ private getCollectionsConfig;
23
+ private getCollectionContentRoot;
24
+ private writeGeneratedFile;
25
+ private getOrCreateScanner;
26
+ private regenerateCollectionModule;
27
+ private regenerateCollections;
28
+ private regenerateAllCollections;
29
+ private regenerateCollectionsForPath;
30
+ private initializeWatchPaths;
31
+ private generateTypes;
32
+ private ensureCollectionsGenerated;
33
+ prepareBuildContributions(): Promise<void>;
34
+ setup(): Promise<void>;
35
+ process(_input: unknown): Promise<void>;
36
+ }
37
+ export declare const contentProcessorPlugin: (config: Omit<ProcessorConfig<ContentProcessorConfig>, "name" | "description">) => ContentProcessorPlugin;
package/src/plugin.js ADDED
@@ -0,0 +1,196 @@
1
+ import path from "node:path";
2
+ import { fileSystem } from "@ecopages/file-system";
3
+ import {
4
+ mergeProcessorOptions,
5
+ Processor,
6
+ resolveGeneratedPath
7
+ } from "@ecopages/core/plugins/processor";
8
+ import { Logger } from "@ecopages/logger";
9
+ import { renderCollectionModule, renderVirtualModuleTypes } from "./codegen.js";
10
+ import { compareEntriesBySlug } from "./sort.js";
11
+ import { ContentScanner } from "./content-scanner.js";
12
+ import { createContentPlugin, createContentPluginBundler, getCollectionCachePath } from "./content-plugins.js";
13
+ import { COLLECTION_NAME_PATTERN, CONTENT_PROCESSOR_NAME } from "./constants.js";
14
+ const logger = new Logger("[@ecopages/content-processor]", {
15
+ debug: process.env.ECOPAGES_LOGGER_DEBUG === "true"
16
+ });
17
+ function assertValidCollectionName(collectionName) {
18
+ if (!COLLECTION_NAME_PATTERN.test(collectionName)) {
19
+ throw new Error(
20
+ `Invalid content collection name "${collectionName}". Use kebab-case identifiers matching ${COLLECTION_NAME_PATTERN}.`
21
+ );
22
+ }
23
+ }
24
+ class ContentProcessorPlugin extends Processor {
25
+ collectionsGenerated = false;
26
+ scanners = /* @__PURE__ */ new Map();
27
+ /**
28
+ * Absolute paths to generated collection modules, keyed by collection name.
29
+ * Virtual-module plugins close over this object so mutations stay live.
30
+ */
31
+ collectionModules = {};
32
+ constructor(config) {
33
+ const defaultWatchConfig = {
34
+ paths: [],
35
+ extensions: ["mdx"],
36
+ onCreate: async (ctx) => this.regenerateCollectionsForPath(ctx.path),
37
+ onChange: async (ctx) => this.regenerateCollectionsForPath(ctx.path),
38
+ onDelete: async (ctx) => this.regenerateCollectionsForPath(ctx.path)
39
+ };
40
+ super({
41
+ ...config,
42
+ name: CONTENT_PROCESSOR_NAME,
43
+ description: "Build-time content collections exposed as ecopages:content/* virtual modules.",
44
+ watch: config.watch ? mergeProcessorOptions(defaultWatchConfig, config.watch) : defaultWatchConfig
45
+ });
46
+ }
47
+ get buildPlugins() {
48
+ return [createContentPluginBundler(this.collectionModules)];
49
+ }
50
+ get plugins() {
51
+ return [createContentPlugin(this.collectionModules)];
52
+ }
53
+ getCollectionsConfig() {
54
+ if (!this.options?.collections) {
55
+ throw new Error("Content processor requires `options.collections`");
56
+ }
57
+ return this.options.collections;
58
+ }
59
+ getCollectionContentRoot(contentDir) {
60
+ if (!this.context) {
61
+ throw new Error("Content processor requires context to be set");
62
+ }
63
+ return path.join(this.context.srcDir, contentDir);
64
+ }
65
+ writeGeneratedFile(filePath, content) {
66
+ fileSystem.ensureDir(path.dirname(filePath));
67
+ if (fileSystem.exists(filePath) && fileSystem.readFileSync(filePath) === content) {
68
+ return;
69
+ }
70
+ fileSystem.write(filePath, content);
71
+ }
72
+ getOrCreateScanner(collectionName) {
73
+ const existing = this.scanners.get(collectionName);
74
+ if (existing) {
75
+ return existing;
76
+ }
77
+ const definition = this.getCollectionsConfig()[collectionName];
78
+ if (!definition) {
79
+ throw new Error(`Unknown content collection: ${collectionName}`);
80
+ }
81
+ const scanner = new ContentScanner({
82
+ contentRoot: this.getCollectionContentRoot(definition.contentDir),
83
+ orderBy: definition.orderBy ?? compareEntriesBySlug,
84
+ extensions: definition.extensions,
85
+ schema: definition.schema
86
+ });
87
+ this.scanners.set(collectionName, scanner);
88
+ return scanner;
89
+ }
90
+ async regenerateCollectionModule(collectionName) {
91
+ if (!this.context?.cache) {
92
+ throw new Error("Content processor requires context to be set");
93
+ }
94
+ assertValidCollectionName(collectionName);
95
+ const definition = this.getCollectionsConfig()[collectionName];
96
+ if (!definition) {
97
+ return;
98
+ }
99
+ const scanner = this.getOrCreateScanner(collectionName);
100
+ scanner.clearCache();
101
+ const entrySources = await scanner.getEntrySources();
102
+ const manifest = entrySources.map(({ entry }) => entry);
103
+ const outputFile = getCollectionCachePath(this.context.cache, collectionName);
104
+ const outputDir = path.dirname(outputFile);
105
+ const output = renderCollectionModule(collectionName, outputDir, manifest, entrySources);
106
+ this.writeGeneratedFile(outputFile, output);
107
+ this.collectionModules[collectionName] = outputFile;
108
+ logger.debug("Generated content collection module", {
109
+ collectionName,
110
+ outputFile,
111
+ entryCount: manifest.length
112
+ });
113
+ }
114
+ async regenerateCollections(collectionNames) {
115
+ for (const collectionName of collectionNames) {
116
+ await this.regenerateCollectionModule(collectionName);
117
+ }
118
+ this.generateTypes();
119
+ }
120
+ async regenerateAllCollections() {
121
+ await this.regenerateCollections(Object.keys(this.getCollectionsConfig()));
122
+ }
123
+ async regenerateCollectionsForPath(filePath) {
124
+ if (!this.context) {
125
+ return;
126
+ }
127
+ const normalizedPath = path.normalize(filePath);
128
+ const affectedCollections = [];
129
+ for (const [collectionName, definition] of Object.entries(this.getCollectionsConfig())) {
130
+ const contentRoot = this.getCollectionContentRoot(definition.contentDir);
131
+ if (normalizedPath.startsWith(contentRoot + path.sep) || normalizedPath === contentRoot) {
132
+ affectedCollections.push(collectionName);
133
+ }
134
+ }
135
+ if (affectedCollections.length > 0) {
136
+ await this.regenerateCollections(affectedCollections);
137
+ }
138
+ }
139
+ initializeWatchPaths() {
140
+ if (!this.watchConfig || !this.context) {
141
+ return;
142
+ }
143
+ this.watchConfig.paths = Object.values(this.getCollectionsConfig()).map(
144
+ (definition) => this.getCollectionContentRoot(definition.contentDir)
145
+ );
146
+ }
147
+ generateTypes() {
148
+ if (!this.context) {
149
+ throw new Error("Content processor requires context to be set");
150
+ }
151
+ const collectionNames = Object.keys(this.getCollectionsConfig());
152
+ for (const collectionName of collectionNames) {
153
+ assertValidCollectionName(collectionName);
154
+ }
155
+ const typesDir = resolveGeneratedPath("types", {
156
+ root: this.context.rootDir,
157
+ module: this.name,
158
+ subPath: "virtual-module.d.ts"
159
+ });
160
+ const content = renderVirtualModuleTypes(this.getCollectionsConfig(), {
161
+ rootDir: this.context.rootDir,
162
+ typesOutputFile: typesDir
163
+ });
164
+ this.writeGeneratedFile(typesDir, content);
165
+ const indexTypesDir = resolveGeneratedPath("types", {
166
+ root: this.context.rootDir,
167
+ module: this.name,
168
+ subPath: "index.d.ts"
169
+ });
170
+ this.writeGeneratedFile(indexTypesDir, 'import "./virtual-module.d.js";\n');
171
+ }
172
+ async ensureCollectionsGenerated() {
173
+ if (this.collectionsGenerated) {
174
+ return;
175
+ }
176
+ this.initializeWatchPaths();
177
+ await this.regenerateAllCollections();
178
+ this.collectionsGenerated = true;
179
+ }
180
+ async prepareBuildContributions() {
181
+ await this.ensureCollectionsGenerated();
182
+ }
183
+ async setup() {
184
+ await this.ensureCollectionsGenerated();
185
+ }
186
+ async process(_input) {
187
+ await this.regenerateAllCollections();
188
+ }
189
+ }
190
+ const contentProcessorPlugin = (config) => {
191
+ return new ContentProcessorPlugin(config);
192
+ };
193
+ export {
194
+ ContentProcessorPlugin,
195
+ contentProcessorPlugin
196
+ };
package/src/sort.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { ContentEntry } from './types.js';
2
+ export type EntryComparator<T extends Record<string, unknown> = Record<string, unknown>> = (a: ContentEntry<T>, b: ContentEntry<T>) => number;
3
+ /** Default manifest sort: slug segments in path order. */
4
+ export declare function compareEntriesBySlug<T extends Record<string, unknown>>(a: ContentEntry<T>, b: ContentEntry<T>): number;
5
+ /**
6
+ * Sort by a validated frontmatter field.
7
+ *
8
+ * @remarks
9
+ * The caller must ensure the field exists on entries validated by the collection schema.
10
+ */
11
+ export declare function compareEntriesByField<T extends Record<string, unknown>, K extends keyof T>(field: K): EntryComparator<T>;
package/src/sort.js ADDED
@@ -0,0 +1,20 @@
1
+ function compareEntriesBySlug(a, b) {
2
+ return a.slug.localeCompare(b.slug);
3
+ }
4
+ function compareEntriesByField(field) {
5
+ return (a, b) => {
6
+ const left = a[field];
7
+ const right = b[field];
8
+ if (typeof left === "number" && typeof right === "number") {
9
+ return left - right || compareEntriesBySlug(a, b);
10
+ }
11
+ if (typeof left === "string" && typeof right === "string") {
12
+ return left.localeCompare(right) || compareEntriesBySlug(a, b);
13
+ }
14
+ return compareEntriesBySlug(a, b);
15
+ };
16
+ }
17
+ export {
18
+ compareEntriesByField,
19
+ compareEntriesBySlug
20
+ };
package/src/types.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { EcoComponent } from '@ecopages/core';
2
+ import type { EntryComparator } from './sort.js';
3
+ export type { EntryComparator } from './sort.js';
4
+ /**
5
+ * Content entry metadata produced by the content processor.
6
+ * Frontmatter fields come from the collection schema declared in processor config.
7
+ */
8
+ export type ContentEntry<T extends Record<string, unknown> = Record<string, unknown>> = T & {
9
+ /** Joined slug segments, e.g. `getting-started/introduction`. */
10
+ slug: string;
11
+ /** Path segments relative to the content root, e.g. `['getting-started', 'introduction']`. */
12
+ segments: string[];
13
+ };
14
+ /** @deprecated Use {@link EntryComparator} instead. */
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 ContentCollectionModule<TEntry extends Record<string, unknown> = Record<string, unknown>> = {
18
+ readonly entries: readonly ContentEntry<TEntry>[];
19
+ getEntry(slug: string): ContentEntry<TEntry>;
20
+ getEntryBySegments(segments: string[]): ContentEntry<TEntry>;
21
+ getComponent(slug: string): EcoComponent<Record<string, unknown>>;
22
+ };
package/src/types.js ADDED
File without changes