-
Notifications
You must be signed in to change notification settings - Fork 4
/
next-sitemap.config.js
53 lines (44 loc) · 1.45 KB
/
next-sitemap.config.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
46
47
48
49
50
51
52
53
const fsStd = require('fs');
const pathStd = require('path');
const { promises: fs } = fsStd;
const targetLocale = process.env.TARGET_LOCALE;
const staticPart = `/${targetLocale}/docs/`;
const contentCachePath = 'cache';
const pageFileName = 'index.json';
const pagesPath = `${contentCachePath}/files`;
const config = {
siteUrl: process.env.BASE_PATH,
generateRobotsTxt: false,
exclude: ['/translation-status-priority', '/translation-status-general'],
// Default transformation function
transform: async (config, path) => {
// TODO connect to page data
const isWebDokPage = path.indexOf(staticPart) >= 0;
if (isWebDokPage) {
const slug = path.replace(staticPart, '');
const file = await fs.readFile(
pathStd.resolve(pagesPath, slug, pageFileName),
'utf-8'
);
const pageData = JSON.parse(file);
const { translationLastUpdatedAt, hasContent } = pageData;
if (!hasContent) {
return undefined;
}
return {
loc: path, // => this will be exported as http(s)://<config.siteUrl>/<path>
lastmod: translationLastUpdatedAt
? new Date(translationLastUpdatedAt).toISOString()
: undefined,
};
}
return {
loc: path, // => this will be exported as http(s)://<config.siteUrl>/<path>
};
},
// TODO:??
// additionalPaths: async (config) => [
// await config.transform(config, '/additional-page'),
// ],
};
module.exports = config;