ぼざクリ タグ広場 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.
 
 
 
 
 
 

42 lines
1.4 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 DOMAIN = 'https://hub.nizika.monster'
  11. const API_BASE_URL = 'https://hub.nizika.monster/api'
  12. const fetchPostIds =
  13. async () => (await axios.get (`${ API_BASE_URL }/posts`)).data.posts.map (post => post.id)
  14. const fetchTagNames =
  15. async () => (await axios.get (`${ API_BASE_URL }/tags`)).data.map (tag => tag.name)
  16. const fetchWikiTitles =
  17. async () => (await axios.get (`${ API_BASE_URL }/wiki`)).data.map (page => page.title)
  18. const routes = [
  19. '/',
  20. ...(await fetchTagNames ()).map (tags => `/posts?${ (new URLSearchParams ({ tags })).toString () }`),
  21. ...(await fetchPostIds ()).map (id => `/posts/${ id }`),
  22. '/wiki',
  23. ...(await fetchWikiTitles ()).map (title => `/wiki/${ encodeURIComponent (title) }`)]
  24. const xml = `<?xml version="1.0" encoding="UTF-8"?>
  25. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  26. ${ routes.map (route => ` <url>
  27. <loc>${ DOMAIN }${ route }</loc>
  28. <lastmod>${ formatDate () }</lastmod>
  29. <changefreq>daily</changefreq>
  30. </url>`).join ('\n') }
  31. </urlset>`
  32. fs.writeFileSync (path.resolve ('dist/sitemap.xml'), xml)