Merge pull request #126 from misenhower/codex/router-sitemap

Add robots.txt and generate sitemap from Vue routes
This commit is contained in:
Matt Isenhower
2026-09-27 12:48:01 -07:00
committed by GitHub
4 changed files with 85 additions and 41 deletions

4
public/robots.txt Normal file
View File

@@ -0,0 +1,4 @@
User-agent: *
Allow: /
Sitemap: https://splatoon3.ink/sitemap.xml

View File

@@ -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
View 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' },
},
];
}

View File

@@ -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('<', '&lt;')
.replaceAll('>', '&gt;');
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) {