This commit is contained in:
@@ -2,6 +2,14 @@ import axios from 'axios'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const formatDate = (date = new Date) => {
|
||||
const year = date.getFullYear ()
|
||||
const month = (date.getMonth () + 1).toString ().padStart (2, '0')
|
||||
const day = date.getDate ().toString ().padStart (2, '0')
|
||||
|
||||
return `${ year }-${ month }-${ day }`
|
||||
}
|
||||
|
||||
const DOMAIN = 'https://hub.nizika.monster'
|
||||
const API_BASE_URL = 'https://hub.nizika.monster/api'
|
||||
|
||||
@@ -18,17 +26,16 @@ 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']
|
||||
...(await fetchWikiTitles ()).map (title => `/wiki/${ encodeURIComponent (title) }`)]
|
||||
|
||||
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') }
|
||||
${ routes.map (route => ` <url>
|
||||
<loc>${ DOMAIN }${ route }</loc>
|
||||
<lastmod>${ formatDate () }</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>`).join ('\n') }
|
||||
</urlset>`
|
||||
|
||||
fs.writeFileSync (path.resolve ('dist/sitemap.xml'), xml)
|
||||
|
||||
Reference in New Issue
Block a user