You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(blog): Update MDX install in themes blog post (#13771)
* fix(blog): Update MDX install in themes blog post
A few things have changed in MDX so this seeks to update
the install instructions.
This also adds a site running section before we customize
the index page. Additionally, it adds some file names and
code highlighting to make things a bit more clear.
* Add intro sentence before site develop command
* Add a few more code block tweaks
* Add missing backtick
* Update docs/blog/2019-02-26-getting-started-with-gatsby-themes/index.md
Co-Authored-By: johno <[email protected]>
* Address feedback to post
* Fix formatting
Copy file name to clipboardExpand all lines: docs/blog/2019-02-26-getting-started-with-gatsby-themes/index.md
+82-59Lines changed: 82 additions & 59 deletions
Original file line number
Diff line number
Diff line change
@@ -21,11 +21,11 @@ Navigate to the directory
21
21
22
22
Create a _package.json_ file
23
23
24
-
`yarn init`
24
+
`yarn init -y`
25
25
26
26
Tidy up your _package.json_ file and create workspaces which includes the project name, site, and your packages. Both of these directories will include their own _package.json_ files.
27
27
28
-
```json
28
+
```json:title=package.json
29
29
{
30
30
"name": "gatsby-site",
31
31
"private": true,
@@ -36,58 +36,41 @@ Tidy up your _package.json_ file and create workspaces which includes the projec
36
36
37
37
Next, you want to create your _site_ directory and your _packages_ directory within your _gatsby-theme_ project directory. Make sure the names that you choose for your directories are the same as what you put in your workspaces. You will also want to go into your packages directory and make another directory with the name of your theme. For the purpose of this tutorial, we will call it _theme_. Then you will want to `yarn init` the _theme_ directory and the _site_ directory.
38
38
39
-
```
39
+
```sh
40
40
mkdir site
41
41
mkdir packages
42
42
cd packages
43
43
mkdir theme
44
44
cd theme
45
-
yarn init
45
+
yarn init -y
46
+
touch index.js
46
47
cd ../../site/
47
-
yarn init
48
+
yarn init -y
48
49
```
49
50
50
-
After using `yarn init` you will be asked a few questions. The main thing you will want to pay attention to is the entry point (index.js). For the _theme_ directory, you can leave the entry point as _index.js_ (just make sure you have an _index.js_ file) and for the _site_ directory, you can make entry point _gatsby-config.js_. Next, you will want to go into your _site_ directory and do `yarn workspace site add gatsby`.
51
+
The `-y` in `yarn init`automatically adds defaults to your `package.json`. If you opt to run `yarn init` without `-y` you will be asked a few questions. The main thing you will want to pay attention to is the entry point (index.js). For the _theme_ directory, you can leave the entry point as _index.js_ (just make sure you have an _index.js_ file).
51
52
52
-
Hooray! Gatsby should now be added to your site directory if you look in your _package.json_ file. Adjustments you make to your file is adding "scripts" and adding the name of your Gatsby theme, in this case, _theme_, to your dependencies.
53
-
54
-
```json
53
+
```json:title=packages/theme/package.json
55
54
{
56
55
"name": "theme",
57
-
"version": "0.0.1",
56
+
"version": "1.0.0",
58
57
"description": "Practicing making a Gatsby theme",
59
58
"main": "index.js",
60
-
"license": "MIT",
61
-
"devDependencies": {
62
-
"gatsby": "^2.0.118",
63
-
"react": "^16.8.1",
64
-
"react-dom": "^16.8.1"
65
-
},
66
-
"peerDependencies": {
67
-
"gatsby": "^2.0.118",
68
-
"react": "^16.8.1",
69
-
"react-dom": "^16.8.1"
70
-
},
71
-
"dependencies": {
72
-
"@mdx-js/mdx": "^0.17.0",
73
-
"@mdx-js/tag": "^0.17.0",
74
-
"gatsby-mdx": "^0.3.6",
75
-
"gatsby-plugin-page-creator": "^2.0.6"
76
-
}
59
+
"license": "MIT"
77
60
}
78
61
```
79
62
80
63
You will want to add Gatsby, React, and ReactDOM to as dev dependencies for _site_.
81
64
82
-
`yarn workspace site add gatsby react react-dom -D`
65
+
`yarn workspace site add gatsby react react-dom`
83
66
84
67
Then you will navigate out of the _site_ directory and add Gatsby, React, and ReactDOM as dev dependencies for _theme_.
Next, you will want to add gatsby-plugin-page-creator
118
101
@@ -126,37 +109,70 @@ Read more about the page-creator plugin [here.](/packages/gatsby-plugin-page-cre
126
109
127
110
Next, you will want to create your _gatsby-config.js_ file under your _theme_ directory. Make sure to include 'gatsby-mdx' and 'gatsby-plugin-page-creator.'
Now, you can make sure _site_ is linked to _theme_.
131
+
Lastly, you're going to want to add a _gatsby-config.js_ file to your _site_ directory.
132
+
133
+
```javascript:title=site/gatsby-config.js
134
+
module.exports= {
135
+
__experimentalThemes: [`theme`],
136
+
}
137
+
```
138
+
139
+
### Setting up Site `package.json`
151
140
141
+
You will need to add `gatsby` CLI scripts and specify your newly created `theme` as a dependency.
142
+
143
+
```json:title=site/package.json
144
+
{
145
+
"name": "site",
146
+
"version": "1.0.0",
147
+
"main": "index.js",
148
+
"license": "MIT",
149
+
"scripts": {
150
+
// highlight-start
151
+
"develop": "gatsby develop",
152
+
"build": "gatsby build"
153
+
// highlight-end
154
+
},
155
+
"dependencies": {
156
+
"gatsby": "^2.3.34",
157
+
"react": "^16.8.6",
158
+
"react-dom": "^16.8.6",
159
+
// highlight-start
160
+
"theme": "*"
161
+
// highlight-end
162
+
}
163
+
}
152
164
```
165
+
166
+
Now, you can make sure _site_ is linked to _theme_.
167
+
168
+
```sh
153
169
yarn
154
170
yarn workspaces info
155
171
```
156
172
157
173
Your workspace info should look similar to this:
158
174
159
-
```shell
175
+
```json
160
176
{
161
177
"site": {
162
178
"location": "site",
@@ -171,20 +187,29 @@ Your workspace info should look similar to this:
171
187
}
172
188
```
173
189
174
-
Lastly, you're going to want to add a _gatsby-config.js_ file to your _site_ directory.
190
+
### Run the Site
175
191
176
-
```javascript:title=gatsby-config.js
177
-
module.exports= {
178
-
__experimentalThemes: ["theme"],
179
-
}
192
+
Now that we've set up the site's _package.json_ we can run the workspace:
193
+
194
+
```sh
195
+
yarn workspace site develop
180
196
```
181
197
182
-
While you're still in the _site_ directory, you are going to create an _index.mdx_ file in the pages folder.
198
+
### Customizing the Index Page
199
+
200
+
You can override the index page from your theme by creating one in site. To do so, change directory into
201
+
the _site_ directory, and create an _index.mdx_ file in the pages folder.
183
202
184
203
`site/src/pages/index.mdx`
185
204
186
205
Your website content goes in _index.mdx_.
187
206
207
+
Now, rerun the development server and see your new content:
208
+
209
+
```sh
210
+
yarn workspace site develop
211
+
```
212
+
188
213
## Styling Layout and Components
189
214
190
215
Next, you will navigate to the _theme_ directory. You will then create a _components_ folder under _src_, and in components you create a _layout.js_ file.
@@ -193,13 +218,13 @@ Next, you will navigate to the _theme_ directory. You will then create a _compon
193
218
194
219
Inside of your _layout.js_ file, you can add your styling.
To make sure your _layout.js_ file is connected to your theme you will navigate to your _gatsby-config.js_ file in your _theme_ directory. You will add defaultLayouts under options and make sure that the _layout.js_ is required.
0 commit comments