-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext-sitemap.js
More file actions
58 lines (51 loc) · 1.48 KB
/
next-sitemap.js
File metadata and controls
58 lines (51 loc) · 1.48 KB
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
54
55
56
57
58
const orgId = process.env.NEXT_PUBLIC_PLANNER_ORG_ID;
const {
listStopPlaces,
} = require('./scripts/generate-stopplaces/list-stop-places');
function getOrgData() {
const org = require(`./orgs/${orgId}.json`);
return {
sitemapUrls: org.urls.sitemapUrls,
authPrefix: authIdToPrefix(org.authorityId),
};
}
const orgData = getOrgData();
const environmentUrls = orgData.sitemapUrls;
const environment = process.env.NEXT_PUBLIC_ENVIRONMENT;
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: environment ? environmentUrls[environment] : environmentUrls['dev'],
generateIndexSitemap: false,
sitemapSize: 7000,
generateRobotsTxt: true,
robotsTxtOptions: {
policies:
environment === 'production'
? [{ userAgent: '*', allow: '/' }]
: [{ userAgent: '*', disallow: '/' }],
},
// Adds path as it doesn't support dynamic routes.
async additionalPaths(config) {
const data = await listStopPlaces(orgData.authPrefix);
const result = [];
// @TODO Consider if we should prepopulate this for better SEO for
// quays.
result.push({
loc: '/departures',
changefreq: 'yearly',
priority: 0.7,
lastmod: new Date().toISOString(),
});
for (const id of data) {
result.push({
loc: `/departures/${encodeURIComponent(id)}`,
changefreq: 'always',
priority: 0.3,
});
}
return result;
},
};
function authIdToPrefix(authId) {
return authId.split(':')[0];
}