forked from colinhacks/devii
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sitemap.ts
33 lines (28 loc) · 919 Bytes
/
sitemap.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export const sitemap = '';
import glob from 'glob';
import { globals } from './globals';
import { getStaticPaths as getBlogPaths } from './pages/blog/[blog]';
export const generateSitemap = async () => {
const pagesDir = './pages/**/*.*';
const posts = await glob.sync(pagesDir);
const pagePaths = posts
.filter((path) => !path.includes('['))
.filter((path) => !path.includes('/_'))
.map((path) => path.slice(1));
const blogPaths = await getBlogPaths().paths;
const sitemap = `
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>${globals.url}</loc>
<lastmod>2020-06-01</lastmod>
</url>
${[...pagePaths, ...blogPaths].map((path) => {
const item = [`<url>`];
item.push(` <loc>${globals.url}${path}</loc>`);
item.push(` <lastmod>2020-06-01</lastmod>`);
return [`<url>`];
})}
</urlset>`;
return sitemap;
};