mirror of
https://github.com/misenhower/splatoon3.ink.git
synced 2026-10-02 20:06:45 -05:00
Generate sitemap from shared router definitions
This commit is contained in:
4
public/robots.txt
Normal file
4
public/robots.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
User-agent: *
|
||||
Allow: /
|
||||
|
||||
Sitemap: https://splatoon3.ink/sitemap.xml
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import { createRoutes } from './routes.mjs';
|
||||
import HomeView from '@/views/HomeView.vue';
|
||||
import SalmonRunView from '@/views/SalmonRunView.vue';
|
||||
import GearView from '@/views/GearView.vue';
|
||||
@@ -9,47 +10,15 @@ import SocialsView from '@/views/SocialsView.vue';
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: HomeView,
|
||||
},
|
||||
{
|
||||
path: '/salmonrun',
|
||||
name: 'salmonrun',
|
||||
component: SalmonRunView,
|
||||
},
|
||||
{
|
||||
path: '/gear',
|
||||
name: 'gear',
|
||||
component: GearView,
|
||||
},
|
||||
{
|
||||
path: '/splatfests',
|
||||
name: 'splatfests',
|
||||
component: SplatfestsView,
|
||||
},
|
||||
{
|
||||
path: '/challenges',
|
||||
name: 'challenges',
|
||||
component: ChallengesView,
|
||||
},
|
||||
{
|
||||
path: '/socials',
|
||||
name: 'socials',
|
||||
component: SocialsView,
|
||||
},
|
||||
{
|
||||
path: '/about',
|
||||
name: 'about',
|
||||
component: AboutView,
|
||||
},
|
||||
{
|
||||
path: '/faq',
|
||||
redirect: { name: 'about' },
|
||||
},
|
||||
],
|
||||
routes: createRoutes({
|
||||
HomeView,
|
||||
SalmonRunView,
|
||||
GearView,
|
||||
SplatfestsView,
|
||||
ChallengesView,
|
||||
SocialsView,
|
||||
AboutView,
|
||||
}),
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
44
src/router/routes.mjs
Normal file
44
src/router/routes.mjs
Normal file
@@ -0,0 +1,44 @@
|
||||
// Build tools can read route metadata without importing Vue components.
|
||||
export function createRoutes(views = {}) {
|
||||
return [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: views.HomeView,
|
||||
},
|
||||
{
|
||||
path: '/salmonrun',
|
||||
name: 'salmonrun',
|
||||
component: views.SalmonRunView,
|
||||
},
|
||||
{
|
||||
path: '/gear',
|
||||
name: 'gear',
|
||||
component: views.GearView,
|
||||
},
|
||||
{
|
||||
path: '/splatfests',
|
||||
name: 'splatfests',
|
||||
component: views.SplatfestsView,
|
||||
},
|
||||
{
|
||||
path: '/challenges',
|
||||
name: 'challenges',
|
||||
component: views.ChallengesView,
|
||||
},
|
||||
{
|
||||
path: '/socials',
|
||||
name: 'socials',
|
||||
component: views.SocialsView,
|
||||
},
|
||||
{
|
||||
path: '/about',
|
||||
name: 'about',
|
||||
component: views.AboutView,
|
||||
},
|
||||
{
|
||||
path: '/faq',
|
||||
redirect: { name: 'about' },
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { defineConfig } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
|
||||
import { createRoutes } from './src/router/routes.mjs';
|
||||
|
||||
const redirectToDist = [
|
||||
'/assets/splatnet/',
|
||||
@@ -23,6 +24,32 @@ export default defineConfig({
|
||||
VueI18nPlugin({
|
||||
include: resolve(import.meta.dirname, './src/assets/i18n/*.json'),
|
||||
}),
|
||||
{
|
||||
name: 'sitemap',
|
||||
generateBundle() {
|
||||
const urls = createRoutes()
|
||||
.filter(route => !route.redirect && !route.path.includes(':') && route.meta?.sitemap !== false)
|
||||
.map(route => {
|
||||
const url = new URL(route.path, 'https://splatoon3.ink').href
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>');
|
||||
|
||||
return ` <url>\n <loc>${url}</loc>\n </url>`;
|
||||
});
|
||||
|
||||
this.emitFile({
|
||||
type: 'asset',
|
||||
fileName: 'sitemap.xml',
|
||||
source: [
|
||||
'<?xml version="1.0" encoding="UTF-8"?>',
|
||||
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
||||
...urls,
|
||||
'</urlset>\n',
|
||||
].join('\n'),
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
// Quick hack to redirect dynamic assets to the /dist/ directory
|
||||
configureServer(server) {
|
||||
|
||||
Reference in New Issue
Block a user