みてるぞ 5 days ago
parent
commit
9cfa9696d4
2 changed files with 33 additions and 0 deletions
  1. +1
    -0
      frontend/package.json
  2. +32
    -0
      frontend/scripts/generate-sitemap.ts

+ 1
- 0
frontend/package.json View File

@@ -6,6 +6,7 @@
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"postbuild": "ts-node scripts/generate-sitemap.ts",
"lint": "eslint .",
"preview": "vite preview"
},


+ 32
- 0
frontend/scripts/generate-sitemap.ts View File

@@ -0,0 +1,32 @@
import axios from 'axios'
import fs from 'fs'
import path from 'path'

const DOMAIN = 'https://hub.nizika.monster'
const API_BASE_URL = 'https://hub.nizika.monster/api'

const fetchPostIds =
async () => (await axios.get (`${ API_BASE_URL }/posts`)).data.posts.map (post => post.id)

const fetchTagNames =
async () => (await axios.get (`${ API_BASE_URL }/tags`)).data.map (tag => tag.name)

const fetchWikiTitles =
async () => (await axios.get (`${ API_BASE_URL }/wiki`)).data.map (page => page.title)

const routes = [
'/',
...(await fetchTagNames ()).map (tags => `/posts?${ (new URLSearchParams ({ tags })).toString () }`),
...(await fetchPostIds ()).map (id => `/posts/${ id }`),
'/tags',
'/tags/nico',
'/wiki',
'/wiki/changes',
...(await fetchWikiTitles ()).map (title => `/wiki/${ encodeURIComponent (title) }`),
'/users',
'/users/settings']

const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${ routes.map (route => ` <url><loc>${ DOMAIN }${ route }</loc></url>`).join ('\n') }
</urlset>`

Loading…
Cancel
Save