This commit is contained in:
@@ -2,6 +2,14 @@ import axios from 'axios'
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
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 DOMAIN = 'https://hub.nizika.monster'
|
||||||
const API_BASE_URL = 'https://hub.nizika.monster/api'
|
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 fetchTagNames ()).map (tags => `/posts?${ (new URLSearchParams ({ tags })).toString () }`),
|
||||||
...(await fetchPostIds ()).map (id => `/posts/${ id }`),
|
...(await fetchPostIds ()).map (id => `/posts/${ id }`),
|
||||||
'/tags',
|
|
||||||
'/tags/nico',
|
|
||||||
'/wiki',
|
'/wiki',
|
||||||
'/wiki/changes',
|
...(await fetchWikiTitles ()).map (title => `/wiki/${ encodeURIComponent (title) }`)]
|
||||||
...(await fetchWikiTitles ()).map (title => `/wiki/${ encodeURIComponent (title) }`),
|
|
||||||
'/users',
|
|
||||||
'/users/settings']
|
|
||||||
|
|
||||||
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<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>`
|
</urlset>`
|
||||||
|
|
||||||
fs.writeFileSync (path.resolve ('dist/sitemap.xml'), xml)
|
fs.writeFileSync (path.resolve ('dist/sitemap.xml'), xml)
|
||||||
|
|||||||
Reference in New Issue
Block a user