1
0
mirror of synced 2025-12-22 03:16:52 -05:00

React: All landing pages (#19943)

* default all remaining landing pages to react, update tests
This commit is contained in:
Mike Surowiec
2021-06-17 10:04:53 -07:00
committed by GitHub
parent 87f6bc327e
commit 5396f5f9e4
16 changed files with 135 additions and 96 deletions

View File

@@ -1,36 +1,41 @@
const pathToRegexp = require('path-to-regexp')
const { productIds } = require('../lib/all-products')
const versionIds = Object.keys(require('../lib/all-versions'))
const { FEATURE_NEXTJS } = process.env;
const productIds = [
const enabledSubSections = [
// 'actions',
'admin',
"billing",
"code-security",
"codespaces",
"communities",
"desktop",
"developers",
"discussions",
// 'admin',
// "billing",
// "code-security",
// "codespaces",
// "communities",
// "desktop",
// "developers",
// "discussions",
// 'early-access',
"education",
// "education",
// 'github',
"graphql",
// "graphql",
// 'insights',
"issues",
"organizations",
// "issues",
// "organizations",
// 'packages',
"pages",
"rest",
"sponsors",
// "pages",
// "rest",
// "sponsors",
];
const landingPageExp = pathToRegexp('/:locale/:versionId?/:productId')
const homePageExp = pathToRegexp('/:locale/:versionId?')
const productPageExp = pathToRegexp('/:locale/:versionId?/:productId')
const subSectionExp = pathToRegexp('/:locale/:versionId?/:productId/:subSection')
module.exports = function isNextRequest(req, res, next) {
req.renderWithNextjs = false;
if (FEATURE_NEXTJS) {
if (FEATURE_NEXTJS && !req.path.startsWith('/_next/')) {
if ('nextjs' in req.query) {
req.renderWithNextjs = true;
} else {
@@ -40,10 +45,15 @@ module.exports = function isNextRequest(req, res, next) {
const { pathname } = new URL(req.originalUrl, "https://docs.github.com");
// Should the current path be rendered by NextJS?
const landingPageMatch = landingPageExp.exec(pathname)
if (landingPageMatch) {
const productId = landingPageMatch[3]
req.renderWithNextjs = productIds.includes(productId)
const homePageMatch = homePageExp.exec(pathname)
const productPageMatch = productPageExp.exec(pathname)
const subSectionMatch = subSectionExp.exec(pathname)
if (homePageMatch && (!homePageMatch[2] || versionIds.includes(homePageMatch[2]))) {
req.renderWithNextjs = true
} else if (productPageMatch && productIds.includes(productPageMatch[3])) {
req.renderWithNextjs = true
} else if (subSectionMatch) {
req.renderWithNextjs = enabledSubSections.includes(subSectionMatch[4])
}
}
}