|
- 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 SITE_TITLE = 'ぼざクリ タグ広場'
- const DOMAIN = 'https://hub.nizika.monster'
- const API_BASE_URL = 'https://hub.nizika.monster/api'
-
- const fetchPosts = async () => (await axios.get (`${ API_BASE_URL }/posts`)).data.posts
- const fetchPostIds = async () => (await fetchPosts ()).map (post => post.id)
-
- const fetchTags = async () => (await axios.get (`${ API_BASE_URL }/tags`)).data
- const fetchTagNames = async () => (await fetchTags ()).map (tag => tag.name)
-
- const fetchWikiPages = async () => (await axios.get (`${ API_BASE_URL }/wiki`)).data
- 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 = [
- ['/', `${ SITE_TITLE } 〜 ぼざろクリーチャーシリーズ綜合リンク集サイト`],
- ...tags,
- ...posts,
- ['/wiki', `Wiki | ${ SITE_TITLE }`],
- ...wikiPages]
-
- 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>
- <lastmod>${ formatDate () }</lastmod>
- <changefreq>daily</changefreq>
- </url>`).join ('\n') }
- </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/rss.xml'), rss)
|