@adonisjs/content 1.2.0 → 1.3.0
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.
|
@@ -70,10 +70,20 @@ var Collection = class _Collection {
|
|
|
70
70
|
static multi(sections, callback) {
|
|
71
71
|
return sections.reduce(
|
|
72
72
|
(result, section) => {
|
|
73
|
+
;
|
|
73
74
|
result[section] = callback(section);
|
|
74
75
|
return result;
|
|
75
76
|
},
|
|
76
|
-
{
|
|
77
|
+
{
|
|
78
|
+
async load() {
|
|
79
|
+
const views = {};
|
|
80
|
+
for (let section of sections) {
|
|
81
|
+
;
|
|
82
|
+
views[section] = await this[section].load();
|
|
83
|
+
}
|
|
84
|
+
return views;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
77
87
|
);
|
|
78
88
|
}
|
|
79
89
|
/**
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ApplicationService } from '@adonisjs/core/types';
|
|
2
2
|
declare module '@vinejs/vine' {
|
|
3
3
|
interface VineString {
|
|
4
|
+
toContents(): this;
|
|
4
5
|
/**
|
|
5
6
|
* Converts a relative path to a Vite asset path.
|
|
6
7
|
* This method transforms the path using Vite's asset resolution system.
|
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Collection
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-Q6QIMTOW.js";
|
|
4
4
|
import "../chunk-LB6JFRVG.js";
|
|
5
5
|
|
|
6
6
|
// providers/content_provider.ts
|
|
7
7
|
import { resolve } from "path";
|
|
8
8
|
import vine, { VineString } from "@vinejs/vine";
|
|
9
|
+
import { readFile } from "fs/promises";
|
|
9
10
|
var toVitePath = vine.createRule(function vitePath(value, _, field) {
|
|
10
|
-
|
|
11
|
+
if (typeof value === "string") {
|
|
12
|
+
field.mutate(
|
|
13
|
+
field.meta.vite.assetPath(value.replace(/^\.\/|^\//, "").replace(/\/$/, "")),
|
|
14
|
+
field
|
|
15
|
+
);
|
|
16
|
+
}
|
|
11
17
|
});
|
|
18
|
+
var toContents = vine.createRule(
|
|
19
|
+
async function vitePath2(value, _, field) {
|
|
20
|
+
if (typeof value === "string") {
|
|
21
|
+
const absolutePath2 = resolve(field.meta.menuFileRoot, value);
|
|
22
|
+
field.mutate(await readFile(absolutePath2, "utf-8"), field);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
isAsync: true
|
|
27
|
+
}
|
|
28
|
+
);
|
|
12
29
|
var toAbsolutePath = vine.createRule(function absolutePath(value, _, field) {
|
|
13
30
|
field.mutate(resolve(field.meta.menuFileRoot, value), field);
|
|
14
31
|
});
|
|
@@ -18,6 +35,9 @@ VineString.macro("toVitePath", function() {
|
|
|
18
35
|
VineString.macro("toAbsolutePath", function() {
|
|
19
36
|
return this.use(toAbsolutePath());
|
|
20
37
|
});
|
|
38
|
+
VineString.macro("toContents", function() {
|
|
39
|
+
return this.use(toContents());
|
|
40
|
+
});
|
|
21
41
|
var ContentProvider = class {
|
|
22
42
|
/**
|
|
23
43
|
* Creates a new instance of the content provider.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Vite } from '@adonisjs/vite';
|
|
2
2
|
import { type Infer, type SchemaTypes } from '@vinejs/vine/types';
|
|
3
3
|
import { type CollectionOptions, type ViewFn, type ViewsToQueryMethods } from './types.js';
|
|
4
|
+
import { type Prettify } from '@adonisjs/core/types/common';
|
|
4
5
|
/**
|
|
5
6
|
* Manages a collection of data with schema validation and custom view functions.
|
|
6
7
|
*
|
|
@@ -81,8 +82,14 @@ export declare class Collection<Schema extends SchemaTypes, Views extends Record
|
|
|
81
82
|
* // Results in: { api: Collection, guides: Collection, tutorials: Collection }
|
|
82
83
|
* ```
|
|
83
84
|
*/
|
|
84
|
-
static multi<Section extends string, Callback extends (section: Section) => any
|
|
85
|
+
static multi<Section extends string, Callback extends (section: Section) => Collection<any, any>>(sections: Section[], callback: Callback): {
|
|
85
86
|
[K in Section]: ReturnType<Callback>;
|
|
87
|
+
} & {
|
|
88
|
+
load(): Promise<{
|
|
89
|
+
[K in Section]: ReturnType<Callback> extends Collection<infer S, infer V> ? Prettify<{
|
|
90
|
+
all(): Infer<S>;
|
|
91
|
+
} & ViewsToQueryMethods<V>> : never;
|
|
92
|
+
}>;
|
|
86
93
|
};
|
|
87
94
|
/**
|
|
88
95
|
* Configures the Vite service instance for resolving asset paths.
|
|
@@ -129,7 +136,7 @@ export declare class Collection<Schema extends SchemaTypes, Views extends Record
|
|
|
129
136
|
* const post = query.findBySlug('hello-world')
|
|
130
137
|
* ```
|
|
131
138
|
*/
|
|
132
|
-
load(): Promise<{
|
|
139
|
+
load(): Promise<Prettify<{
|
|
133
140
|
all(): Infer<Schema>;
|
|
134
|
-
} & ViewsToQueryMethods<Views
|
|
141
|
+
} & ViewsToQueryMethods<Views>>>;
|
|
135
142
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/content",
|
|
3
3
|
"description": "Content management for AdonisJS with schema validation, GitHub loaders, and custom queries",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.0.0"
|
|
7
7
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"main": "build/index.js",
|
|
15
15
|
"exports": {
|
|
16
16
|
"./loaders": "./build/src/loaders/main.js",
|
|
17
|
-
"./types": "./build/types.js",
|
|
17
|
+
"./types": "./build/src/types.js",
|
|
18
18
|
"./content_provider": "./build/providers/content_provider.js",
|
|
19
19
|
".": "./build/index.js"
|
|
20
20
|
},
|