@gravito/constellation 1.0.0-alpha.6 → 1.0.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.
- package/README.md +1 -1
- package/README.zh-TW.md +1 -1
- package/dist/DiskSitemapStorage-7ZZMGC4K.js +6 -0
- package/dist/chunk-7WHLC3OJ.js +56 -0
- package/dist/index.cjs +515 -254
- package/dist/index.d.cts +821 -0
- package/dist/index.d.ts +821 -0
- package/dist/{index.mjs → index.js} +413 -258
- package/package.json +21 -11
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ title: Constellation
|
|
|
4
4
|
|
|
5
5
|
# Constellation
|
|
6
6
|
|
|
7
|
-
Dynamic and static sitemap generation for Gravito applications.
|
|
7
|
+
Dynamic and static sitemap generation for Gravito applications. Constellation can be used standalone or as the sitemap and route-scanning engine for Luminosity.
|
|
8
8
|
|
|
9
9
|
**Constellation** provides a flexible way to generate XML sitemaps for your Gravito application, supporting both dynamic generation (via routes) and static generation (for build time). It includes support for Google Sitemap extensions like Images, Videos, News, and i18n alternates.
|
|
10
10
|
|
package/README.zh-TW.md
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/storage/DiskSitemapStorage.ts
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
function sanitizeFilename(filename) {
|
|
5
|
+
if (!filename) {
|
|
6
|
+
throw new Error("Invalid sitemap filename.");
|
|
7
|
+
}
|
|
8
|
+
if (filename.includes("\0")) {
|
|
9
|
+
throw new Error("Invalid sitemap filename.");
|
|
10
|
+
}
|
|
11
|
+
if (filename.includes("/") || filename.includes("\\")) {
|
|
12
|
+
throw new Error("Invalid sitemap filename.");
|
|
13
|
+
}
|
|
14
|
+
if (filename.includes("..")) {
|
|
15
|
+
throw new Error("Invalid sitemap filename.");
|
|
16
|
+
}
|
|
17
|
+
return filename;
|
|
18
|
+
}
|
|
19
|
+
var DiskSitemapStorage = class {
|
|
20
|
+
constructor(outDir, baseUrl) {
|
|
21
|
+
this.outDir = outDir;
|
|
22
|
+
this.baseUrl = baseUrl;
|
|
23
|
+
}
|
|
24
|
+
async write(filename, content) {
|
|
25
|
+
const safeName = sanitizeFilename(filename);
|
|
26
|
+
await fs.mkdir(this.outDir, { recursive: true });
|
|
27
|
+
await fs.writeFile(path.join(this.outDir, safeName), content);
|
|
28
|
+
}
|
|
29
|
+
async read(filename) {
|
|
30
|
+
try {
|
|
31
|
+
const safeName = sanitizeFilename(filename);
|
|
32
|
+
return await fs.readFile(path.join(this.outDir, safeName), "utf-8");
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async exists(filename) {
|
|
38
|
+
try {
|
|
39
|
+
const safeName = sanitizeFilename(filename);
|
|
40
|
+
await fs.access(path.join(this.outDir, safeName));
|
|
41
|
+
return true;
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
getUrl(filename) {
|
|
47
|
+
const safeName = sanitizeFilename(filename);
|
|
48
|
+
const base = this.baseUrl.endsWith("/") ? this.baseUrl.slice(0, -1) : this.baseUrl;
|
|
49
|
+
const file = safeName.startsWith("/") ? safeName.slice(1) : safeName;
|
|
50
|
+
return `${base}/${file}`;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
DiskSitemapStorage
|
|
56
|
+
};
|