Skip to content

Commit

Permalink
docs: migrate website to Gatsby v2 (#1623)
Browse files Browse the repository at this point in the history
* website: initial conversion to gatsby v2

* fix unexpected history use warning

* use commonjs only to fix gatsby error

* fix gatsby import error with sidecar

* remove unused postcss-colour-functions

* remove unused prop

* lowercase layout filename import to match actual file

* chore(lint): format code
  • Loading branch information
zebapy authored and tech4him1 committed Aug 23, 2018
1 parent c209c2a commit aaaedd0
Show file tree
Hide file tree
Showing 17 changed files with 4,095 additions and 4,673 deletions.
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

5 changes: 0 additions & 5 deletions .eslintrc

This file was deleted.

3 changes: 1 addition & 2 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SmoothScroll from 'smooth-scroll';

// Make scroll behavior of internal links smooth
exports.onClientEntry = () => {
const SmoothScroll = require('smooth-scroll');
new SmoothScroll('a[href*="#"]', {
offset() {
return document.querySelector('#header').offsetHeight;
Expand Down
26 changes: 1 addition & 25 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
const pkg = require('./package.json');

const neatgrid = require('postcss-neat');
const nestedcss = require('postcss-nested');
const colorfunctions = require('postcss-colour-functions');
const hdBackgrounds = require('postcss-at2x');
const cssextend = require('postcss-simple-extend');
const cssvars = require('postcss-simple-vars-async');

const styleVariables = require('./src/theme');

const postCssPlugins = [
neatgrid(),
nestedcss(),
colorfunctions(),
hdBackgrounds(),
cssextend(),
cssvars({ variables: styleVariables }),
];

module.exports = {
siteMetadata: {
title: 'Netlify CMS | Open-Source Content Management System',
Expand Down Expand Up @@ -71,14 +53,8 @@ module.exports = {
]
},
},
{
resolve: 'gatsby-plugin-postcss-sass',
options: {
postCssPlugins,
},
},
'gatsby-plugin-postcss',
'gatsby-plugin-react-helmet',
'gatsby-plugin-react-next',
'gatsby-plugin-catch-links',
{
resolve: `gatsby-plugin-manifest`,
Expand Down
32 changes: 17 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,34 @@
"license": "MIT",
"dependencies": {
"classnames": "^2.2.5",
"eslint": "^3.1.1",
"eslint-plugin-import": "^1.11.1",
"gatsby": "^1.9.270",
"gatsby-plugin-catch-links": "^1.0.22",
"gatsby-plugin-manifest": "^1.0.21",
"gatsby-plugin-postcss-sass": "^1.0.20",
"gatsby-plugin-react-helmet": "^2.0.11",
"gatsby-plugin-react-next": "^1.0.11",
"gatsby-remark-autolink-headers": "^1.4.18",
"gatsby-remark-prismjs": "^2.0.2",
"gatsby-source-filesystem": "^1.5.35",
"gatsby-transformer-json": "^1.0.17",
"gatsby-transformer-remark": "^1.7.42",
"gatsby-transformer-yaml": "^1.5.16",
"gatsby": "next",
"gatsby-plugin-catch-links": "next",
"gatsby-plugin-manifest": "next",
"gatsby-plugin-postcss": "^1.0.0",
"gatsby-plugin-react-helmet": "next",
"gatsby-remark-autolink-headers": "next",
"gatsby-remark-prismjs": "next",
"gatsby-source-filesystem": "next",
"gatsby-transformer-json": "next",
"gatsby-transformer-remark": "next",
"gatsby-transformer-yaml": "next",
"postcss-at2x": "^2.0.0",
"postcss-colour-functions": "^1.5.1",
"postcss-cssnext": "^2.7.0",
"postcss-neat": "^2.5.2",
"postcss-nested": "^1.0.0",
"postcss-simple-extend": "^1.0.0",
"postcss-simple-vars-async": "^1.2.1",
"prismjs": "^1.14.0",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-helmet": "^5.2.0",
"react-markdown": "^3.3.2",
"react-sidecar": "^0.1.1",
"smooth-scroll": "^14.2.0"
},
"devDependencies": {
"eslint": "^3.1.1",
"eslint-plugin-import": "^1.11.1"
},
"private": true
}
19 changes: 19 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const neatgrid = require('postcss-neat');
const nestedcss = require('postcss-nested');
// const colorfunctions = require('postcss-colour-functions');
const hdBackgrounds = require('postcss-at2x');
const cssextend = require('postcss-simple-extend');
const cssvars = require('postcss-simple-vars-async');

const styleVariables = require('./src/theme');

module.exports = () => ({
plugins: [
neatgrid(),
nestedcss(),
// colorfunctions(),
hdBackgrounds(),
cssextend(),
cssvars({ variables: styleVariables }),
],
});
100 changes: 53 additions & 47 deletions src/components/header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import Link from 'gatsby-link';
import classnames from 'classnames';
import { Location } from '@reach/router';

import DocSearch from './docsearch';

Expand Down Expand Up @@ -33,56 +34,61 @@ class Header extends Component {
};

render() {
const { location } = this.props;
const { scrolled } = this.state;

const isDocs = location.pathname.indexOf('docs') !== -1;
const isBlog = location.pathname.indexOf('blog') !== -1;

return (
<header
id="header"
className={classnames({
docs: isDocs,
blog: isBlog,
scrolled,
})}
>
<div className="contained">
<div className="logo-container">
<Link to="/" className="logo">
<img src={logo} />
</Link>
{isDocs && <DocSearch />}
</div>
<div className="nav-container">
<Link className="nav-link docs-link" to="/docs/intro">
Docs
</Link>
<Link className="nav-link contributing-link" to="/docs/contributor-guide">
Contributing
</Link>
<Link className="nav-link" to="/community">
Community
</Link>
<Link className="nav-link" to="/blog">
Blog
</Link>
<span className="gh-button">
<a
id="ghstars"
className="github-button"
href="https://github.com/netlify/netlify-cms"
data-icon="octicon-star"
data-show-count="true"
aria-label="Star netlify/netlify-cms on GitHub"
>
Star
</a>
</span>
</div>
</div>
</header>
<Location>
{({ location }) => {
const isDocs = location.pathname.indexOf('docs') !== -1;
const isBlog = location.pathname.indexOf('blog') !== -1;

return (
<header
id="header"
className={classnames({
docs: isDocs,
blog: isBlog,
scrolled,
})}
>
<div className="contained">
<div className="logo-container">
<Link to="/" className="logo">
<img src={logo} />
</Link>
{isDocs && <DocSearch />}
</div>
<div className="nav-container">
<Link className="nav-link docs-link" to="/docs/intro">
Docs
</Link>
<Link className="nav-link contributing-link" to="/docs/contributor-guide">
Contributing
</Link>
<Link className="nav-link" to="/community">
Community
</Link>
<Link className="nav-link" to="/blog">
Blog
</Link>
<span className="gh-button">
<a
id="ghstars"
className="github-button"
href="https://github.com/netlify/netlify-cms"
data-icon="octicon-star"
data-show-count="true"
aria-label="Star netlify/netlify-cms on GitHub"
>
Star
</a>
</span>
</div>
</div>
</header>
);
}}
</Location>
);
}
}
Expand Down
77 changes: 77 additions & 0 deletions src/components/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, { Fragment } from 'react';
import Helmet from 'react-helmet';
import classnames from 'classnames';
import { graphql, StaticQuery } from 'gatsby';

import Header from './header';
import Footer from './footer';

import '../css/imports/base.css';
import '../css/imports/utilities.css';
import '../css/imports/gitter.css';

const Layout = ({ children }) => {
return (
<StaticQuery
query={graphql`
query layoutQuery {
site {
siteMetadata {
title
description
}
}
footer: file(relativePath: { regex: "/global/" }) {
childDataYaml {
footer {
buttons {
url
name
}
}
}
}
notifs: file(relativePath: { regex: "/notifications/" }) {
childDataYaml {
notifications {
published
loud
message
url
}
}
}
}
`}
>
{data => {
const { title, description } = data.site.siteMetadata;
const notifs = data.notifs.childDataYaml.notifications.filter(notif => notif.published);

return (
<Fragment>
<Helmet defaultTitle={title} titleTemplate={`%s | ${title}`}>
<meta name="description" content={description} />
</Helmet>
{notifs.map((node, i) => (
<a
key={i}
href={node.url}
className={classnames('notification', {
'notification-loud': node.loud,
})}
>
{node.message}
</a>
))}
<Header notifications={notifs} />
{children}
<Footer buttons={data.footer.childDataYaml.footer.buttons} />
</Fragment>
);
}}
</StaticQuery>
);
};

export default Layout;
2 changes: 1 addition & 1 deletion src/components/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Widgets extends Component {
currentWidget: target,
},
() => {
history.pushState(null, null, `#${target}`);
window.history.pushState(null, null, `#${target}`);
},
);
};
Expand Down
25 changes: 7 additions & 18 deletions src/html.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
import React from 'react';
import Gitter from 'react-sidecar';
// gatsby throws some error when importing just react-sidecar.
// Maybe because jsx file ext?
import Gitter from 'react-sidecar/dist-modules/index.js';

let stylesStr;
if (process.env.NODE_ENV === `production`) {
try {
stylesStr = require('!raw-loader!../public/styles.css');
} catch (e) {
console.log(e);
}
}

module.exports = class HTML extends React.Component {
class HTML extends React.Component {
render() {
let css;
if (process.env.NODE_ENV === 'production') {
css = <style id="gatsby-inlined-css" dangerouslySetInnerHTML={{ __html: stylesStr }} />;
}

return (
<html {...this.props.htmlAttributes}>
<head>
Expand All @@ -30,7 +18,6 @@ module.exports = class HTML extends React.Component {
<meta name="apple-mobile-web-app-title" content="NetlifyCMS" />
<meta name="application-name" content="NetlifyCMS" />
{this.props.headComponents}
{css}
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/cdn/docsearch.min.css"
Expand All @@ -47,4 +34,6 @@ module.exports = class HTML extends React.Component {
</html>
);
}
};
}

export default HTML;
Loading

0 comments on commit aaaedd0

Please sign in to comment.