@monkeyplus/flow 6.0.90 → 6.0.91
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.
|
@@ -24,5 +24,4 @@ export declare function readContentEntries(): Promise<ContentEntry[]>;
|
|
|
24
24
|
export declare function buildContentTree(entries: ContentEntry[]): ContentTreeNode[];
|
|
25
25
|
export declare function findContentTree(tree: ContentTreeNode[], path?: string): ContentTreeNode[];
|
|
26
26
|
export declare function processContentQuery(entries: ContentEntry[], query: Record<string, any>, allEntries: ContentEntry[]): ContentEntry[];
|
|
27
|
-
|
|
28
|
-
export default _default;
|
|
27
|
+
export default function (event: any): Promise<ContentTreeNode[] | ContentEntry[]>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { extname } from "node:path";
|
|
2
2
|
import { consola } from "consola";
|
|
3
|
-
import { defineEventHandler, getQuery, getRequestURL } from "nitro/h3";
|
|
4
|
-
import { useStorage } from "nitro/storage";
|
|
5
3
|
function normalizeQueryPath(path) {
|
|
6
4
|
if (!path || path === "/") {
|
|
7
5
|
return "/";
|
|
@@ -126,57 +124,62 @@ export async function readContentEntries() {
|
|
|
126
124
|
}
|
|
127
125
|
return entries2;
|
|
128
126
|
};
|
|
129
|
-
const storage = useStorage("content");
|
|
130
|
-
const keys = await storage.getKeys();
|
|
131
127
|
const entries = [];
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const normalizedKey = relativePath.replace(/\\/g, "/");
|
|
148
|
-
const raw = await fs.readFile(res, "utf-8");
|
|
149
|
-
const entry = parseContentFile(normalizedKey, raw);
|
|
150
|
-
entries.push(entry);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
128
|
+
try {
|
|
129
|
+
const { useStorage } = await import("nitro/storage");
|
|
130
|
+
const storage = useStorage("content");
|
|
131
|
+
const keys = await storage.getKeys();
|
|
132
|
+
if (keys.length > 0) {
|
|
133
|
+
for (const key of keys) {
|
|
134
|
+
const normalizedKey = key.replace(/:/g, "/");
|
|
135
|
+
const extension = extname(normalizedKey).toLowerCase();
|
|
136
|
+
if (![".md", ".json", ".yml", ".yaml", ".txt"].includes(extension)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const raw = await storage.getItem(key);
|
|
140
|
+
if (raw !== null && raw !== void 0) {
|
|
141
|
+
const entry = parseContentFile(normalizedKey, raw);
|
|
142
|
+
entries.push(entry);
|
|
153
143
|
}
|
|
154
144
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
await walkDir(contentDir, contentDir);
|
|
158
|
-
} catch (e) {
|
|
159
|
-
}
|
|
160
|
-
const sorted = entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
161
|
-
return applyCmsPreview(sorted);
|
|
162
|
-
} catch (e) {
|
|
163
|
-
consola.error("[Flow Content] fs fallback failed:", e);
|
|
145
|
+
const sortedEntries = entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
146
|
+
return applyCmsPreview(sortedEntries);
|
|
164
147
|
}
|
|
148
|
+
} catch (e) {
|
|
165
149
|
}
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
150
|
+
try {
|
|
151
|
+
const fs = await import("node:fs/promises");
|
|
152
|
+
const path = await import("node:path");
|
|
153
|
+
const contentDir = path.resolve(process.cwd(), "content");
|
|
154
|
+
async function walkDir(dir, baseDir) {
|
|
155
|
+
const files = await fs.readdir(dir, { withFileTypes: true });
|
|
156
|
+
for (const file of files) {
|
|
157
|
+
const res = path.resolve(dir, file.name);
|
|
158
|
+
if (file.isDirectory()) {
|
|
159
|
+
await walkDir(res, baseDir);
|
|
160
|
+
} else {
|
|
161
|
+
const extension = path.extname(res).toLowerCase();
|
|
162
|
+
if ([".md", ".json", ".yml", ".yaml", ".txt"].includes(extension)) {
|
|
163
|
+
const relativePath = path.relative(baseDir, res);
|
|
164
|
+
const normalizedKey = relativePath.replace(/\\/g, "/");
|
|
165
|
+
const raw = await fs.readFile(res, "utf-8");
|
|
166
|
+
const entry = parseContentFile(normalizedKey, raw);
|
|
167
|
+
entries.push(entry);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
171
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
try {
|
|
173
|
+
await fs.access(contentDir);
|
|
174
|
+
await walkDir(contentDir, contentDir);
|
|
175
|
+
} catch (e) {
|
|
176
176
|
}
|
|
177
|
+
const sorted = entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
178
|
+
return applyCmsPreview(sorted);
|
|
179
|
+
} catch (e) {
|
|
180
|
+
consola.error("[Flow Content] fs fallback failed:", e);
|
|
177
181
|
}
|
|
178
|
-
|
|
179
|
-
return applyCmsPreview(sortedEntries);
|
|
182
|
+
return applyCmsPreview(entries);
|
|
180
183
|
}
|
|
181
184
|
function sortTree(nodes) {
|
|
182
185
|
nodes.sort((left, right) => {
|
|
@@ -371,7 +374,8 @@ export function processContentQuery(entries, query, allEntries) {
|
|
|
371
374
|
}
|
|
372
375
|
return entries;
|
|
373
376
|
}
|
|
374
|
-
export default
|
|
377
|
+
export default async function(event) {
|
|
378
|
+
const { getQuery, getRequestURL } = await import("nitro/h3");
|
|
375
379
|
const query = getQuery(event);
|
|
376
380
|
const requestUrl = getRequestURL(event);
|
|
377
381
|
const isTreeRequest = requestUrl.pathname.endsWith("/tree") || query.tree === true || query.tree === "true" || query.tree === "1";
|
|
@@ -385,4 +389,4 @@ export default defineEventHandler(async (event) => {
|
|
|
385
389
|
entries = findContentEntries(entries, query.path);
|
|
386
390
|
}
|
|
387
391
|
return processContentQuery(entries, query, allEntries);
|
|
388
|
-
}
|
|
392
|
+
}
|
|
Binary file
|