Skip to content

Commit 6460f3e

Browse files
authored
Merge pull request react-bootstrap#5318 from react-bootstrap/feat/netlify-docs-alert
feat(netlify): more resilient docs alert implementation
2 parents 2be1d53 + 391c083 commit 6460f3e

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

www/config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,21 @@ const bootstrapVersion = require('bootstrap/package.json').version;
1313

1414
const shortVersion = bootstrapVersion.split('.').slice(0, 2).join('.');
1515

16+
const netlify =
17+
process.env.NETLIFY === 'true'
18+
? {
19+
pullRequest: process.env.PULL_REQUEST,
20+
reviewId: process.env.REVIEW_ID,
21+
branch: process.env.BRANCH,
22+
}
23+
: null;
24+
1625
const config = {
1726
bootstrapVersion,
1827
docsUrl: `https://getbootstrap.com/docs/${shortVersion}`,
1928
version: require('../package.json').version,
2029
cssHash: getIntegrity('bootstrap/dist/css/bootstrap.min.css'),
30+
netlify,
2131
};
2232

2333
module.exports = config;

www/src/components/DocsAlert.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import Alert from 'react-bootstrap/Alert';
3+
import Container from 'react-bootstrap/Container';
4+
import Row from 'react-bootstrap/Row';
5+
6+
export default function DocsAlert() {
7+
const { netlify } = config;
8+
return (
9+
netlify && (
10+
<Container fluid>
11+
<Row>
12+
<Alert variant="warning" className="w-100">
13+
You are currently viewing the auto-generated docs from{' '}
14+
{netlify.pullRequest ? (
15+
<span>
16+
a{' '}
17+
<Alert.Link
18+
href={`https://github.com/react-bootstrap/react-bootstrap/pull/${netlify.reviewId}`}
19+
>
20+
pull request
21+
</Alert.Link>
22+
</span>
23+
) : (
24+
<span>the {netlify.branch} branch</span>
25+
)}
26+
. The docs for the current release are available at{' '}
27+
<Alert.Link href="https://react-bootstrap.github.io/">
28+
https://react-bootstrap.github.io/
29+
</Alert.Link>
30+
</Alert>
31+
</Row>
32+
</Container>
33+
)
34+
);
35+
}

www/src/layouts/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import NavMain from '../components/NavMain';
77
import Heading from '../components/Heading';
88
import CodeBlock from '../components/CodeBlock';
99
import LinkedHeading from '../components/LinkedHeading';
10+
import DocsAlert from '../components/DocsAlert';
1011

1112
const styles = css`
1213
.gray > :not(:first-child) {
@@ -46,6 +47,7 @@ function DefaultLayout({ children, location, grayscale = true }) {
4647
return (
4748
<div className={grayscale ? styles.gray : undefined}>
4849
<NavMain activePage={location.pathname} />
50+
<DocsAlert />
4951
<MDXProvider components={components}>{children}</MDXProvider>
5052
</div>
5153
);

0 commit comments

Comments
 (0)