feat(Sitemap): add HOSTNAME env var to generate a sitemap

Fix #476
This commit is contained in:
ShareVB committed 2026-07-13 23:16:40 +02:00
1 parent a2d696168a
commit 96a2079283
5 files changed
+79 -15

No files matched your search

+2 -1
View File
@@ -4,6 +4,7 @@ env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VITE_VERCEL_ENV: production VITE_VERCEL_ENV: production
VITE_VERCEL_DEPLOY: true VITE_VERCEL_DEPLOY: true
HOSTNAME: https://sharevb-it-tools.vercel.app/
on: on:
push: push:
branches: branches:
@@ -20,4 +21,4 @@ jobs:
- name: Build Project Artifacts - name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel - name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --archive=tgz --prod --token=${{ secrets.VERCEL_TOKEN }} run: vercel deploy --prebuilt --archive=tgz --prod --token=${{ secrets.VERCEL_TOKEN }}
+2
View File
@@ -379,6 +379,7 @@
"utf8": "^3.0.0", "utf8": "^3.0.0",
"uuid": "^14.0.1", "uuid": "^14.0.1",
"vanilla-jsoneditor": "^3.12.0", "vanilla-jsoneditor": "^3.12.0",
"vite-plugin-sitemap": "^0.8.2",
"vue": "^3.5.39", "vue": "^3.5.39",
"vue-color-wheel": "^0.1.1", "vue-color-wheel": "^0.1.1",
"vue-i18n": "^11.4.6", "vue-i18n": "^11.4.6",
@@ -457,6 +458,7 @@
"commander": "^15.0.0", "commander": "^15.0.0",
"consola": "^3.4.2", "consola": "^3.4.2",
"dotenv": "^17.4.2", "dotenv": "^17.4.2",
"fast-glob": "^3.3.3",
"hygen": "^6.2.11", "hygen": "^6.2.11",
"jsdom": "^29.1.1", "jsdom": "^29.1.1",
"less": "^4.6.7", "less": "^4.6.7",
+11
View File
@@ -1026,6 +1026,9 @@ importers:
vanilla-jsoneditor: vanilla-jsoneditor:
specifier: ^3.12.0 specifier: ^3.12.0
version: 3.12.0(@typescript-eslint/types@8.62.1) version: 3.12.0(@typescript-eslint/types@8.62.1)
vite-plugin-sitemap:
specifier: ^0.8.2
version: 0.8.2
vue: vue:
specifier: ^3.5.39 specifier: ^3.5.39
version: 3.5.39(typescript@6.0.3) version: 3.5.39(typescript@6.0.3)
@@ -1255,6 +1258,9 @@ importers:
dotenv: dotenv:
specifier: ^17.4.2 specifier: ^17.4.2
version: 17.4.2 version: 17.4.2
fast-glob:
specifier: ^3.3.3
version: 3.3.3
hygen: hygen:
specifier: ^6.2.11 specifier: ^6.2.11
version: 6.2.11 version: 6.2.11
@@ -11012,6 +11018,9 @@ packages:
'@vite-pwa/assets-generator': '@vite-pwa/assets-generator':
optional: true optional: true
vite-plugin-sitemap@0.8.2:
resolution: {integrity: sha512-bqIw6NVOXg6je81lzX8Lm0vjf8/QSAp8di8fYQzZ3ZdVicOm8+6idBGALJiy1R1FiXNIK8rgORO6HBqXyHW+iQ==}
vite-plugin-wasm@3.6.0: vite-plugin-wasm@3.6.0:
resolution: {integrity: sha512-mL/QPziiIA4RAA6DkaZZzOstdwbW5jO4Vz7Zenj0wieKWBlNvIvX5L5ljum9lcUX0ShNfBgCNLKTjNkRVVqcsw==} resolution: {integrity: sha512-mL/QPziiIA4RAA6DkaZZzOstdwbW5jO4Vz7Zenj0wieKWBlNvIvX5L5ljum9lcUX0ShNfBgCNLKTjNkRVVqcsw==}
peerDependencies: peerDependencies:
@@ -22248,6 +22257,8 @@ snapshots:
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
vite-plugin-sitemap@0.8.2: {}
vite-plugin-wasm@3.6.0(vite@8.1.3(@types/node@24.13.3)(jiti@2.7.0)(less@4.6.7)(terser@5.48.0)(yaml@2.9.0)): vite-plugin-wasm@3.6.0(vite@8.1.3(@types/node@24.13.3)(jiti@2.7.0)(less@4.6.7)(terser@5.48.0)(yaml@2.9.0)):
dependencies: dependencies:
vite: 8.1.3(@types/node@24.13.3)(jiti@2.7.0)(less@4.6.7)(terser@5.48.0)(yaml@2.9.0) vite: 8.1.3(@types/node@24.13.3)(jiti@2.7.0)(less@4.6.7)(terser@5.48.0)(yaml@2.9.0)
+15 -2
View File
@@ -3,7 +3,20 @@
"git": { "git": {
"deploymentEnabled": false "deploymentEnabled": false
}, },
"rewrites": [{ "source": "/:path*", "destination": "/index.html" }], "rewrites": [
{
"source": "/robots.txt",
"destination": "/robots.txt"
},
{
"source": "/sitemap.xml",
"destination": "/sitemap.xml"
},
{
"source": "/:path*",
"destination": "/index.html"
}
],
"headers": [ "headers": [
{ {
"source": "/index.html", "source": "/index.html",
@@ -24,4 +37,4 @@
] ]
} }
] ]
} }
+49 -12
View File
@@ -18,17 +18,19 @@ import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver'; import IconsResolver from 'unplugin-icons/resolver';
import VueI18n from '@intlify/unplugin-vue-i18n/vite'; import VueI18n from '@intlify/unplugin-vue-i18n/vite';
import fs from 'node:fs';
import fg from 'fast-glob';
import Sitemap from 'vite-plugin-sitemap';
import { visualizer } from 'rollup-plugin-visualizer'; import { visualizer } from 'rollup-plugin-visualizer';
const baseUrl = process.env.BASE_URL || '/'; const baseUrl = process.env.BASE_URL || '/';
const hostname = process.env.HOSTNAME;
// Locales are code-split: only en is bundled eagerly, the rest become lazy chunks fetched on // Locales are code-split: only en is bundled eagerly, the rest become lazy chunks fetched on
// first use (see src/plugins/i18n.plugin.ts). VITE_AVAILABLE_LOCALES filters the locales // first use (see src/plugins/i18n.plugin.ts). VITE_AVAILABLE_LOCALES filters the locales
// offered at runtime instead of trimming the build. // offered at runtime instead of trimming the build.
const includeLocales = [ const includeLocales = [resolve(__dirname, 'src/tools/*/locales/**'), resolve(__dirname, 'locales/**')];
resolve(__dirname, 'src/tools/*/locales/**'),
resolve(__dirname, 'locales/**'),
];
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
@@ -67,15 +69,16 @@ export default defineConfig({
// tool chunk and WASM binary (~160 MB) on first visit; hashed assets are // tool chunk and WASM binary (~160 MB) on first visit; hashed assets are
// cached on demand as tools are opened. Set VITE_PWA_FULL_PRECACHE=true to // cached on demand as tools are opened. Set VITE_PWA_FULL_PRECACHE=true to
// restore full offline precaching of everything. // restore full offline precaching of everything.
globPatterns: (process.env.VITE_PWA_FULL_PRECACHE === 'true' && !process.env.VITE_VERCEL_DEPLOY) globPatterns:
? ['**\/*.{js,wasm,css,html}'] process.env.VITE_PWA_FULL_PRECACHE === 'true' && !process.env.VITE_VERCEL_DEPLOY
: ['**\/*.{css,html}'], ? ['**\/*.{js,wasm,css,html}']
: ['**\/*.{css,html}'],
maximumFileSizeToCacheInBytes: 25 * 1024 ** 2, maximumFileSizeToCacheInBytes: 25 * 1024 ** 2,
navigateFallback: `${baseUrl}index.html`, navigateFallback: `${baseUrl}index.html`,
runtimeCaching: [ runtimeCaching: [
{ {
urlPattern: ({ sameOrigin, request }) => sameOrigin urlPattern: ({ sameOrigin, request }) =>
&& (request.destination === 'script' || request.destination === 'worker'), sameOrigin && (request.destination === 'script' || request.destination === 'worker'),
handler: 'CacheFirst', handler: 'CacheFirst',
options: { options: {
cacheName: 'app-chunks', cacheName: 'app-chunks',
@@ -142,6 +145,29 @@ export default defineConfig({
nodePolyfills(), nodePolyfills(),
wasm(), wasm(),
visualizer(), visualizer(),
hostname
? Sitemap({
hostname,
generateRobotsTxt: true,
robots: [{ userAgent: '*', allow: '/' }],
dynamicRoutes: (() => {
const paths = ['/', '/about'];
fg.sync('src/tools/*/index.ts').forEach((file) => {
const content = fs.readFileSync(file, 'utf-8');
const pathMatch = content.match(/path:\s*['"`]([^'"`]+)['"`]/);
if (pathMatch) {
paths.push(pathMatch[1]);
}
const redirectMatch = content.match(/redirectFrom:\s*\[([^\]]+)\]/);
if (redirectMatch?.[1]) {
const redirectPaths = redirectMatch[1].match(/['"`]([^'"`]+)['"`]/g);
redirectPaths?.forEach((p) => paths.push(p.replace(/['"`]/g, '')));
}
});
return paths;
})(),
})
: undefined,
], ],
base: baseUrl, base: baseUrl,
resolve: { resolve: {
@@ -149,12 +175,14 @@ export default defineConfig({
'@': fileURLToPath(new URL('./src', import.meta.url)), '@': fileURLToPath(new URL('./src', import.meta.url)),
'node:fs/promises': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), 'node:fs/promises': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'node:fs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), 'node:fs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'fs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), fs: fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'@babel/core': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), '@babel/core': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'isolated-vm': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), 'isolated-vm': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'onnxruntime-node': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), 'onnxruntime-node': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'unpdf/pdfjs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), 'unpdf/pdfjs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
'webcrypto-liner-shim': !process.env.VERCEL ? 'webcrypto-liner-shim' : fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), 'webcrypto-liner-shim': !process.env.VERCEL
? 'webcrypto-liner-shim'
: fileURLToPath(new URL('./src/_empty.ts', import.meta.url)),
}, },
}, },
define: { define: {
@@ -197,7 +225,16 @@ export default defineConfig({
}, },
}, },
optimizeDeps: { optimizeDeps: {
include: ['isolated-vm', '@lezer/highlight', 'pdfjs-dist', 'onnxruntime-node', 'onnxruntime-web', 'unpdf', 'unpdf/pdfjs', ...(process.env.VERCEL ? ['webcrypto-liner-shim'] : [])], // optionally specify dependency name include: [
'isolated-vm',
'@lezer/highlight',
'pdfjs-dist',
'onnxruntime-node',
'onnxruntime-web',
'unpdf',
'unpdf/pdfjs',
...(process.env.VERCEL ? ['webcrypto-liner-shim'] : []),
], // optionally specify dependency name
}, },
// server: { // server: {
// headers: { // headers: {