Skip to content

Commit fb4e9d4

Browse files
authored
Add part two of the tutorial (gatsbyjs#1667)
* WIP * WIP * Add gatsby-plugin-typography * Fix bug in babel-config.js that didn't pass normalizedConfig to plugins * Add blockquote styling * Add remainder of typography + component styling parts of tutorial * Add part two to sidebar * Remove the WIP writing for the layout section
1 parent 8d07625 commit fb4e9d4

21 files changed

+725
-7
lines changed
Loading
305 KB
Loading
126 KB
Loading
122 KB
Loading
336 KB
Loading
329 KB
Loading

docs/tutorial/part-two/index.md

+605
Large diffs are not rendered by default.
Loading
296 KB
Loading
213 KB
Loading

packages/gatsby-plugin-glamor/src/gatsby-node.js

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ exports.modifyWebpackConfig = ({ config }) =>
99
])
1010

1111
// Add Glamor support
12-
// // Add Glamor support
1312
exports.modifyBabelrc = ({ babelrc }) => {
1413
return {
1514
...babelrc,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*.js
2+
!index.js
3+
yarn.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules
28+
*.un~
29+
yarn.lock
30+
src
31+
flow-typed
32+
coverage
33+
decls
34+
examples
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// noop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "gatsby-plugin-typography",
3+
"version": "1.0.0",
4+
"description": "Gatsby plugin to setup server rendering of Typography.js' CSS",
5+
"main": "index.js",
6+
"dependencies": {
7+
"react-typography": "^0.15.10",
8+
"typography": "^0.15.10"
9+
},
10+
"devDependencies": {},
11+
"scripts": {
12+
"build": "babel src --out-dir . --ignore __tests__",
13+
"watch": "babel -w src --out-dir . --ignore __tests__"
14+
},
15+
"keywords": [
16+
"gatsby",
17+
"gatsby-plugin",
18+
"typography",
19+
"typography.js"
20+
],
21+
"author": "Kyle Mathews <[email protected]>",
22+
"license": "MIT"
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import typography from "gatsby-plugin-typography/.cache/typography.js"
2+
3+
// Hot reload typography in development.
4+
if (process.env.NODE_ENV !== `production`) {
5+
console.log("injecting styles", typography)
6+
typography.injectStyles()
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const fs = require(`fs`)
2+
const path = require(`path`)
3+
4+
// Write out a typography module to .cache.
5+
6+
// TODO add a new API hook e.g onPreBootstrap
7+
exports.sourceNodes = ({ store }, pluginOptions) => {
8+
const program = store.getState().program
9+
10+
let module
11+
if (pluginOptions.pathToConfigModule) {
12+
module = `module.exports = require("${path.join(
13+
program.directory,
14+
pluginOptions.pathToConfigModule
15+
)}")`
16+
} else {
17+
module = `const Typography = require("typography")
18+
const typography = new Typography()
19+
module.exports typography`
20+
}
21+
22+
fs.writeFileSync(`${__dirname}/.cache/typography.js`, module)
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from "react"
2+
import { TypographyStyle, GoogleFont } from "react-typography"
3+
import typography from "./.cache/typography"
4+
5+
exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => {
6+
setHeadComponents([
7+
<TypographyStyle key={`TypographyStyle`} typography={typography} />,
8+
<GoogleFont key={`GoogleFont`} typography={typography} />,
9+
])
10+
}

packages/gatsby/src/utils/babel-config.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,16 @@ module.exports = async function babelConfig(program, stage) {
171171
babelrc.plugins.unshift(`react-hot-loader/babel`)
172172
}
173173

174-
// Always add this plugin so our generated routes
175-
// will work regardless of how users export
176-
// their components. Yeah for multiple module standards!
177-
babelrc.plugins.unshift(`add-module-exports`)
178-
179174
babelrc.plugins.unshift(require.resolve(`./babel-plugin-extract-graphql`))
180175

181176
if (!babelrc.hasOwnProperty(`cacheDirectory`)) {
182177
babelrc.cacheDirectory = true
183178
}
184179

185180
const normalizedConfig = normalizeConfig(babelrc, directory)
186-
let modifiedConfig = await apiRunnerNode(`modifyBabelrc`, { babelrc })
181+
let modifiedConfig = await apiRunnerNode(`modifyBabelrc`, {
182+
babelrc: normalizedConfig,
183+
})
187184
if (modifiedConfig.length > 0) {
188185
modifiedConfig = _.merge({}, ...modifiedConfig)
189186
// Otherwise this means no plugin changed the babel config.

www/src/pages/docs/tutorial-links.yml

+11
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@
99
">> Linking between pages": /tutorial/part-one/#linking-between-pages
1010
">> Interactive page": /tutorial/part-one/#interactive-page
1111
">> Deploying Gatsby.js websites on the web": /tutorial/part-one/#deploying-gatsbyjs-websites-on-the-web
12+
- title: Part Two
13+
links:
14+
Part two: /tutorial/part-two/
15+
">> Building with components": /tutorial/part-two/#building-with-components
16+
">> Creating Global Styles": /tutorial/part-two/#creating-global-styles
17+
">> Typography.js": /tutorial/part-two/#typographyjs
18+
">> Gatsby Plugins": /tutorial/part-two/#gatsby-plugins
19+
">> Component CSS": /tutorial/part-two/#component-css
20+
">> CSS Modules": /tutorial/part-two/#css-modules
21+
">> Glamor": /tutorial/part-two/#glamor
22+
">> Styled Components": /tutorial/part-two/#styled-components
1223

www/src/utils/typography.js

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ const options = {
4242
h5: {
4343
...scale(0),
4444
},
45+
blockquote: {
46+
paddingLeft: rhythm(3 / 8),
47+
marginLeft: rhythm(3 / 8),
48+
borderLeft: `${rhythm(2 / 8)} solid ${presets.brandDark}`,
49+
},
4550
"tt,code": {
4651
// background: `hsla(23, 60%, 97%, 1)`,
4752
background: colors.a[0],

0 commit comments

Comments
 (0)