|
| 1 | +export const sitemap = ''; |
| 2 | +import glob from 'glob'; |
| 3 | +import { getStaticPaths as getBlogPaths } from './pages/blog/[blog]'; |
| 4 | +// import { getStaticPaths as getBlogPaths } from './pages/blog/[blog]'; |
| 5 | + |
| 6 | +export const generateSitemap = async () => { |
| 7 | + const pagesDir = './pages/**/*.*'; |
| 8 | + const posts = await glob.sync(pagesDir); |
| 9 | + |
| 10 | + const pagePaths = posts |
| 11 | + .filter((path) => !path.includes('[')) |
| 12 | + .filter((path) => !path.includes('/_')) |
| 13 | + .map((path) => path.slice(1)); |
| 14 | + |
| 15 | + const blogPaths = await getBlogPaths().paths; |
| 16 | + // console.log(blogs); |
| 17 | + |
| 18 | + // console.log(JSON.stringify(pages, null, 2)); |
| 19 | + // const templates = posts |
| 20 | + // .filter((path) => path.includes('[')) |
| 21 | + // .filter((path) => path.includes(']')) |
| 22 | + // .filter((path) => !path.includes('/_')).map(path => `.${path}`); |
| 23 | + |
| 24 | + // console.log(JSON.stringify(templates, null, 2)); |
| 25 | + |
| 26 | + // for (const temp of templates) { |
| 27 | + // console.log(temp); |
| 28 | + // const imports = await import(`${temp}`); |
| 29 | + // console.log(imports); |
| 30 | + // const { getStaticPaths } = await import(`${temp}`); |
| 31 | + // console.log(getStaticPaths); |
| 32 | + // } |
| 33 | + |
| 34 | + const sitemap = ` |
| 35 | +<?xml version="1.0" encoding="UTF-8"?> |
| 36 | +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
| 37 | + <url> |
| 38 | + <loc>https://vriad.com</loc> |
| 39 | + <lastmod>2020-06-01</lastmod> |
| 40 | + </url> |
| 41 | +${[...pagePaths, ...blogPaths].map((path) => { |
| 42 | + const item = [`<url>`]; |
| 43 | + item.push(` <loc>https://vriad.com${path}</loc>`); |
| 44 | + item.push(` <lastmod>2020-06-01</lastmod>`); |
| 45 | + return [`<url>`]; |
| 46 | +})} |
| 47 | +
|
| 48 | + <url> |
| 49 | + <loc>https://vriad.com/essay/zod</loc> |
| 50 | + <lastmod>2020-03-28</lastmod> |
| 51 | + </url> |
| 52 | + <url> |
| 53 | + <loc>https://vriad.com/essay/devii</loc> |
| 54 | + <lastmod>2020-05-28</lastmod> |
| 55 | + </url> |
| 56 | + <url> |
| 57 | + <loc>https://vriad.com/essay/say-no-to-emotion-core</loc> |
| 58 | + <lastmod>2020-06-05</lastmod> |
| 59 | + </url> |
| 60 | + <url> |
| 61 | + <loc>https://vriad.com/essay/css-in-js-is-inevitable</loc> |
| 62 | + <lastmod>2020-06-07</lastmod> |
| 63 | + </url> |
| 64 | +</urlset>`; |
| 65 | + |
| 66 | + return sitemap; |
| 67 | +}; |
0 commit comments