From 2738d59d72ca08a22c0f9f6f06a8fed53c23293b Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sat, 26 Jul 2025 05:40:31 +0900 Subject: [PATCH] =?UTF-8?q?#81=20RSS=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/scripts/generate-sitemap.js | 55 ++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/frontend/scripts/generate-sitemap.js b/frontend/scripts/generate-sitemap.js index 6a08b16..ef03c9d 100644 --- a/frontend/scripts/generate-sitemap.js +++ b/frontend/scripts/generate-sitemap.js @@ -10,32 +10,63 @@ const formatDate = (date = new Date) => { return `${ year }-${ month }-${ day }` } +const SITE_TITLE = 'ぼざクリ タグ広場' 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 fetchPosts = async () => (await axios.get (`${ API_BASE_URL }/posts`)).data.posts +const fetchPostIds = async () => (await fetchPosts ()).map (post => post.id) -const fetchTagNames = - async () => (await axios.get (`${ API_BASE_URL }/tags`)).data.map (tag => tag.name) +const fetchTags = async () => (await axios.get (`${ API_BASE_URL }/tags`)).data +const fetchTagNames = async () => (await fetchTags ()).map (tag => tag.name) -const fetchWikiTitles = - async () => (await axios.get (`${ API_BASE_URL }/wiki`)).data.map (page => page.title) +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 = [ - '/', - ...(await fetchTagNames ()).map (tags => `/posts?${ (new URLSearchParams ({ tags })).toString () }`), - ...(await fetchPostIds ()).map (id => `/posts/${ id }`), - '/wiki', - ...(await fetchWikiTitles ()).map (title => `/wiki/${ encodeURIComponent (title) }`)] + ['/', `${ SITE_TITLE } 〜 ぼざろクリーチャーシリーズ綜合リンク集サイト`], + ...tags, + ...posts, + ['/wiki', `Wiki | ${ SITE_TITLE }`], + ...wikiPages] const xml = ` -${ routes.map (route => ` +${ routes.map (([route]) => ` ${ DOMAIN }${ route } ${ formatDate () } daily `).join ('\n') } ` +const rss = ` + + + The Series of Bocchi the Rock! Creatures Hub Feed + ${ DOMAIN }/ + 最新の投稿、タグ、Wiki ページの一覧 + ja + ${ (new Date).toUTCString () } +${ routes.map (([route, title]) => ` + ${ title } + ${ DOMAIN }${ route } + ${ DOMAIN }${ route } + ${ (new Date).toUTCString () } + `).join ('\n') } + +` + fs.writeFileSync (path.resolve ('dist/sitemap.xml'), xml) +fs.writeFileSync (path.resolve ('dist/rss.xml'), rss)