nuxt-content-assets 0.7.0 → 0.9.0-alpha
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/README.md +45 -141
- package/dist/module.d.ts +0 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +275 -163
- package/dist/runtime/options.d.ts +4 -4
- package/dist/runtime/options.mjs +4 -8
- package/dist/runtime/plugin.mjs +15 -3
- package/dist/runtime/services/assets.d.ts +1 -1
- package/dist/runtime/services/assets.mjs +2 -3
- package/dist/runtime/services/sockets/client.d.ts +2 -0
- package/dist/runtime/services/sockets/client.mjs +9 -0
- package/dist/runtime/services/sockets/composable.d.ts +4 -0
- package/dist/runtime/services/sockets/composable.mjs +77 -0
- package/dist/runtime/services/sockets/server.d.ts +23 -0
- package/dist/runtime/services/sockets/server.mjs +78 -0
- package/dist/runtime/services/sources.d.ts +22 -10
- package/dist/runtime/services/sources.mjs +85 -32
- package/dist/runtime/utils/assert.d.ts +7 -3
- package/dist/runtime/utils/assert.mjs +7 -4
- package/dist/runtime/utils/fs.d.ts +3 -0
- package/dist/runtime/utils/fs.mjs +12 -0
- package/dist/runtime/utils/string.d.ts +3 -0
- package/dist/runtime/utils/string.mjs +9 -0
- package/dist/runtime/watcher.d.ts +2 -0
- package/dist/runtime/watcher.mjs +18 -0
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
## Overview
|
|
15
15
|
|
|
16
|
-
Nuxt Content Assets enables locally-located assets in
|
|
16
|
+
Nuxt Content Assets enables locally-located assets in [Nuxt Content](https://content.nuxtjs.org/):
|
|
17
17
|
|
|
18
18
|
```
|
|
19
19
|
+- content
|
|
@@ -43,7 +43,7 @@ Almost as much as being in the sea!
|
|
|
43
43
|
<video src="media/seaside.mp4"></video>
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
The module supports a variety of [common tags](#how-it-works) and has additional goodies such as [image sizing](#image-sizing) and [live-reload](#live-reload).
|
|
47
47
|
|
|
48
48
|
## Demo
|
|
49
49
|
|
|
@@ -82,6 +82,8 @@ export default defineNuxtConfig({
|
|
|
82
82
|
|
|
83
83
|
Run the dev server or build and local assets should now be served alongside markdown content.
|
|
84
84
|
|
|
85
|
+
See the [How it works](#how-it-works) section for more information.
|
|
86
|
+
|
|
85
87
|
## Usage
|
|
86
88
|
|
|
87
89
|
### Overview
|
|
@@ -93,27 +95,7 @@ Use relative paths anywhere within your documents:
|
|
|
93
95
|
<video src="media/video.mp4" />
|
|
94
96
|
```
|
|
95
97
|
|
|
96
|
-
Relative paths
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
image.jpg
|
|
100
|
-
assets/featured.png
|
|
101
|
-
../assets/cv.pdf
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Note that only specific tags and attributes are targeted:
|
|
105
|
-
|
|
106
|
-
```html
|
|
107
|
-
<img src="...">
|
|
108
|
-
<video src="...">
|
|
109
|
-
<audio src="...">
|
|
110
|
-
<source src="...">
|
|
111
|
-
<embed src="...">
|
|
112
|
-
<iframe src="...">
|
|
113
|
-
<a href="...">
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
However, you can use relative paths in frontmatter:
|
|
98
|
+
Relative paths can be defined in frontmatter, as long as they are the only value:
|
|
117
99
|
|
|
118
100
|
```mdx
|
|
119
101
|
---
|
|
@@ -125,30 +107,22 @@ images:
|
|
|
125
107
|
---
|
|
126
108
|
```
|
|
127
109
|
|
|
128
|
-
|
|
110
|
+
These values can then be passed to components:
|
|
129
111
|
|
|
130
112
|
```markdown
|
|
131
113
|
::gallery{:data="images"}
|
|
132
114
|
::
|
|
133
115
|
```
|
|
134
116
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
See the [Demo](demo/content/recipes/index.md) for an example.
|
|
117
|
+
See the [Demo](demo/content/recipes/index.md) for a component example.
|
|
138
118
|
|
|
139
|
-
###
|
|
119
|
+
### Live reload
|
|
140
120
|
|
|
141
|
-
|
|
121
|
+
From version `0.9.0-alpha` assets are watched and live-reloaded!
|
|
142
122
|
|
|
143
|
-
|
|
144
|
-
|--------|-------------------------------------------------------------------------|
|
|
145
|
-
| Images | `png`, `jpg`, `jpeg`, `gif`, `svg`, `webp` |
|
|
146
|
-
| Media | `mp3`, `m4a`, `wav`, `mp4`, `mov`, `webm`, `ogg`, `avi`, `flv`, `avchd` |
|
|
147
|
-
| Files | `pdf`, `doc`, `docx`, `xls`, `xlsx`, `ppt`, `pptx`, `odp`, `key` |
|
|
123
|
+
Any additions, moves or deletes, or modifications to image content will be updated in the browser automatically.
|
|
148
124
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
### Images
|
|
125
|
+
### Image sizing
|
|
152
126
|
|
|
153
127
|
The module can prevent content jumps by optionally writing image size information to generated `<img>` tags:
|
|
154
128
|
|
|
@@ -156,7 +130,7 @@ The module can prevent content jumps by optionally writing image size informatio
|
|
|
156
130
|
<img src="/image.jpg?width=640&height=480" width="640" height="480" style="aspect-ratio:640/480">
|
|
157
131
|
```
|
|
158
132
|
|
|
159
|
-
If you use [ProseImg](https://content.nuxtjs.org/api/components/prose) components, you can
|
|
133
|
+
If you use [ProseImg](https://content.nuxtjs.org/api/components/prose) components, you can hook into these values via the `$attrs` property:
|
|
160
134
|
|
|
161
135
|
```vue
|
|
162
136
|
<template>
|
|
@@ -172,36 +146,40 @@ export default {
|
|
|
172
146
|
</script>
|
|
173
147
|
```
|
|
174
148
|
|
|
175
|
-
|
|
149
|
+
For more information see the [configuration](#image-size) section and [Demo](demo/components/temp/ProseImg.vue) for an example.
|
|
150
|
+
|
|
151
|
+
## How it works
|
|
176
152
|
|
|
177
|
-
|
|
153
|
+
Nuxt Content Assets works by serving a _copy_ of your assets using [Nitro](https://nitro.unjs.io/guide/assets#custom-server-assets).
|
|
178
154
|
|
|
179
|
-
|
|
155
|
+
When Nuxt builds, the following happens:
|
|
180
156
|
|
|
181
|
-
-
|
|
182
|
-
-
|
|
183
|
-
-
|
|
184
|
-
-
|
|
157
|
+
- all content sources are scanned for valid assets
|
|
158
|
+
- found assets are copied to a temporary build folder
|
|
159
|
+
- relative paths in markdown are rewritten to point at this folder
|
|
160
|
+
- metadata such as image size is written to a lookup file
|
|
161
|
+
- finally, Nitro serves the folder for public access
|
|
185
162
|
|
|
186
|
-
|
|
163
|
+
Note only specific tags and attributes are targeted in the parsing phase for rewriting:
|
|
164
|
+
|
|
165
|
+
```html
|
|
166
|
+
<a href="...">
|
|
167
|
+
<img src="...">
|
|
168
|
+
<video src="...">
|
|
169
|
+
<audio src="...">
|
|
170
|
+
<source src="...">
|
|
171
|
+
<embed src="...">
|
|
172
|
+
<iframe src="...">
|
|
173
|
+
```
|
|
187
174
|
|
|
188
175
|
## Configuration
|
|
189
176
|
|
|
190
|
-
|
|
177
|
+
You can configure the module like so:
|
|
191
178
|
|
|
192
179
|
```ts
|
|
193
180
|
// nuxt.config.ts
|
|
194
181
|
export default defineNuxtConfig({
|
|
195
|
-
'content-assets': {
|
|
196
|
-
// where to generate and serve the assets from
|
|
197
|
-
output: 'assets/content/[path]/[file]',
|
|
198
|
-
|
|
199
|
-
// include additional extensions
|
|
200
|
-
additionalExtensions: 'html',
|
|
201
|
-
|
|
202
|
-
// completely replace supported extensions
|
|
203
|
-
extensions: 'png jpg',
|
|
204
|
-
|
|
182
|
+
'content-assets': {
|
|
205
183
|
// use aspect-ratio rather than attributes
|
|
206
184
|
imageSize: 'style',
|
|
207
185
|
|
|
@@ -211,91 +189,27 @@ export default defineNuxtConfig({
|
|
|
211
189
|
})
|
|
212
190
|
```
|
|
213
191
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
The output path can be customised using a template string:
|
|
217
|
-
|
|
218
|
-
```
|
|
219
|
-
assets/[name]-[hash].[ext]
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
The first part of the path is where you want content assets to be served from:
|
|
223
|
-
|
|
224
|
-
```
|
|
225
|
-
assets/
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
The optional second part of the path indicates the relative location of each asset.
|
|
229
|
-
|
|
230
|
-
The table below shows replacements for the asset `content/posts/2023-01-01/featured.jpg`:
|
|
231
|
-
|
|
232
|
-
| Token | Description | Example |
|
|
233
|
-
|-------------|----------------------------------------------------------------------------------------------------|----------------------------|
|
|
234
|
-
| `[key]` | The config key of the source (see [sources](https://content.nuxtjs.org/api/configuration#sources)) | `content` |
|
|
235
|
-
| `[path]` | The relative path of the source | `content/posts/2023-01-01` |
|
|
236
|
-
| `[folder]` | The relative path of the file's folder | `posts/2023-01-01` |
|
|
237
|
-
| `[file]` | The full filename of the file | `featured.jpg` |
|
|
238
|
-
| `[name]` | The name of the file without the extension | `featured` |
|
|
239
|
-
| `[hash]` | A hash of the absolute source path | `9M00N4l9A0` |
|
|
240
|
-
| `[extname]` | The full extension with the dot | `.jpg` |
|
|
241
|
-
| `[ext]` | The extension without the dot | `jpg` |
|
|
242
|
-
|
|
243
|
-
For example:
|
|
244
|
-
|
|
245
|
-
| Template | Output |
|
|
246
|
-
|------------------------------|------------------------------------------------|
|
|
247
|
-
| `assets/[path]/[file]` | `assets/content/posts/2023-01-01/featured.jpg` |
|
|
248
|
-
| `assets/[folder]/[file]` | `assets/posts/2023-01-01/featured.jpg` |
|
|
249
|
-
| `assets/[name]-[hash].[ext]` | `assets/featured-9M00N4l9A0.jpg` |
|
|
250
|
-
| `assets/[hash].[ext]` | `assets/9M00N4l9A0.jpg` |
|
|
251
|
-
|
|
252
|
-
Note that the module defaults to:
|
|
253
|
-
|
|
254
|
-
```
|
|
255
|
-
/assets/[path]/[file]
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
### Extensions
|
|
259
|
-
|
|
260
|
-
You can add (or replace) supported extensions if you need to:
|
|
261
|
-
|
|
262
|
-
To add extensions, use `additionalExtensions`:
|
|
263
|
-
|
|
264
|
-
```ts
|
|
265
|
-
{
|
|
266
|
-
additionalExtensions: 'html' // add support for html
|
|
267
|
-
}
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
To replace extensions, use `extensions`:
|
|
271
|
-
|
|
272
|
-
```ts
|
|
273
|
-
{
|
|
274
|
-
extensions: 'png jpg' // serve png and jpg files only
|
|
275
|
-
}
|
|
276
|
-
```
|
|
192
|
+
Note that from version `0.9.0-alpha` the `output` location is no longer configurable; images are copied relative to their original locations.
|
|
277
193
|
|
|
278
194
|
### Image size
|
|
279
195
|
|
|
280
|
-
You can add image size hints to the generated images
|
|
281
|
-
|
|
282
|
-
To add `style` aspect-ratio:
|
|
196
|
+
You can add one or more image size hints to the generated images:
|
|
283
197
|
|
|
284
198
|
```ts
|
|
285
199
|
{
|
|
286
|
-
imageSize: '
|
|
200
|
+
imageSize: 'attrs url'
|
|
287
201
|
}
|
|
288
202
|
```
|
|
289
203
|
|
|
290
|
-
|
|
204
|
+
Pick from the following switches:
|
|
291
205
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
206
|
+
| Switch | What it does |
|
|
207
|
+
|---------|------------------------------------------------------------------------------|
|
|
208
|
+
| `style` | Adds `style="aspect-ratio:..."` to any `<img>` tag |
|
|
209
|
+
| `attrs` | Adds `width` and `height` attributes to any `<img>` tag |
|
|
210
|
+
| `url` | Adds the `?width=...&height=...` query string to image frontmatter variables |
|
|
297
211
|
|
|
298
|
-
|
|
212
|
+
Note: if you add `attrs` only, include the following CSS in your app:
|
|
299
213
|
|
|
300
214
|
```css
|
|
301
215
|
img {
|
|
@@ -304,16 +218,6 @@ img {
|
|
|
304
218
|
}
|
|
305
219
|
```
|
|
306
220
|
|
|
307
|
-
To pass size hints as parameters in the URL (frontmatter only, see [Demo](demo/components/content/Gallery.vue)):
|
|
308
|
-
|
|
309
|
-
```ts
|
|
310
|
-
{
|
|
311
|
-
imageSize: 'url'
|
|
312
|
-
}
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
Note that you can one, some or all keywords, i.e. `attrs url`.
|
|
316
|
-
|
|
317
221
|
### Debug
|
|
318
222
|
|
|
319
223
|
If you want to see what the module does as it runs, set `debug` to true:
|
package/dist/module.d.ts
CHANGED
package/dist/module.json
CHANGED