Skip to content

Commit 88ac305

Browse files
authored
Fix Gatsby Hashes (codesandbox#391)
* Hopefully fix hashes * Footer everywhere * Fix layout * Fix query * Fix another cache * Another change to pageQuery * Yarn revert
1 parent 84c140d commit 88ac305

File tree

12 files changed

+89
-56
lines changed

12 files changed

+89
-56
lines changed

packages/codesandbox-api/package.json

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"main": "dist/codesandbox.umd.js",
77
"module": "dist/codesandbox.es5.js",
88
"typings": "dist/types/codesandbox.d.ts",
9-
"files": ["dist"],
9+
"files": [
10+
"dist"
11+
],
1012
"author": "Ives van Hoorne <[email protected]>",
1113
"repository": {
1214
"type": "git",
@@ -20,41 +22,47 @@
2022
"lint": "tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
2123
"prebuild": "rimraf dist",
2224
"build:clean": "tsc && rollup -c",
23-
"build":
24-
"tsc && rollup -c && rimraf compiled && typedoc --out dist/docs --target es6 --theme minimal src",
25-
"start":
26-
"nodemon --watch \"src/**/*.ts\" -e ts --exec \"npm run build:clean\"",
25+
"build": "tsc && rollup -c && rimraf compiled && typedoc --out dist/docs --target es6 --theme minimal src",
26+
"start": "nodemon --watch \"src/**/*.ts\" -e ts --exec \"npm run build:clean\"",
2727
"test": "echo TODO",
2828
"test:watch": "jest --watch",
2929
"test:prod": "npm run lint && npm run test -- --coverage --no-cache",
3030
"deploy-docs": "ts-node tools/gh-pages-publish",
3131
"report-coverage": "cat ./coverage/lcov.info | coveralls",
3232
"commit": "git-cz",
33-
"semantic-release":
34-
"semantic-release pre && npm publish && semantic-release post",
33+
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
3534
"semantic-release-prepare": "ts-node tools/semantic-release-prepare",
3635
"precommit": "lint-staged"
3736
},
3837
"lint-staged": {
39-
"./{src,test}/**/*.ts": ["prettier --write --no-semi", "git add"]
38+
"./{src,test}/**/*.ts": [
39+
"prettier --write --no-semi",
40+
"git add"
41+
]
4042
},
4143
"config": {
4244
"commitizen": {
4345
"path": "node_modules/cz-conventional-changelog"
4446
},
4547
"validate-commit-msg": {
4648
"types": "conventional-commit-types",
47-
"helpMessage":
48-
"Use \"npm run commit\" instead, we use conventional-changelog format :) (https://github.com/commitizen/cz-cli)"
49+
"helpMessage": "Use \"npm run commit\" instead, we use conventional-changelog format :) (https://github.com/commitizen/cz-cli)"
4950
}
5051
},
5152
"jest": {
5253
"transform": {
5354
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
5455
},
5556
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
56-
"moduleFileExtensions": ["ts", "tsx", "js"],
57-
"coveragePathIgnorePatterns": ["/node_modules/", "/test/"],
57+
"moduleFileExtensions": [
58+
"ts",
59+
"tsx",
60+
"js"
61+
],
62+
"coveragePathIgnorePatterns": [
63+
"/node_modules/",
64+
"/test/"
65+
],
5866
"coverageThreshold": {
5967
"global": {
6068
"branches": 90,

packages/homepage/gatsby-node.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ exports.createPages = async ({ graphql, boundActionCreators }) => {
7979
// Redirect /index.html to root.
8080
createRedirect({
8181
fromPath: '/index.html',
82+
redirectInBrowser: true,
8283
toPath: '/',
8384
});
8485

@@ -129,3 +130,13 @@ exports.createPages = async ({ graphql, boundActionCreators }) => {
129130
}
130131
});
131132
};
133+
134+
exports.modifyWebpackConfig = ({ config }) => {
135+
config.merge({
136+
resolve: {
137+
root: resolve(__dirname, './src'),
138+
extensions: ['', '.js', '.jsx', '.json'],
139+
},
140+
});
141+
return config;
142+
};

packages/homepage/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
"devDependencies": {
4747
"gatsby-cli": "^1.1.20",
48-
"prettier": "^1.7.4"
48+
"prettier": "^1.8.2"
4949
},
5050
"browserslist": [
5151
"> 1%",

packages/homepage/src/screens/home/Footer.js renamed to packages/homepage/src/components/Footer.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from 'react';
22
import styled from 'styled-components';
33

4+
import Link from 'gatsby-link';
5+
46
import MaxWidth from 'common/components/flex/MaxWidth';
57

6-
import media from '../../utils/media';
8+
import media from '../utils/media';
79

810
const Container = styled.div`
911
display: flex;
@@ -59,12 +61,14 @@ const Authors = styled.div`
5961
`;
6062

6163
const Background = styled.div`
64+
position: relative;
6265
background-color: ${props => props.theme.background2.darken(0.2)};
63-
padding: 2rem;
66+
padding: 1rem;
67+
z-index: 100;
6468
`;
6569

6670
export default () => (
67-
<Background>
71+
<Background id="footer">
6872
<MaxWidth width={1280}>
6973
<Container>
7074
<Column>
@@ -80,6 +84,12 @@ export default () => (
8084
Search
8185
</a>
8286
</li>
87+
<li>
88+
<Link to="/changelog">Recent Updates</Link>
89+
</li>
90+
<li>
91+
<Link to="/docs">Documentation</Link>
92+
</li>
8393
<li>
8494
<a href="/patron" target="_blank" rel="noopener noreferrer">
8595
Patron

packages/homepage/src/components/StickyNavigation.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ const Navigation = styled.nav`
2121
height: 100vh;
2222
`};
2323
24+
${props =>
25+
props.absoluteTop &&
26+
css`
27+
position: absolute;
28+
top: ${props.absoluteTop}px;
29+
`};
30+
2431
${media.phone`
2532
padding-bottom: 1rem;
2633
position: relative;
@@ -100,8 +107,15 @@ export default class StickyNavigation extends React.PureComponent<Props> {
100107
componentDidMount() {
101108
window.addEventListener('scroll', this.handleScroll);
102109
const { y } = getScrollPos(Date.now(), false);
103-
this.top =
104-
y + document.getElementById('navigation').getBoundingClientRect().top;
110+
111+
const { top, height } = document
112+
.getElementById('navigation')
113+
.getBoundingClientRect();
114+
115+
this.top = y + top;
116+
this.height = height;
117+
this.footerTop =
118+
y + document.getElementById('footer').getBoundingClientRect().top;
105119
}
106120

107121
componentWillUnmount() {
@@ -111,10 +125,15 @@ export default class StickyNavigation extends React.PureComponent<Props> {
111125
handleScroll = () => {
112126
const { y } = getScrollPos(Date.now(), false);
113127

114-
if (y > this.top && !this.state.fixed) {
115-
this.setState({ fixed: true });
128+
if (y + this.height + 32 > this.footerTop) {
129+
this.setState({
130+
absoluteTop: this.footerTop - 32 - this.height,
131+
fixed: false,
132+
});
133+
} else if (y > this.top && !this.state.fixed) {
134+
this.setState({ fixed: true, absoluteTop: null });
116135
} else if (y < this.top && this.state.fixed) {
117-
this.setState({ fixed: false });
136+
this.setState({ fixed: false, absoluteTop: null });
118137
}
119138
};
120139

@@ -127,7 +146,11 @@ export default class StickyNavigation extends React.PureComponent<Props> {
127146
};
128147

129148
return (
130-
<Navigation fixed={this.state.fixed} id="navigation">
149+
<Navigation
150+
fixed={this.state.fixed}
151+
absoluteTop={this.state.absoluteTop}
152+
id="navigation"
153+
>
131154
<ul>
132155
{docs.map(({ node }) => (
133156
<NavigationItem key={node.frontmatter.title}>

packages/homepage/src/html.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { Component } from 'react';
2-
import * as PropTypes from 'prop-types';
32
import { TypographyStyle } from 'react-typography';
43
import typography from './utils/typography';
54

@@ -12,13 +11,8 @@ if (process.env.NODE_ENV === `production`) {
1211
}
1312
}
1413

15-
const propTypes = {
16-
headComponents: PropTypes.node.isRequired,
17-
body: PropTypes.node.isRequired,
18-
postBodyComponents: PropTypes.node.isRequired,
19-
};
20-
21-
class Html extends Component {
14+
// eslint-disable-next-line react/prefer-stateless-function
15+
export default class HTML extends Component {
2216
render() {
2317
let css;
2418
if (process.env.NODE_ENV === `production`) {
@@ -82,7 +76,3 @@ class Html extends Component {
8276
);
8377
}
8478
}
85-
86-
Html.propTypes = propTypes;
87-
88-
module.exports = Html;
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import styled, { ThemeProvider } from 'styled-components';
43

54
import theme from 'common/theme';
5+
import '../css/global.css';
66

77
import Navigation from '../components/Navigation';
8-
9-
import './index.css';
8+
import Footer from '../components/Footer';
109

1110
const Absolute = styled.div`
1211
position: absolute;
@@ -15,23 +14,16 @@ const Absolute = styled.div`
1514
z-index: 20;
1615
`;
1716

18-
const Header = () => (
19-
<Absolute>
20-
<Navigation />
21-
</Absolute>
22-
);
23-
2417
const TemplateWrapper = ({ children }) => (
2518
<ThemeProvider theme={theme}>
2619
<div>
27-
<Header />
20+
<Absolute>
21+
<Navigation />
22+
</Absolute>
2823
<div style={{ maxWidth: '100vw', overflowX: 'hidden' }}>{children()}</div>
24+
<Footer />
2925
</div>
3026
</ThemeProvider>
3127
);
3228

33-
TemplateWrapper.propTypes = {
34-
children: PropTypes.func,
35-
};
36-
3729
export default TemplateWrapper;

packages/homepage/src/pages/changelog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export default ({ data }) => {
163163
);
164164
};
165165

166-
export const query = graphql`
166+
export const pageQuery = graphql`
167167
query Changelogs {
168168
allMarkdownRemark(
169169
filter: { id: { regex: "/changelog/" } }

packages/homepage/src/pages/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import Animation from '../screens/home/Animation';
44
import NPMFeature from '../screens/home/NPMFeature';
55
import CycleFeature from '../screens/home/CycleFeature';
66
import ExtraFeatures from '../screens/home/ExtraFeatures';
7-
import Footer from '../screens/home/Footer';
87
import RecentPublications from '../screens/home/RecentPublications';
98
import Patron from '../screens/home/Patron';
109
import TitleAndMetaTags from '../components/TitleAndMetaTags';
1110

12-
export default class HomePage extends React.PureComponent {
11+
export default class HomePage extends React.Component {
1312
componentDidMount() {
1413
window.addEventListener('scroll', this.scrollCheck, false);
1514
}
@@ -19,7 +18,7 @@ export default class HomePage extends React.PureComponent {
1918
}
2019

2120
scrollCheck = () => {
22-
clearTimeout(this.timertimer);
21+
clearTimeout(this.timer);
2322
if (!document.body.classList.contains('disable-hover')) {
2423
document.body.classList.add('disable-hover');
2524
window.scrolling = true;
@@ -42,13 +41,12 @@ export default class HomePage extends React.PureComponent {
4241
<ExtraFeatures />
4342
<RecentPublications sizes={this.props.data.publicationImages.edges} />
4443
<Patron />
45-
<Footer />
4644
</div>
4745
);
4846
}
4947
}
5048

51-
export const query = graphql`
49+
export const pageQuery = graphql`
5250
query ImageSizesQuery {
5351
publicationImages: allImageSharp(
5452
filter: { id: { regex: "/RecentPublications/" } }

0 commit comments

Comments
 (0)