nuxt-ai-ready 0.3.1 → 0.3.2
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/dist/module.json
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import routes from "#ai-ready/routes.mjs";
|
|
2
2
|
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
3
|
export { jsonResult } from "../utils.js";
|
|
4
|
+
function routeToRegex(routePath) {
|
|
5
|
+
const pattern = routePath.replace(/:[^/]+\(\.\*\)\*?/g, ".*").replace(/:[^/]+/g, "[^/]+");
|
|
6
|
+
return new RegExp(`^${pattern}$`);
|
|
7
|
+
}
|
|
8
|
+
function matchRoute(path, routeRecords) {
|
|
9
|
+
for (const r of routeRecords) {
|
|
10
|
+
if (routeToRegex(r.path).test(path))
|
|
11
|
+
return r;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
4
14
|
export async function getDevPages() {
|
|
5
15
|
const config = useRuntimeConfig()["nuxt-ai-ready"];
|
|
6
16
|
if (!config.hasSitemap)
|
|
@@ -12,11 +22,13 @@ export async function getDevPages() {
|
|
|
12
22
|
const xml = await sitemapRes.text();
|
|
13
23
|
const { urls } = await parseSitemapXml(xml);
|
|
14
24
|
return urls.map((entry) => {
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
const pathname = typeof entry === "string" ? new URL(entry).pathname : new URL(entry.loc).pathname;
|
|
26
|
+
const matched = matchRoute(pathname, routes);
|
|
17
27
|
return {
|
|
18
|
-
route:
|
|
19
|
-
lastmod: entry.lastmod
|
|
28
|
+
route: pathname,
|
|
29
|
+
...typeof entry !== "string" && entry.lastmod && { lastmod: entry.lastmod },
|
|
30
|
+
...matched?.name && { name: matched.name },
|
|
31
|
+
...matched?.meta && { meta: matched.meta }
|
|
20
32
|
};
|
|
21
33
|
});
|
|
22
34
|
}
|