Merge branch 'main' of https://git.miteruzo.com/miteruzo/btrc-hub
This commit is contained in:
@@ -10,32 +10,63 @@ const formatDate = (date = new Date) => {
|
|||||||
return `${ year }-${ month }-${ day }`
|
return `${ year }-${ month }-${ day }`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SITE_TITLE = 'ぼざクリ タグ広場'
|
||||||
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'
|
||||||
|
|
||||||
const fetchPostIds =
|
const fetchPosts = async () => (await axios.get (`${ API_BASE_URL }/posts`)).data.posts
|
||||||
async () => (await axios.get (`${ API_BASE_URL }/posts`)).data.posts.map (post => post.id)
|
const fetchPostIds = async () => (await fetchPosts ()).map (post => post.id)
|
||||||
|
|
||||||
const fetchTagNames =
|
const fetchTags = async () => (await axios.get (`${ API_BASE_URL }/tags`)).data
|
||||||
async () => (await axios.get (`${ API_BASE_URL }/tags`)).data.map (tag => tag.name)
|
const fetchTagNames = async () => (await fetchTags ()).map (tag => tag.name)
|
||||||
|
|
||||||
const fetchWikiTitles =
|
const fetchWikiPages = async () => (await axios.get (`${ API_BASE_URL }/wiki`)).data
|
||||||
async () => (await axios.get (`${ API_BASE_URL }/wiki`)).data.map (page => page.title)
|
const fetchWikiTitles = async () => (await fetchWikiPages ()).map (page => page.title)
|
||||||
|
|
||||||
|
const posts = (await fetchPosts ()).map (post => [
|
||||||
|
`/posts/${ post.id }`,
|
||||||
|
`${ post.title || post.url } | ${ SITE_TITLE }` ])
|
||||||
|
|
||||||
|
const tags = (await fetchTags ()).map (tag => [
|
||||||
|
`/posts?${ new URLSearchParams ({ tags: tag.name }) }`,
|
||||||
|
`${ tag.name } | ${ SITE_TITLE }`])
|
||||||
|
|
||||||
|
const wikiPages = (await fetchWikiPages ()).map (page => [
|
||||||
|
`/wiki/${ encodeURIComponent (page.title) }`,
|
||||||
|
`${ page.title } Wiki | ${ SITE_TITLE }`])
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
'/',
|
['/', `${ SITE_TITLE } 〜 ぼざろクリーチャーシリーズ綜合リンク集サイト`],
|
||||||
...(await fetchTagNames ()).map (tags => `/posts?${ (new URLSearchParams ({ tags })).toString () }`),
|
...tags,
|
||||||
...(await fetchPostIds ()).map (id => `/posts/${ id }`),
|
...posts,
|
||||||
'/wiki',
|
['/wiki', `Wiki | ${ SITE_TITLE }`],
|
||||||
...(await fetchWikiTitles ()).map (title => `/wiki/${ encodeURIComponent (title) }`)]
|
...wikiPages]
|
||||||
|
|
||||||
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>
|
${ routes.map (([route]) => ` <url>
|
||||||
<loc>${ DOMAIN }${ route }</loc>
|
<loc>${ DOMAIN }${ route }</loc>
|
||||||
<lastmod>${ formatDate () }</lastmod>
|
<lastmod>${ formatDate () }</lastmod>
|
||||||
<changefreq>daily</changefreq>
|
<changefreq>daily</changefreq>
|
||||||
</url>`).join ('\n') }
|
</url>`).join ('\n') }
|
||||||
</urlset>`
|
</urlset>`
|
||||||
|
|
||||||
|
const rss = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<rss version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title>The Series of Bocchi the Rock! Creatures Hub Feed</title>
|
||||||
|
<link>${ DOMAIN }/</link>
|
||||||
|
<description>最新の投稿、タグ、Wiki ページの一覧</description>
|
||||||
|
<language>ja</language>
|
||||||
|
<pubDate>${ (new Date).toUTCString () }</pubDate>
|
||||||
|
${ routes.map (([route, title]) => ` <item>
|
||||||
|
<title>${ title }</title>
|
||||||
|
<link>${ DOMAIN }${ route }</link>
|
||||||
|
<guid>${ DOMAIN }${ route }</guid>
|
||||||
|
<pubDate>${ (new Date).toUTCString () }</pubDate>
|
||||||
|
</item>`).join ('\n') }
|
||||||
|
</channel>
|
||||||
|
</rss>`
|
||||||
|
|
||||||
fs.writeFileSync (path.resolve ('dist/sitemap.xml'), xml)
|
fs.writeFileSync (path.resolve ('dist/sitemap.xml'), xml)
|
||||||
|
fs.writeFileSync (path.resolve ('dist/rss.xml'), rss)
|
||||||
|
|||||||
Reference in New Issue
Block a user