ぼざクリ タグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

73 lines
2.6 KiB

  1. import axios from 'axios'
  2. import fs from 'fs'
  3. import path from 'path'
  4. const formatDate = (date = new Date) => {
  5. const year = date.getFullYear ()
  6. const month = (date.getMonth () + 1).toString ().padStart (2, '0')
  7. const day = date.getDate ().toString ().padStart (2, '0')
  8. return `${ year }-${ month }-${ day }`
  9. }
  10. const SITE_TITLE = 'ぼざクリ タグ広場'
  11. const DOMAIN = 'https://hub.nizika.monster'
  12. const API_BASE_URL = 'https://hub.nizika.monster/api'
  13. const fetchPosts = async () => (await axios.get (`${ API_BASE_URL }/posts`)).data.posts
  14. const fetchPostIds = async () => (await fetchPosts ()).map (post => post.id)
  15. const fetchTags = async () => (await axios.get (`${ API_BASE_URL }/tags`)).data
  16. const fetchTagNames = async () => (await fetchTags ()).map (tag => tag.name)
  17. const fetchWikiPages = async () => (await axios.get (`${ API_BASE_URL }/wiki`)).data
  18. const fetchWikiTitles = async () => (await fetchWikiPages ()).map (page => page.title)
  19. const posts = (await fetchPosts ()).map (post => [
  20. `/posts/${ post.id }`,
  21. `${ post.title || post.url } | ${ SITE_TITLE }` ])
  22. const tags = (await fetchTags ()).map (tag => [
  23. `/posts?${ new URLSearchParams ({ tags: tag.name }) }`,
  24. `${ tag.name } | ${ SITE_TITLE }`])
  25. const wikiPages = (await fetchWikiPages ()).map (page => [
  26. `/wiki/${ encodeURIComponent (page.title) }`,
  27. `${ page.title } Wiki | ${ SITE_TITLE }`])
  28. const routes = [
  29. ['/', `${ SITE_TITLE } 〜 ぼざろクリーチャーシリーズ綜合リンク集サイト`],
  30. ...tags,
  31. ...posts,
  32. ['/wiki', `Wiki | ${ SITE_TITLE }`],
  33. ...wikiPages]
  34. const xml = `<?xml version="1.0" encoding="UTF-8"?>
  35. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  36. ${ routes.map (([route]) => ` <url>
  37. <loc>${ DOMAIN }${ route }</loc>
  38. <lastmod>${ formatDate () }</lastmod>
  39. <changefreq>daily</changefreq>
  40. </url>`).join ('\n') }
  41. </urlset>`
  42. const rss = `<?xml version="1.0" encoding="UTF-8"?>
  43. <rss version="2.0">
  44. <channel>
  45. <title>The Series of Bocchi the Rock! Creatures Hub Feed</title>
  46. <link>${ DOMAIN }/</link>
  47. <description>最新の投稿、タグ、Wiki ページの一覧</description>
  48. <language>ja</language>
  49. <pubDate>${ (new Date).toUTCString () }</pubDate>
  50. ${ routes.map (([route, title]) => ` <item>
  51. <title>${ title }</title>
  52. <link>${ DOMAIN }${ route }</link>
  53. <guid>${ DOMAIN }${ route }</guid>
  54. <pubDate>${ (new Date).toUTCString () }</pubDate>
  55. </item>`).join ('\n') }
  56. </channel>
  57. </rss>`
  58. fs.writeFileSync (path.resolve ('dist/sitemap.xml'), xml)
  59. fs.writeFileSync (path.resolve ('dist/rss.xml'), rss)