web: add automatic sitemap generation

This commit is contained in:
jj 2024-12-10 16:14:15 +00:00
parent e041e376c7
commit f1916cef6e
No known key found for this signature in database
3 changed files with 105 additions and 1 deletions

View file

@ -163,6 +163,9 @@ importers:
svelte-preprocess: svelte-preprocess:
specifier: ^6.0.2 specifier: ^6.0.2
version: 6.0.2(postcss@8.4.47)(svelte@4.2.19)(typescript@5.5.4) version: 6.0.2(postcss@8.4.47)(svelte@4.2.19)(typescript@5.5.4)
svelte-sitemap:
specifier: 2.6.0
version: 2.6.0
sveltekit-i18n: sveltekit-i18n:
specifier: ^2.4.2 specifier: ^2.4.2
version: 2.4.2(svelte@4.2.19) version: 2.4.2(svelte@4.2.19)
@ -603,6 +606,22 @@ packages:
resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
'@oozcitak/dom@1.15.10':
resolution: {integrity: sha512-0JT29/LaxVgRcGKvHmSrUTEvZ8BXvZhGl2LASRUgHqDTC1M5g1pLmVv56IYNyt3bG2CUjDkc67wnyZC14pbQrQ==}
engines: {node: '>=8.0'}
'@oozcitak/infra@1.0.8':
resolution: {integrity: sha512-JRAUc9VR6IGHOL7OGF+yrvs0LO8SlqGnPAMqyzOuFZPSZSXI7Xf2O9+awQPSMXgIWGtgUf/dA6Hs6X6ySEaWTg==}
engines: {node: '>=6.0'}
'@oozcitak/url@1.0.4':
resolution: {integrity: sha512-kDcD8y+y3FCSOvnBI6HJgl00viO/nGbQoCINmQ0h98OhnGITrWR3bOGfwYCthgcrV8AnTJz8MzslTQbC3SOAmw==}
engines: {node: '>=8.0'}
'@oozcitak/util@8.3.8':
resolution: {integrity: sha512-T8TbSnGsxo6TDBJx/Sgv/BlVJL3tshxZP7Aq5R1mSnM5OcHY2dQaxLMu2+E8u3gN0MLOzdjurqN4ZRVuzQycOQ==}
engines: {node: '>=8.0'}
'@pkgjs/parseargs@0.11.0': '@pkgjs/parseargs@0.11.0':
resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==}
engines: {node: '>=14'} engines: {node: '>=14'}
@ -899,6 +918,9 @@ packages:
resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==} resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
argparse@1.0.10:
resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==}
argparse@2.0.1: argparse@2.0.1:
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
@ -1304,6 +1326,11 @@ packages:
resolution: {integrity: sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==} resolution: {integrity: sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
esprima@4.0.1:
resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==}
engines: {node: '>=4'}
hasBin: true
esquery@1.6.0: esquery@1.6.0:
resolution: {integrity: sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==} resolution: {integrity: sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==}
engines: {node: '>=0.10'} engines: {node: '>=0.10'}
@ -1589,6 +1616,10 @@ packages:
resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==}
engines: {node: '>=10'} engines: {node: '>=10'}
js-yaml@3.14.1:
resolution: {integrity: sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==}
hasBin: true
js-yaml@4.1.0: js-yaml@4.1.0:
resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==} resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==}
hasBin: true hasBin: true
@ -2045,6 +2076,9 @@ packages:
resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==} resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
sprintf-js@1.0.3:
resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==}
statuses@2.0.1: statuses@2.0.1:
resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==} resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==}
engines: {node: '>= 0.8'} engines: {node: '>= 0.8'}
@ -2175,6 +2209,11 @@ packages:
typescript: typescript:
optional: true optional: true
svelte-sitemap@2.6.0:
resolution: {integrity: sha512-WcwsuIeo8iJFG9a5cgvXwXEGoyjk6Zowb6JmL5BbwfnFXMzakGa1+mQjthw5Ni3UV/gGbE0PgJvc7Ygir3LmFg==}
engines: {node: '>= 14.17.0'}
hasBin: true
svelte@4.2.19: svelte@4.2.19:
resolution: {integrity: sha512-IY1rnGr6izd10B0A8LqsBfmlT5OILVuZ7XsI0vdGPEvuonFV7NYEUK4dAkm9Zg2q0Um92kYjTpS1CAP3Nh/KWw==} resolution: {integrity: sha512-IY1rnGr6izd10B0A8LqsBfmlT5OILVuZ7XsI0vdGPEvuonFV7NYEUK4dAkm9Zg2q0Um92kYjTpS1CAP3Nh/KWw==}
engines: {node: '>=16'} engines: {node: '>=16'}
@ -2381,6 +2420,10 @@ packages:
wrappy@1.0.2: wrappy@1.0.2:
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
xmlbuilder2@3.1.1:
resolution: {integrity: sha512-WCSfbfZnQDdLQLiMdGUQpMxxckeQ4oZNMNhLVkcekTu7xhD4tuUDyAPoY8CwXvBYE6LwBHd6QW2WZXlOWr1vCw==}
engines: {node: '>=12.0'}
yallist@4.0.0: yallist@4.0.0:
resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==}
@ -2668,6 +2711,23 @@ snapshots:
'@nodelib/fs.scandir': 2.1.5 '@nodelib/fs.scandir': 2.1.5
fastq: 1.17.1 fastq: 1.17.1
'@oozcitak/dom@1.15.10':
dependencies:
'@oozcitak/infra': 1.0.8
'@oozcitak/url': 1.0.4
'@oozcitak/util': 8.3.8
'@oozcitak/infra@1.0.8':
dependencies:
'@oozcitak/util': 8.3.8
'@oozcitak/url@1.0.4':
dependencies:
'@oozcitak/infra': 1.0.8
'@oozcitak/util': 8.3.8
'@oozcitak/util@8.3.8': {}
'@pkgjs/parseargs@0.11.0': '@pkgjs/parseargs@0.11.0':
optional: true optional: true
@ -2966,6 +3026,10 @@ snapshots:
normalize-path: 3.0.0 normalize-path: 3.0.0
picomatch: 2.3.1 picomatch: 2.3.1
argparse@1.0.10:
dependencies:
sprintf-js: 1.0.3
argparse@2.0.1: {} argparse@2.0.1: {}
aria-query@5.3.0: aria-query@5.3.0:
@ -3371,6 +3435,8 @@ snapshots:
acorn-jsx: 5.3.2(acorn@8.14.0) acorn-jsx: 5.3.2(acorn@8.14.0)
eslint-visitor-keys: 4.2.0 eslint-visitor-keys: 4.2.0
esprima@4.0.1: {}
esquery@1.6.0: esquery@1.6.0:
dependencies: dependencies:
estraverse: 5.3.0 estraverse: 5.3.0
@ -3693,6 +3759,11 @@ snapshots:
joycon@3.1.1: {} joycon@3.1.1: {}
js-yaml@3.14.1:
dependencies:
argparse: 1.0.10
esprima: 4.0.1
js-yaml@4.1.0: js-yaml@4.1.0:
dependencies: dependencies:
argparse: 2.0.1 argparse: 2.0.1
@ -4108,6 +4179,8 @@ snapshots:
dependencies: dependencies:
whatwg-url: 7.1.0 whatwg-url: 7.1.0
sprintf-js@1.0.3: {}
statuses@2.0.1: {} statuses@2.0.1: {}
string-width@4.2.3: string-width@4.2.3:
@ -4199,6 +4272,12 @@ snapshots:
postcss: 8.4.47 postcss: 8.4.47
typescript: 5.5.4 typescript: 5.5.4
svelte-sitemap@2.6.0:
dependencies:
fast-glob: 3.3.2
minimist: 1.2.8
xmlbuilder2: 3.1.1
svelte@4.2.19: svelte@4.2.19:
dependencies: dependencies:
'@ampproject/remapping': 2.3.0 '@ampproject/remapping': 2.3.0
@ -4389,6 +4468,13 @@ snapshots:
wrappy@1.0.2: {} wrappy@1.0.2: {}
xmlbuilder2@3.1.1:
dependencies:
'@oozcitak/dom': 1.15.10
'@oozcitak/infra': 1.0.8
'@oozcitak/util': 8.3.8
js-yaml: 3.14.1
yallist@4.0.0: yallist@4.0.0:
optional: true optional: true

