diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..fa20f7e --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Allow: / + +Sitemap: https://splatoon3.ink/sitemap.xml diff --git a/src/router/index.js b/src/router/index.js index b36475f..2406e83 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -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; diff --git a/src/router/routes.mjs b/src/router/routes.mjs new file mode 100644 index 0000000..3f52e62 --- /dev/null +++ b/src/router/routes.mjs @@ -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' }, + }, + ]; +} diff --git a/vite.config.mjs b/vite.config.mjs index 78c6238..9dc3765 100644 --- a/vite.config.mjs +++ b/vite.config.mjs @@ -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 ` \n ${url}\n `; + }); + + this.emitFile({ + type: 'asset', + fileName: 'sitemap.xml', + source: [ + '', + '', + ...urls, + '\n', + ].join('\n'), + }); + }, + }, { // Quick hack to redirect dynamic assets to the /dist/ directory configureServer(server) {