@mattgrill/storyblok-11ty 2.4.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/readme.md +58 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mattgrill/storyblok-11ty",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "Import Stories and Datasources from Storyblok to 11ty as data objects or static files and it adds custom tags for blocks parsing.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
package/readme.md
CHANGED
|
@@ -128,37 +128,49 @@ module.exports = async () => {
|
|
|
128
128
|
With this method you can get all the Stories or a single one or a subset of them. The stories will be returned in a javascript object already parsed.
|
|
129
129
|
|
|
130
130
|
**Parameters**
|
|
131
|
-
- `[
|
|
132
|
-
- `
|
|
131
|
+
- `[params]` Object (GetStoriesParams), optional. Filter and configuration options:
|
|
132
|
+
- `component` String, optional. Filter stories by component name.
|
|
133
|
+
- `resolve_relations` String, optional. Resolve multiple levels of content by specifying comma-separated values of `component.field_name` according to your data model (e.g., `"article.author,article.categories"`).
|
|
134
|
+
- `resolve_links` String, optional. Resolve internal links. Possible values: `"url"`, `"story"`, `"link"`.
|
|
135
|
+
- `language` String, optional. Language code to fetch content in a specific language.
|
|
136
|
+
- `fallback_lang` String, optional. Fallback language code if the requested language is not available.
|
|
133
137
|
|
|
134
138
|
**Return**
|
|
135
|
-
Promise. The response of the promise is
|
|
139
|
+
Promise. The response of the promise is an array of `TransformedStory` objects:
|
|
136
140
|
|
|
137
141
|
```typescript
|
|
138
|
-
|
|
139
|
-
total: 1,
|
|
140
|
-
stories: Story[]
|
|
141
|
-
}
|
|
142
|
-
```
|
|
143
|
-
Otherwise it will be:
|
|
144
|
-
```typescript
|
|
145
|
-
Array<{
|
|
146
|
-
total: number
|
|
147
|
-
stories: Story[]
|
|
148
|
-
}>
|
|
142
|
+
TransformedStory[]
|
|
149
143
|
```
|
|
150
144
|
|
|
145
|
+
Each `TransformedStory` includes the story data plus 11ty-specific fields like `layout`, `tags`, `data`, and `permalink`.
|
|
146
|
+
|
|
151
147
|
**Examples**
|
|
152
148
|
|
|
153
149
|
**TypeScript:**
|
|
154
150
|
```typescript
|
|
155
|
-
import { StoryblokTo11tyData, type
|
|
151
|
+
import { StoryblokTo11tyData, type TransformedStory } from '@mattgrill/storyblok-11ty';
|
|
156
152
|
|
|
157
153
|
export default async () => {
|
|
158
154
|
const sb = new StoryblokTo11tyData({token: 'your-space-token'});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
155
|
+
|
|
156
|
+
// Get all stories
|
|
157
|
+
const allStories: TransformedStory[] = await sb.getStories();
|
|
158
|
+
|
|
159
|
+
// Get only stories with a specific component
|
|
160
|
+
const articles = await sb.getStories({ component: 'article' });
|
|
161
|
+
|
|
162
|
+
// Resolve relations to get linked content
|
|
163
|
+
const storiesWithRelations = await sb.getStories({
|
|
164
|
+
resolve_relations: 'article.author,article.categories'
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Get stories in a specific language with fallback
|
|
168
|
+
const germanStories = await sb.getStories({
|
|
169
|
+
language: 'de',
|
|
170
|
+
fallback_lang: 'en'
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
return allStories;
|
|
162
174
|
}
|
|
163
175
|
```
|
|
164
176
|
|
|
@@ -168,20 +180,32 @@ const { StoryblokTo11tyData } = require('@mattgrill/storyblok-11ty');
|
|
|
168
180
|
|
|
169
181
|
module.exports = async () => {
|
|
170
182
|
const sb = new StoryblokTo11tyData({token: 'your-space-token'});
|
|
171
|
-
|
|
183
|
+
|
|
184
|
+
// Get all stories
|
|
172
185
|
return await sb.getStories();
|
|
186
|
+
|
|
187
|
+
// Or with options:
|
|
188
|
+
// return await sb.getStories({
|
|
189
|
+
// component: 'article',
|
|
190
|
+
// resolve_relations: 'article.author'
|
|
191
|
+
// });
|
|
173
192
|
}
|
|
174
193
|
```
|
|
175
194
|
|
|
176
195
|
### Method `storeStories`
|
|
177
196
|
|
|
178
|
-
Store all the stories or a subset of them
|
|
197
|
+
Store all the stories or a subset of them as markdown files with JSON front matter. Stories are stored in the folder specified through the `stories_path` parameter (default: `storyblok/`). Each story is saved as `{uuid}.md`.
|
|
179
198
|
|
|
180
199
|
**Parameters**
|
|
181
|
-
- `[
|
|
200
|
+
- `[params]` Object (GetStoriesParams), optional. Same filter options as `getStories`:
|
|
201
|
+
- `component` String, optional. Filter stories by component name.
|
|
202
|
+
- `resolve_relations` String, optional. Resolve relations before storing.
|
|
203
|
+
- `resolve_links` String, optional. Resolve internal links.
|
|
204
|
+
- `language` String, optional. Language code.
|
|
205
|
+
- `fallback_lang` String, optional. Fallback language code.
|
|
182
206
|
|
|
183
207
|
**Return**
|
|
184
|
-
Promise.
|
|
208
|
+
Promise. Returns `true` if stories were stored successfully, `false` otherwise.
|
|
185
209
|
|
|
186
210
|
**Examples**
|
|
187
211
|
|
|
@@ -191,14 +215,17 @@ import { StoryblokTo11tyData } from '@mattgrill/storyblok-11ty';
|
|
|
191
215
|
|
|
192
216
|
const sb = new StoryblokTo11tyData({
|
|
193
217
|
token: 'your-space-token',
|
|
194
|
-
|
|
218
|
+
stories_path: 'content/stories'
|
|
195
219
|
});
|
|
196
220
|
|
|
197
221
|
// Store all stories
|
|
198
222
|
await sb.storeStories();
|
|
199
223
|
|
|
200
|
-
// Store only
|
|
201
|
-
await sb.storeStories(
|
|
224
|
+
// Store only article components with resolved relations
|
|
225
|
+
await sb.storeStories({
|
|
226
|
+
component: 'article',
|
|
227
|
+
resolve_relations: 'article.author,article.categories'
|
|
228
|
+
});
|
|
202
229
|
```
|
|
203
230
|
|
|
204
231
|
**JavaScript:**
|
|
@@ -209,8 +236,11 @@ const sb = new StoryblokTo11tyData({token: 'your-space-token'});
|
|
|
209
236
|
// Store all stories
|
|
210
237
|
await sb.storeStories();
|
|
211
238
|
|
|
212
|
-
// Store only
|
|
213
|
-
await sb.storeStories(
|
|
239
|
+
// Store only articles with resolved author relations
|
|
240
|
+
await sb.storeStories({
|
|
241
|
+
component: 'article',
|
|
242
|
+
resolve_relations: 'article.author'
|
|
243
|
+
});
|
|
214
244
|
```
|
|
215
245
|
|
|
216
246
|
### Method `getDatasources`
|
|
@@ -401,7 +431,7 @@ import type {
|
|
|
401
431
|
Story, // Story object from Storyblok
|
|
402
432
|
TransformedStory, // Transformed story with 11ty specific fields
|
|
403
433
|
DatasourceEntry, // Datasource entry object
|
|
404
|
-
GetStoriesParams, // Parameters for getStories
|
|
434
|
+
GetStoriesParams, // Parameters for getStories/storeStories (component, resolve_relations, etc.)
|
|
405
435
|
ApiResponse // API response structure
|
|
406
436
|
} from '@mattgrill/storyblok-11ty';
|
|
407
437
|
```
|