View file

@ -47,6 +47,7 @@
"svelte": "^4.2.19", "svelte": "^4.2.19",
"svelte-check": "^3.6.0", "svelte-check": "^3.6.0",
"svelte-preprocess": "^6.0.2", "svelte-preprocess": "^6.0.2",
"svelte-sitemap": "2.6.0",
"sveltekit-i18n": "^2.4.2", "sveltekit-i18n": "^2.4.2",
"ts-deepmerge": "^7.0.1", "ts-deepmerge": "^7.0.1",
"tslib": "^2.4.1", "tslib": "^2.4.1",

View file

@ -3,6 +3,7 @@ import { sveltekit } from "@sveltejs/kit/vite";
import basicSSL from "@vitejs/plugin-basic-ssl"; import basicSSL from "@vitejs/plugin-basic-ssl";
import { glob } from "glob"; import { glob } from "glob";
import mime from "mime"; import mime from "mime";
import { createSitemap } from 'svelte-sitemap/src/index'
import { cp, readdir, mkdir } from "node:fs/promises"; import { cp, readdir, mkdir } from "node:fs/promises";
import { createReadStream } from "node:fs"; import { createReadStream } from "node:fs";
@ -60,12 +61,28 @@ const enableCOEP: PluginOption = {
} }
}; };
const generateSitemap: PluginOption = {
name: "generate-sitemap",
async writeBundle(bundle) {
if (!process.env.WEB_HOST || !bundle.dir?.endsWith('server')) {
return;
}
await createSitemap(`https://${process.env.WEB_HOST}`, {
changeFreq: 'monthly',
outDir: '.svelte-kit/output/prerendered/pages',
resetTime: true
});
}
}
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [
basicSSL(), basicSSL(),
sveltekit(), sveltekit(),
enableCOEP, enableCOEP,
exposeLibAV exposeLibAV,
generateSitemap
], ],
build: { build: {
rollupOptions: { rollupOptions: {