Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Commit

Permalink
docs(site): Fix playroom routing in ghpages (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltaranto authored Dec 4, 2018
1 parent 82fdd5c commit fef3e43
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
50 changes: 30 additions & 20 deletions docs/src/components/App/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const allRoutes = [
{
route:
process.env.NODE_ENV === 'production' ?
'/playroom' :
`${process.env.BASE_HREF}playroom` :
'http://localhost:9000/',
title: 'Playroom',
category: 'Tools',
Expand Down Expand Up @@ -142,6 +142,34 @@ class Header extends Component {
});
};

renderListItem = demoSpec => {
const isExternal = demoSpec.target === '_blank';
const ComponentItem = isExternal ? 'a' : Link;
const linkDestination = isExternal ?
{ href: demoSpec.route } :
{ to: demoSpec.route };

return (
<WithHighlighting
key={demoSpec.title}
highlighted={demoSpec.highlighted}>
<Text headline regular>
<ComponentItem
ref={
demoSpec.highlighted ?
this.highlightedRef :
''
}
className={styles.link}
target={demoSpec.target}
{...linkDestination}>
{demoSpec.title}
</ComponentItem>
</Text>
</WithHighlighting>
);
}

render() {
const { fullWidth } = this.props;
const { menuOpen, displayComponents, highlightedElement } = this.state;
Expand Down Expand Up @@ -211,25 +239,7 @@ class Header extends Component {
</h2>
</Card>
<Card transparent>
{routes.map(demoSpec => (
<WithHighlighting
key={demoSpec.title}
highlighted={demoSpec.highlighted}>
<Text headline regular>
<Link
ref={
demoSpec.highlighted ?
this.highlightedRef :
''
}
className={styles.link}
to={demoSpec.route}
target={demoSpec.target}>
{demoSpec.title}
</Link>
</Text>
</WithHighlighting>
))}
{routes.map(this.renderListItem)}
</Card>
</Fragment>
);
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"build": "npm run clean && npm run compile && npm run playroom:build",
"build-gh-pages": "BASE_HREF=/seek-style-guide/ npm run build",
"deploy-gh-pages": "node scripts/deploy-gh-pages.js",
"preview-gh-pages": "npm run build-gh-pages && node scripts/preview-gh-pages",
"deploy-surge": "surge -p ./docs/dist",
"playroom": "playroom",
"playroom:build": "playroom build",
Expand Down Expand Up @@ -107,6 +108,7 @@
"html-minifier": "^3.5.6",
"html-sketchapp-cli": "0.6.2",
"html-webpack-plugin": "^3.2.0",
"http-server": "^0.11.1",
"husky": "^0.14.3",
"ignore-loader": "^0.1.2",
"import-glob": "^1.5.0",
Expand All @@ -118,6 +120,7 @@
"less-vars-to-js": "^1.2.0",
"mini-css-extract-plugin": "^0.4.4",
"module-alias": "^2.0.1",
"mv": "^2.1.1",
"opn": "^5.1.0",
"opn-cli": "^3.1.0",
"playroom": "0.5.1",
Expand Down
28 changes: 28 additions & 0 deletions scripts/preview-gh-pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { promisify } = require('util');
const mv = promisify(require('mv'));
const opn = require('opn');
const fs = require('fs');
const { createServer } = require('http-server');
const portfinder = require('portfinder');
portfinder.basePort = 4000;

(async() => {
if (!fs.existsSync('docs/dist/seek-style-guide')) { // eslint-disable-line no-sync
await mv('docs/dist', 'docs/seek-style-guide', { mkdirp: true });
await mv('docs/seek-style-guide', 'docs/dist/seek-style-guide', { mkdirp: true });
}

const port = await portfinder.getPortPromise();
const host = '127.0.0.1';
const url = `http://${host}:${port}/seek-style-guide/`;

createServer({ root: 'docs/dist', cache: -1 })
.listen(port, host, err => {
if (err) {
throw new Error(err);
}

console.log(`Preview available at: ${url}`);
opn(url);
});
})();

0 comments on commit fef3e43

Please sign in to comment.