Skip to content

Commit

Permalink
[website] Exclude experiment pages in production (mui#35180)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored and Daniel Rabe committed Nov 29, 2022
1 parent 7c36e45 commit f2e63fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 5 additions & 1 deletion docs/next.config.js
Expand Up @@ -170,7 +170,11 @@ module.exports = withDocsInfra({
const prefix = userLanguage === 'en' ? '' : `/${userLanguage}`;

pages2.forEach((page) => {
if (page.pathname.startsWith('/experiments') && process.env.DEPLOY_ENV !== 'production') {
// The experiments pages are only meant for experiments, they shouldn't leak to production.
if (
(page.pathname.startsWith('/experiments/') || page.pathname === '/experiments') &&
process.env.DEPLOY_ENV === 'production'
) {
return;
}
// The blog is not translated
Expand Down
17 changes: 16 additions & 1 deletion docs/nextConfigDocsInfra.js
@@ -1,3 +1,14 @@
/**
* See the docs of the Netlify environment variables:
* https://docs.netlify.com/configure-builds/environment-variables/#build-metadata.
*
* A few comments:
* - process.env.CONTEXT === 'production' means that the branch in Netlify was configured as production.
* For example, the `master` branch of the Core team is considered a `production` build on Netlify based
* on https://app.netlify.com/sites/material-ui/settings/deploys#branches.
* - Each team has different site https://app.netlify.com/teams/mui/sites.
* The following logic must be compatible with all of them.
*/
let DEPLOY_ENV = 'development';

// Same as process.env.PULL_REQUEST_ID
Expand All @@ -9,12 +20,16 @@ if (process.env.CONTEXT === 'production' || process.env.CONTEXT === 'branch-depl
DEPLOY_ENV = 'production';
}

// The 'master' and 'next' branches are NEVER a production environment. We use these branches for staging.
if (
process.env.CONTEXT === 'branch-deploy' &&
(process.env.CONTEXT === 'production' || process.env.CONTEXT === 'branch-deploy') &&
(process.env.HEAD === 'master' || process.env.HEAD === 'next')
) {
DEPLOY_ENV = 'staging';
}
/**
* ====================================================================================
*/

process.env.DEPLOY_ENV = DEPLOY_ENV;

Expand Down
8 changes: 3 additions & 5 deletions docs/pages/experiments/index.js
Expand Up @@ -56,13 +56,11 @@ export default function Experiments({ experiments }) {
<Box sx={{ textAlign: 'left' }}>
<ul>
<Typography component="li">
All the files under <code>/experiments</code> are committed to git.
The files under <code>/experiments/*</code> are committed to git.
</Typography>
<Typography component="li">
URLs start with <code>/experiments/*</code> are deployed only on the pull request.
</Typography>
<Typography component="li">
<code>/experiments/*</code> are not included in docsearch indexing.
These URLs (start with <code>/experiments/*</code>) are not accessible in
production.
</Typography>
</ul>
</Box>
Expand Down

0 comments on commit f2e63fb

Please sign in to comment.