@adonisjs/content 1.6.0 → 1.6.1
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.
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
// src/collection.ts
|
|
6
6
|
var Collection = class _Collection {
|
|
7
7
|
static #vite;
|
|
8
|
+
static #app;
|
|
8
9
|
/** Collection configuration options */
|
|
9
10
|
#options;
|
|
10
11
|
/** Cached validated data */
|
|
@@ -100,6 +101,9 @@ var Collection = class _Collection {
|
|
|
100
101
|
static useVite(vite) {
|
|
101
102
|
this.#vite = vite;
|
|
102
103
|
}
|
|
104
|
+
static useApp(app) {
|
|
105
|
+
this.#app = app;
|
|
106
|
+
}
|
|
103
107
|
/**
|
|
104
108
|
* Loads and validates data using the configured loader and schema.
|
|
105
109
|
* Returns cached data if caching is enabled and data was previously loaded.
|
|
@@ -120,6 +124,7 @@ var Collection = class _Collection {
|
|
|
120
124
|
debug_default("computing data");
|
|
121
125
|
this.#data = await this.#options.loader.load(this.#options.schema, {
|
|
122
126
|
vite: _Collection.#vite,
|
|
127
|
+
app: _Collection.#app,
|
|
123
128
|
...this.#options.validatorMetaData
|
|
124
129
|
});
|
|
125
130
|
const views = this.#options.views ?? {};
|
package/build/index.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Collection
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-IGPZNVR2.js";
|
|
4
4
|
import "../chunk-LB6JFRVG.js";
|
|
5
5
|
|
|
6
6
|
// providers/content_provider.ts
|
|
7
|
-
import { resolve } from "path";
|
|
7
|
+
import { isAbsolute, resolve } from "path";
|
|
8
8
|
import vine, { VineString } from "@vinejs/vine";
|
|
9
9
|
import { readFile } from "fs/promises";
|
|
10
10
|
var toVitePath = vine.createRule(function vitePath(value, _, field) {
|
|
11
11
|
if (typeof value === "string") {
|
|
12
|
-
field.
|
|
13
|
-
|
|
14
|
-
field
|
|
15
|
-
);
|
|
12
|
+
value = isAbsolute(value) ? value : resolve(field.meta.menuFileRoot, value);
|
|
13
|
+
field.mutate(field.meta.vite.assetPath(field.meta.app.relativePath(value)), field);
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
var toContents = vine.createRule(
|
|
19
|
-
async function
|
|
17
|
+
async function contents(value, _, field) {
|
|
20
18
|
if (typeof value === "string") {
|
|
21
19
|
const absolutePath2 = resolve(field.meta.menuFileRoot, value);
|
|
22
20
|
field.mutate(await readFile(absolutePath2, "utf-8"), field);
|
|
@@ -54,6 +52,7 @@ var ContentProvider = class {
|
|
|
54
52
|
* the Collection class to use Vite's asset resolution system.
|
|
55
53
|
*/
|
|
56
54
|
async boot() {
|
|
55
|
+
Collection.useApp(this.app);
|
|
57
56
|
if (this.app.container.hasBinding("vite")) {
|
|
58
57
|
const vite = await this.app.container.make("vite");
|
|
59
58
|
Collection.useVite(vite);
|
|
@@ -2,6 +2,7 @@ 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
4
|
import { type Prettify } from '@adonisjs/core/types/common';
|
|
5
|
+
import { type Application } from '@adonisjs/core/app';
|
|
5
6
|
/**
|
|
6
7
|
* Manages a collection of data with schema validation and custom view functions.
|
|
7
8
|
*
|
|
@@ -103,6 +104,7 @@ export declare class Collection<Schema extends SchemaTypes, Views extends Record
|
|
|
103
104
|
* ```
|
|
104
105
|
*/
|
|
105
106
|
static useVite(vite: Vite): void;
|
|
107
|
+
static useApp(app: Application<any>): void;
|
|
106
108
|
/**
|
|
107
109
|
* Loads and validates data using the configured loader and schema.
|
|
108
110
|
* Returns cached data if caching is enabled and data was previously loaded.
|