-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
prerender-urls.js
45 lines (41 loc) · 976 Bytes
/
prerender-urls.js
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
34
35
36
37
38
39
40
41
42
43
44
45
const { generateFileList } = require('./src/crawler');
const { join } = require('path');
const fs = require('fs');
const parseMD = require('parse-md').default;
const [blogs] = generateFileList(join(__dirname, 'content')).nodes;
module.exports = () => {
const pages = [
{
url: '/',
seo: {
cover: '/assets/profile.jpg'
}
},
{ url: '/contact/' },
{ url: '/contact/success' }
];
// adding blogs list posts page
pages.push({
url: '/blogs/',
data: blogs
});
// adding all blog pages
pages.push(...blogs.edges.map(blog => {
let data;
if (blog.format === 'md') {
const { content } = parseMD(fs.readFileSync(join('content', 'blog', blog.id), 'utf-8'));
data = content;
} else {
data = fs.readFileSync(join('content', 'blog', blog.id), 'utf-8').replace(/---(.*(\r)?\n)*---/, '');
}
return {
url: `/blog/${blog.id}`,
seo: blog.details,
data: {
details: blog.details,
content: data
}
};
}));
return pages;
};