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
> NuxtJS module to easily interact with the Ghost API
8
8
9
9
[📖 **Release Notes**](./CHANGELOG.md)
10
10
11
11
## Setup
12
12
13
-
1. Add `{{ name }}` dependency to your project
13
+
To start using the module you first need to install it using the package manager of your choice.
14
+
15
+
Installation with yarn
16
+
17
+
```bash
18
+
yarn add nuxtjs-ghost
19
+
```
20
+
21
+
Installation with npm
14
22
15
23
```bash
16
-
yarn add {{ name }} # or npm install {{ name }}
24
+
npm install nuxtjs-ghost
17
25
```
18
26
19
-
2. Add `{{ name }}` to the`modules` section of `nuxt.config.js`
27
+
After that you need to register the plugin, that NuxtJS can pick it up. To do this, add `nuxtjs-ghost` to your`modules` section of `nuxt.config.js`.
20
28
21
29
```js
22
30
{
23
31
modules: [
24
-
// Simple usage
25
-
'{{ name }}',
32
+
'nuxtjs-ghost',
33
+
]
34
+
}
35
+
```
26
36
27
-
// With options
28
-
['{{ name }}', { /* module options */ }]
37
+
## Configuration
38
+
The plugin needs an api key of your site and its endpoint url. Optionally you can pass the version of the Ghost API you want to use. Typically the endpoint for your api is your sites hostname.
39
+
40
+
To set these values you have two options:
41
+
1. Use the default module options
42
+
2. Add your options globally to the `nuxt.config.js`
43
+
44
+
#### Module Options
45
+
When registering the module, don't register it as a string, but an array. The syntax should be:
46
+
```js
47
+
{
48
+
modules: [
49
+
[
50
+
'nuxtjs-ghost',
51
+
{
52
+
url:'YOUR_API_ENDPOINT',
53
+
key:'YOUR_API_KEY'
54
+
}
55
+
]
29
56
]
30
57
}
31
58
```
32
59
60
+
#### Global Configuration
61
+
To set up global configuration, add the following object to your `export` of `nuxt.config.js`:
62
+
```js
63
+
ghost: {
64
+
url:'YOUR_API_ENDPOINT',
65
+
key:'YOUR_API_KEY'
66
+
}
67
+
```
68
+
69
+
## Usage
70
+
The usage is pretty straight forward. This package is just a wrapper for the official [JavaScript Content API](https://ghost.org/docs/api/v3/content/). Please check out their documentation to learn about [filtering](https://ghost.org/docs/api/v3/content/#parameters) or [pagination](https://ghost.org/docs/api/v3/content/#pagination). The `filter` parameter of the following methods is an `object` representation of the available query filters.
71
+
72
+
To access the wrapper it is getting exposed to the application context as `$ghost`. Use it in your pages `created()`, or `mounted()` functions using `this`.
73
+
```js
74
+
exportdefault {
75
+
asynccreated() {
76
+
constposts=awaitthis.$ghost.getPosts()
77
+
}
78
+
}
79
+
```
80
+
Or use it in SSR-mode inside of `asyncData()`
81
+
```js
82
+
exportdefault {
83
+
asyncasyncData({ $ghost }) {
84
+
constposts=await$ghost.getPosts()
85
+
return {
86
+
posts
87
+
}
88
+
}
89
+
}
90
+
```
91
+
92
+
All available methods are documented below:
93
+
94
+
-----
95
+
96
+
#### `async getPosts(filter)` - Gets all posts matching the filter query.
97
+
**Parameters**:
98
+
- (optional) `filter`: Object used for filtering. E.g.: `{limit: 2, include: 'tags,authors'}`
99
+
100
+
**Returns**: An `array` of posts
101
+
102
+
-----
103
+
104
+
#### `async getPost(query, filter)` - Gets the post matching the identifier given in `query`.
105
+
**Parameters**:
106
+
-`query`: Object giving the identifier of the post. Can be `slug` or `id`. E.g.: `{slug: 'my-post'}`
107
+
- (optional) `filter`: Object used for filtering. E.g.: `{formats: ['html', 'plaintext']}}`
108
+
109
+
**Returns**: An `object` representing a post
110
+
111
+
-----
112
+
113
+
#### `async getAuthors(filter)` - Gets all authors matching the filter query.
114
+
**Parameters**:
115
+
- (optional) `filter`: Object used for filtering. E.g.: `{include: 'count.posts'}`
116
+
117
+
**Returns**: An `array` of authors
118
+
119
+
-----
120
+
121
+
#### `async getAuthor(query, filter)` - Gets the author matching the identifier given in `query`.
122
+
**Parameters**:
123
+
-`query`: Object giving the identifier of the author. Can be `slug` or `id`. E.g.: `{id: '1234'}`
124
+
- (optional) `filter`: Object used for filtering. E.g.: `{page: 2}`
125
+
126
+
**Returns**: An `object` representing an author
127
+
128
+
-----
129
+
130
+
#### `async getTags(filter)` - Gets all tags matching the filter query.
131
+
**Parameters**:
132
+
- (optional) `filter`: Object used for filtering. E.g.: `{include: 'count.posts'}`
133
+
134
+
**Returns**: An `array` of tags
135
+
136
+
-----
137
+
138
+
#### `async getTag(query, filter)` - Gets the tag matching the identifier given in `query`.
139
+
**Parameters**:
140
+
-`query`: Object giving the identifier of the tag. Can be `slug` or `id`. E.g.: `{id: '1234'}`
141
+
- (optional) `filter`: Object used for filtering. E.g.: `{include: 'count.posts'}`
142
+
143
+
**Returns**: An `object` representing a tag
144
+
145
+
-----
146
+
147
+
#### `async getPages(filter)` - Gets all pages matching the filter query.
148
+
**Parameters**:
149
+
- (optional) `filter`: Object used for filtering. E.g.: `{limit: 2}`
150
+
151
+
**Returns**: An `array` of pages
152
+
153
+
-----
154
+
155
+
#### `async getTag(query, filter)` - Gets the page matching the identifier given in `query`.
156
+
**Parameters**:
157
+
-`query`: Object giving the identifier of the page. Can be `slug` or `id`. E.g.: `{id: '1234'}`
158
+
- (optional) `filter`: Object used for filtering. E.g.: `{fields: ['title']}`
159
+
160
+
**Returns**: An `object` representing a page
161
+
162
+
-----
163
+
164
+
#### `async getSettings()` - Gets your sites settings.
165
+
166
+
**Returns**: An `object` representing your settings
167
+
168
+
-----
169
+
33
170
## Development
34
171
35
172
1. Clone this repository
@@ -40,20 +177,4 @@ yarn add {{ name }} # or npm install {{ name }}
40
177
41
178
[MIT License](./LICENSE)
42
179
43
-
Copyright (c) {{ author }}
44
-
45
-
<!-- Badges -->
46
-
[npm-version-src]: https://img.shields.io/npm/v/{{ name }}/latest.svg
47
-
[npm-version-href]: https://npmjs.com/package/{{ name }}
48
-
49
-
[npm-downloads-src]: https://img.shields.io/npm/dt/{{ name }}.svg
50
-
[npm-downloads-href]: https://npmjs.com/package/{{ name }}
0 commit comments