This repository was archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathcollectNextjsPages.js
50 lines (40 loc) · 1.86 KB
/
collectNextjsPages.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
// Adapted from serverless-next.js (v1.8.0)
// See original file in serverless-next.js folder.
// Changes:
// - Function is now collectNextjsPages (was prepareBuildManifests)
// - Function is now synchronous (used to be async)
// - Ignore API routes/pages
// - Public files are not tracked in manifest
// - Structure is an array of objects (was an object of objects)
const readPagesManifest = require('./readPagesManifest')
const getNetlifyRoute = require('./getNetlifyRoute')
const isDynamicRoute = require("./serverless-next.js/isDynamicRoute")
const expressifyDynamicRoute = require("./serverless-next.js/expressifyDynamicRoute")
const pathToRegexStr = require("./serverless-next.js/pathToRegexStr")
const isHtmlPage = p => p.endsWith(".html");
function collectNextjsPages() {
const pagesManifest = readPagesManifest();
const pages = Object.entries(pagesManifest)
return pages.map(([route, pageFile]) => {
// For each page, add an entry to our manifest
const page = {
// path to the page (/pages/about)
file: pageFile,
// whether the page includes dynamic URL parameters (/posts/[id])
isDynamic: isDynamicRoute(route),
// whether the page is HTML (does not use getInitialProps)
isHTML: isHtmlPage(pageFile)
}
// Route to the page (/about)
// If the page is dynamic, use url segments: /posts/[id] --> /posts/:id
page.route = page.isDynamic ? getNetlifyRoute(route) :route
// Regex for matching the page (/^\/about$/)
// NOTE: This route is different than the Netlify route set above!
// They are very similar, but not the same. See getNetlifyRoute.js for
// more information.
const _route = page.isDynamic ? expressifyDynamicRoute(route) : route
page.regex = pathToRegexStr(_route)
return page
})
}
module.exports = collectNextjsPages