diff --git a/package-lock.json b/package-lock.json
index 69b76ec8..70ee4074 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3159,7 +3159,6 @@
"cpu": [
"arm"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3173,7 +3172,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3187,7 +3185,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3201,7 +3198,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3215,7 +3211,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3229,7 +3224,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3243,7 +3237,6 @@
"cpu": [
"arm"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3257,7 +3250,6 @@
"cpu": [
"arm"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3271,7 +3263,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3285,7 +3276,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3299,7 +3289,6 @@
"cpu": [
"loong64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3313,7 +3302,6 @@
"cpu": [
"loong64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3327,7 +3315,6 @@
"cpu": [
"ppc64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3341,7 +3328,6 @@
"cpu": [
"ppc64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3355,7 +3341,6 @@
"cpu": [
"riscv64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3369,7 +3354,6 @@
"cpu": [
"riscv64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3383,7 +3367,6 @@
"cpu": [
"s390x"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3397,7 +3380,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3411,7 +3393,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3425,7 +3406,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3439,7 +3419,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3453,7 +3432,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3467,7 +3445,6 @@
"cpu": [
"ia32"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3481,7 +3458,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -3495,7 +3471,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
diff --git a/vite.config.ts b/vite.config.ts
index 80cd2851..c84eb580 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,10 +1,10 @@
+import process from "node:process";
import { execSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import react from "@vitejs/plugin-react";
-import type { Plugin } from "vite";
-import { defineConfig } from "vitest/config";
+import { defineConfig, loadEnv, type Plugin } from "vite";
import { DittoConfigSchema } from "./src/lib/schemas";
@@ -92,6 +92,78 @@ function mergePublicDir(externalDir: string): Plugin {
};
}
+/**
+ * All static routes in the application (no dynamic params).
+ * Used to generate a sitemap.xml at build time.
+ */
+const staticRoutes = [
+ '/',
+ '/feed',
+ '/notifications',
+ '/search',
+ '/trends',
+ '/settings',
+ '/settings/profile',
+ '/settings/feed',
+ '/settings/content',
+ '/settings/wallet',
+ '/settings/notifications',
+ '/settings/advanced',
+ '/settings/magic',
+ '/settings/network',
+ '/lists',
+ '/events',
+ '/photos',
+ '/videos',
+ '/vines',
+ '/music',
+ '/podcasts',
+ '/polls',
+ '/treasures',
+ '/colors',
+ '/packs',
+ '/webxdc',
+ '/articles',
+ '/decks',
+ '/emojis',
+ '/development',
+ '/themes',
+ '/bookmarks',
+ '/ai-chat',
+ '/world',
+ '/badges',
+ '/books',
+ '/help',
+];
+
+/**
+ * Vite plugin that generates a sitemap.xml in the build output.
+ * Set the PUBLIC_URL env var (e.g. "https://ditto.pub") to enable.
+ * Skipped when PUBLIC_URL is not set.
+ */
+function generateSitemap(origin: string): Plugin {
+ return {
+ name: 'ditto:sitemap',
+ writeBundle(options) {
+ const outDir = options.dir ?? path.resolve('dist');
+
+ const urls = staticRoutes
+ .map((route) => ` \n ${new URL(route, origin).href}\n `)
+ .join('\n');
+
+ const xml = [
+ '',
+ '',
+ urls,
+ '',
+ '',
+ ].join('\n');
+
+ fs.writeFileSync(path.join(outDir, 'sitemap.xml'), xml);
+ },
+ };
+}
+
const dittoConfig = loadDittoConfig();
const publicDir = process.env.PUBLIC_DIR;
@@ -106,7 +178,11 @@ function getVersion(): string {
// https://vitejs.dev/config/
-export default defineConfig(() => ({
+export default defineConfig(({ mode }) => {
+ const env = loadEnv(mode, process.cwd(), '');
+ const publicUrl = env.PUBLIC_URL;
+
+ return {
server: {
host: "::",
port: 8080,
@@ -114,6 +190,7 @@ export default defineConfig(() => ({
plugins: [
react(),
...(publicDir ? [mergePublicDir(publicDir)] : []),
+ ...(publicUrl ? [generateSitemap(publicUrl)] : []),
],
define: {
__DITTO_CONFIG__: JSON.stringify(dittoConfig ?? null),
@@ -138,4 +215,5 @@ export default defineConfig(() => ({
"@": path.resolve(__dirname, "./src"),
},
},
-}));
\ No newline at end of file
+};
+});
\ No newline at end of file