forked from opennextjs/opennextjs-netlify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpages.js
40 lines (31 loc) · 1.38 KB
/
pages.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
const getPagesManifest = require('../../helpers/getPagesManifest')
const isHtmlFile = require('../../helpers/isHtmlFile')
const isFrameworkRoute = require('../../helpers/isFrameworkRoute')
const isApiRoute = require('../../helpers/isApiRoute')
const isRouteInPrerenderManifest = require('../../helpers/isRouteInPrerenderManifest')
const isRouteWithDataRoute = require('../../helpers/isRouteWithDataRoute')
const asyncForEach = require('../../helpers/asyncForEach')
const getPages = async ({ publishPath }) => {
// Get HTML and SSR pages and API endpoints from the NextJS pages manifest
const pagesManifest = await getPagesManifest({ publishPath })
// Collect pages
const pages = []
// Parse pages
await asyncForEach(Object.entries(pagesManifest), async ([route, filePath]) => {
// Ignore HTML files
if (isHtmlFile(filePath)) return
// Skip framework pages, such as _app and _error
if (isFrameworkRoute(route)) return
// Skip API endpoints
if (isApiRoute(route)) return
// Skip page if it is actually used with getStaticProps
if (await isRouteInPrerenderManifest({ route, publishPath })) return
// Skip page if it has a data route (because then it is a page with
// getServerSideProps)
if (await isRouteWithDataRoute({ route, publishPath })) return
// Add page
pages.push({ route, filePath })
})
return pages
}
module.exports = getPages