@gravito/monolith 1.0.0-alpha.2 → 1.0.0-alpha.6
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.zh-TW.md +35 -0
- package/dist/index.js +1 -0
- package/dist/src/index.js +32 -4
- package/ion/src/index.js +4631 -0
- package/package.json +2 -2
- package/signal/src/index.js +101809 -0
- package/src/ContentManager.ts +23 -7
- package/src/index.ts +1 -0
package/src/ContentManager.ts
CHANGED
|
@@ -21,20 +21,31 @@ export class ContentManager {
|
|
|
21
21
|
// Simple memory cache: collection:locale:slug -> ContentItem
|
|
22
22
|
private cache = new Map<string, ContentItem>()
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Create a new ContentManager instance.
|
|
26
|
+
*
|
|
27
|
+
* @param rootDir - The root directory of the application.
|
|
28
|
+
*/
|
|
24
29
|
constructor(private rootDir: string) {}
|
|
25
30
|
|
|
26
31
|
/**
|
|
27
|
-
* Register a new content collection
|
|
32
|
+
* Register a new content collection.
|
|
33
|
+
*
|
|
34
|
+
* @param name - The name of the collection.
|
|
35
|
+
* @param config - The collection configuration.
|
|
28
36
|
*/
|
|
29
37
|
defineCollection(name: string, config: CollectionConfig) {
|
|
30
38
|
this.collections.set(name, config)
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
/**
|
|
34
|
-
* Find a single content item
|
|
35
|
-
*
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
42
|
+
* Find a single content item.
|
|
43
|
+
*
|
|
44
|
+
* @param collectionName - The collection name (e.g. 'docs').
|
|
45
|
+
* @param slug - The file slug (e.g. 'installation').
|
|
46
|
+
* @param locale - The locale (e.g. 'en'). Defaults to 'en'.
|
|
47
|
+
* @returns A promise resolving to the ContentItem or null if not found.
|
|
48
|
+
* @throws {Error} If the collection is not defined.
|
|
38
49
|
*/
|
|
39
50
|
async find(collectionName: string, slug: string, locale = 'en'): Promise<ContentItem | null> {
|
|
40
51
|
const config = this.collections.get(collectionName)
|
|
@@ -81,8 +92,13 @@ export class ContentManager {
|
|
|
81
92
|
}
|
|
82
93
|
|
|
83
94
|
/**
|
|
84
|
-
* List all items in a collection for a locale
|
|
85
|
-
* Useful for generating sitemaps or index pages
|
|
95
|
+
* List all items in a collection for a locale.
|
|
96
|
+
* Useful for generating sitemaps or index pages.
|
|
97
|
+
*
|
|
98
|
+
* @param collectionName - The collection name.
|
|
99
|
+
* @param locale - The locale. Defaults to 'en'.
|
|
100
|
+
* @returns A promise resolving to an array of ContentItems.
|
|
101
|
+
* @throws {Error} If the collection is not defined.
|
|
86
102
|
*/
|
|
87
103
|
async list(collectionName: string, locale = 'en'): Promise<ContentItem[]> {
|
|
88
104
|
const config = this.collections.get(collectionName)
|