forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
precompile.js
executable file
·20 lines (16 loc) · 977 Bytes
/
precompile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const developerRedirects = require('../redirects/static/developer')
const { latest } = require('../../lib/enterprise-server-releases')
const latestDevRedirects = {}
// Replace hardcoded 'latest' with real value in the redirected path
Object.entries(developerRedirects).forEach(([oldPath, newPath]) => {
latestDevRedirects[oldPath] = newPath.replace('enterprise-server@latest', `enterprise-server@${latest}`)
})
// This function runs at server warmup and precompiles possible redirect routes.
// It outputs them in key-value pairs within a neat Javascript object: { oldPath: newPath }
module.exports = async function precompileRedirects (pageList) {
const allRedirects = Object.assign({}, latestDevRedirects)
// CURRENT PAGES PERMALINKS AND FRONTMATTER
// create backwards-compatible old paths for page permalinks and frontmatter redirects
await Promise.all(pageList.map(async (page) => Object.assign(allRedirects, page.buildRedirects())))
return allRedirects
}