Skip to content

Commit 75b10f8

Browse files
committed
add sitemap
1 parent af22065 commit 75b10f8

3 files changed

Lines changed: 99 additions & 69 deletions

File tree

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# use .env.local or actual env variables to override
22
VITE_CANONICAL_URL=https://material-e621.avoonix.com
33
VITE_GOOGLE_SITE_VERIFICATION_META=""
4+
VITE_APP_DOMAIN=material-e621.avoonix.com

vite.config.ts

Lines changed: 87 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
import { fileURLToPath, URL } from 'node:url'
2-
import { defineConfig } from 'vite'
2+
import { defineConfig, Plugin, loadEnv } from 'vite'
33
import vue from '@vitejs/plugin-vue'
44
import vueDevTools from 'vite-plugin-vue-devtools'
55
import vuetify from 'vite-plugin-vuetify'
66
import { execSync } from "child_process";
77
import { VitePWA } from 'vite-plugin-pwa'
8+
import fs from 'fs';
9+
import path from 'path';
10+
11+
function generateSitemap(env: Record<string, string>): Plugin {
12+
return {
13+
name: 'generate-sitemap',
14+
apply: 'build',
15+
writeBundle(options) {
16+
const outDir = options.dir || 'dist';
17+
const date = new Date().toISOString().split('T')[0];
18+
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
19+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
20+
<url>
21+
<loc>https://${env.VITE_APP_DOMAIN}/</loc>
22+
<lastmod>${date}</lastmod>
23+
</url>
24+
</urlset>`;
25+
26+
fs.writeFileSync(path.resolve(outDir, 'sitemap.xml'), sitemap);
27+
}
28+
};
29+
}
30+
831

932
const VITE_GIT_COMMIT_INFO = execSync(
1033
'git log -n 10 --pretty=format:";;;;;%H;%aI;%an;%B"',
@@ -17,67 +40,71 @@ const VITE_GIT_BRANCH = execSync("git branch --show-current")
1740
.trim();
1841

1942
// https://vite.dev/config/
20-
export default defineConfig({
21-
define: {
22-
"import.meta.env.VITE_GIT_COMMIT_INFO": JSON.stringify(VITE_GIT_COMMIT_INFO),
23-
"import.meta.env.VITE_GIT_BRANCH": JSON.stringify(VITE_GIT_BRANCH),
24-
},
25-
plugins: [
26-
vue(),
27-
vuetify(),
28-
vueDevTools(),
29-
VitePWA({
30-
registerType: 'autoUpdate',
31-
manifest: {
32-
id: "/#/posts",
33-
name: "Material e621",
34-
short_name: "Material e6", // maximum of 12 characters recommended by chromium devs
35-
start_url: "/#/posts",
36-
scope: "/",
37-
display: "fullscreen",
38-
background_color: "#000000",
39-
theme_color: "#000000",
40-
description:
41-
"Material e621 is a modern, open source web client for e621.net. It is customizable, comes with a bunch of additional features that are not available on e621.net, and makes browsing posts a delightful experience.",
42-
orientation: "any",
43-
lang: "en",
44-
icons: [
45-
{
46-
"src": "pwa-64x64.png",
47-
"sizes": "64x64",
48-
"type": "image/png"
49-
},
50-
{
51-
"src": "pwa-192x192.png",
52-
"sizes": "192x192",
53-
"type": "image/png"
54-
},
55-
{
56-
"src": "pwa-512x512.png",
57-
"sizes": "512x512",
58-
"type": "image/png"
59-
},
60-
{
61-
"src": "maskable-icon-512x512.png",
62-
"sizes": "512x512",
63-
"type": "image/png",
64-
"purpose": "maskable"
65-
}
66-
]
67-
}
68-
})
43+
export default defineConfig(({ mode }) => {
44+
const env = loadEnv(mode, process.cwd(), '');
45+
return {
46+
define: {
47+
"import.meta.env.VITE_GIT_COMMIT_INFO": JSON.stringify(VITE_GIT_COMMIT_INFO),
48+
"import.meta.env.VITE_GIT_BRANCH": JSON.stringify(VITE_GIT_BRANCH),
49+
},
50+
plugins: [
51+
generateSitemap(env),
52+
vue(),
53+
vuetify(),
54+
vueDevTools(),
55+
VitePWA({
56+
registerType: 'autoUpdate',
57+
manifest: {
58+
id: "/#/posts",
59+
name: "Material e621",
60+
short_name: "Material e6", // maximum of 12 characters recommended by chromium devs
61+
start_url: "/#/posts",
62+
scope: "/",
63+
display: "fullscreen",
64+
background_color: "#000000",
65+
theme_color: "#000000",
66+
description:
67+
"Material e621 is a modern, open source web client for e621.net. It is customizable, comes with a bunch of additional features that are not available on e621.net, and makes browsing posts a delightful experience.",
68+
orientation: "any",
69+
lang: "en",
70+
icons: [
71+
{
72+
"src": "pwa-64x64.png",
73+
"sizes": "64x64",
74+
"type": "image/png"
75+
},
76+
{
77+
"src": "pwa-192x192.png",
78+
"sizes": "192x192",
79+
"type": "image/png"
80+
},
81+
{
82+
"src": "pwa-512x512.png",
83+
"sizes": "512x512",
84+
"type": "image/png"
85+
},
86+
{
87+
"src": "maskable-icon-512x512.png",
88+
"sizes": "512x512",
89+
"type": "image/png",
90+
"purpose": "maskable"
91+
}
92+
]
93+
}
94+
})
6995

70-
],
71-
resolve: {
72-
alias: {
73-
'@': fileURLToPath(new URL('./src', import.meta.url))
96+
],
97+
resolve: {
98+
alias: {
99+
'@': fileURLToPath(new URL('./src', import.meta.url))
100+
},
74101
},
75-
},
76-
build: {
77-
rollupOptions: {
78-
output: {
79-
format: 'iife',
102+
build: {
103+
rollupOptions: {
104+
output: {
105+
format: 'iife',
106+
},
80107
},
81108
},
82-
},
109+
}
83110
})

vitest.config.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { fileURLToPath } from 'node:url'
22
import { mergeConfig, defineConfig, configDefaults } from 'vitest/config'
33
import viteConfig from './vite.config'
44

5-
export default mergeConfig(
6-
viteConfig,
7-
defineConfig({
8-
test: {
9-
environment: 'jsdom',
10-
exclude: [...configDefaults.exclude, 'e2e/**'],
11-
root: fileURLToPath(new URL('./', import.meta.url)),
12-
},
13-
}),
5+
export default defineConfig((configEnv) =>
6+
mergeConfig(
7+
viteConfig(configEnv),
8+
defineConfig({
9+
test: {
10+
environment: 'jsdom',
11+
exclude: [...configDefaults.exclude, 'e2e/**'],
12+
root: fileURLToPath(new URL('./', import.meta.url)),
13+
},
14+
}),
15+
)
1416
)

0 commit comments

Comments
 (0)