Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 89bd092

Browse files
Jinjiangsdras
authored andcommittedMar 19, 2018
Update serverless-blog.md (typo) (#1499)
* Update serverless-blog.md * Update serverless-blog.md * Update serverless-blog.md
1 parent 4f3a851 commit 89bd092

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed
 

‎src/v2/cookbook/serverless-blog.md

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ const butter = Butter('your_api_token');
3535

3636
Using CDN:
3737

38-
```javascript
38+
```html
3939
<script src="https://cdnjs.buttercms.com/buttercms-1.1.0.min.js"></script>
4040
<script>
4141
var butter = Butter('your_api_token');
4242
</script>
4343
```
4444

45-
Import this file into any component you want to use ButterCMS. Then from the console run:
45+
Import this file into any component you want to use ButterCMS. Then from the console run:
4646

4747
```javascript
4848
butter.post.list({page: 1, page_size: 10}).then(function(response) {
@@ -53,7 +53,8 @@ butter.post.list({page: 1, page_size: 10}).then(function(response) {
5353
This API request fetches your blog posts. Your account comes with one example post which you'll see in the response.
5454

5555
## Display posts
56-
To display posts we create a `/blog` route (using vue-router) in our app and fetch blog posts from the Butter API, as well as a `/blog/:slug` route to handle individual posts.
56+
57+
To display posts we create a `/blog` route (using Vue Router) in our app and fetch blog posts from the Butter API, as well as a `/blog/:slug` route to handle individual posts.
5758

5859
See the ButterCMS [API reference](https://buttercms.com/docs/api/?javascript#blog-posts) for additional options such as filtering by category or author. The response also includes some metadata we'll use for pagination.
5960

@@ -86,7 +87,7 @@ export default new Router({
8687

8788
Then create `components/BlogHome.vue` which will be your blog homepage that lists your most recent posts.
8889

89-
```javascript
90+
```html
9091
<script>
9192
import { butter } from '@/buttercms'
9293
export default {
@@ -103,7 +104,6 @@ Then create `components/BlogHome.vue` which will be your blog homepage that list
103104
page: 1,
104105
page_size: 10
105106
}).then((res) => {
106-
// console.log(res.data)
107107
this.posts = res.data.data
108108
})
109109
}
@@ -113,18 +113,17 @@ Then create `components/BlogHome.vue` which will be your blog homepage that list
113113
}
114114
}
115115
</script>
116-
Display the result
117116

118117
<template>
119118
<div id="blog-home">
120119
<h1>{{ page_title }}</h1>
121-
<!-- Create v-for and apply a key for Vue. Example is using a combination of the slug and index -->
120+
     <!-- Create `v-for` and apply a `key` for Vue. Here we are using a combination of the slug and index. -->
122121
<div v-for="(post,index) in posts" :key="post.slug + '_' + index">
123122
<router-link :to="'/blog/' + post.slug">
124123
<article class="media">
125124
<figure>
126-
<!-- Bind results using a ':' -->
127-
<!-- Use a v-if/else if their is a featured_image -->
125+
<!-- Bind results using a `:` -->
126+
<!-- Use a `v-if`/`else` if their is a `featured_image` -->
128127
<img v-if="post.featured_image" :src="post.featured_image" alt="">
129128
<img v-else src="http://via.placeholder.com/250x250" alt="">
130129
</figure>
@@ -141,10 +140,9 @@ Here's what it looks like (note we added CSS from https://bulma.io/ for quick st
141140

142141
![buttercms-bloglist](https://user-images.githubusercontent.com/160873/36868500-1b22e374-1d5e-11e8-82a0-20c8dc312716.png)
143142

144-
145143
Now create `components/BlogPost.vue` which will be your Blog Post page to list a single post.
146144

147-
```javascript
145+
```html
148146
<script>
149147
import { butter } from '@/buttercms'
150148
export default {
@@ -158,7 +156,6 @@ Now create `components/BlogPost.vue` which will be your Blog Post page to list a
158156
getPost() {
159157
butter.post.retrieve(this.$route.params.slug)
160158
.then((res) => {
161-
// console.log(res.data)
162159
this.post = res.data
163160
}).catch((res) => {
164161
console.log(res)
@@ -170,7 +167,7 @@ Now create `components/BlogPost.vue` which will be your Blog Post page to list a
170167
}
171168
}
172169
</script>
173-
Display the results
170+
174171
<template>
175172
<div id="blog-post">
176173
<h1>{{ post.data.title }}</h1>
@@ -191,18 +188,17 @@ Here's a preview:
191188

192189
![buttercms-blogdetail](https://user-images.githubusercontent.com/160873/36868506-218c86b6-1d5e-11e8-8691-0409d91366d6.png)
193190

194-
195191
Now our app is pulling all blog posts and we can navigate to individual posts. However, our next/previous post buttons are not working.
196192

197-
One thing to note when using routes with params is that when the user navigates from /blog/foo to /blog/bar, the same component instance will be reused. Since both routes render the same component, this is more efficient than destroying the old instance and then creating a new one.
193+
One thing to note when using routes with params is that when the user navigates from `/blog/foo` to `/blog/bar`, the same component instance will be reused. Since both routes render the same component, this is more efficient than destroying the old instance and then creating a new one.
198194

199-
<p class="tip">Be aware, that using the component this way will mean that the lifecycle hooks of the component will not be called. Visit the Vue.js docs to learn more about [Dynamic Route Matching](https://router.vuejs.org/en/essentials/dynamic-matching.html)</p>
195+
<p class="tip">Be aware, that using the component this way will mean that the lifecycle hooks of the component will not be called. Visit the Vue Router's docs to learn more about [Dynamic Route Matching](https://router.vuejs.org/en/essentials/dynamic-matching.html)</p>
200196

201197
To fix this we need to watch the `$route` object and call `getPost()` when the route changes.
202198

203-
Updated `script` section in `components/BlogPost.vue`:
199+
Updated `<script>` section in `components/BlogPost.vue`:
204200

205-
```javascript
201+
```html
206202
<script>
207203
import { butter } from '@/buttercms'
208204
export default {
@@ -249,7 +245,7 @@ See the ButterCMS API reference for more information about these objects:
249245

250246
Here's an example of listing all categories and getting posts by category. Call these methods on the `created()` lifecycle hook:
251247

252-
```
248+
```javascript
253249
methods: {
254250
...
255251
getCategories() {
@@ -280,8 +276,6 @@ created() {
280276

281277
An alternative pattern to consider, especially if you prefer writing only in Markdown, is using something like [Nuxtent](https://nuxtent.now.sh/guide/writing#async-components). Nuxtent allows you to use `Vue Component` inside of Markdown files. This approach would be akin to a static site approach (i.e. Jekyll) where you compose your blog posts in Markdown files. Nuxtent adds a nice integration between Vue.js and Markdown allowing you to live in a 100% Vue.js world.
282278

283-
284279
## Wrap up
285280

286-
That's it! You now have a fully functional CMS-powered blog running in your app. We hope this tutorial was helpful and made your development experience with Vue.js even more enjoyable :)
287-
281+
That's it! You now have a fully functional CMS-powered blog running in your app. We hope this tutorial was helpful and made your development experience with Vue.js even more enjoyable :)

0 commit comments

Comments
 (0)
Please sign in to comment.