nuxt-content-assets 0.6.1 → 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 +49 -140
- package/dist/module.d.ts +0 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +339 -109
- package/dist/runtime/options.d.ts +4 -4
- package/dist/runtime/options.mjs +7 -11
- package/dist/runtime/plugin.mjs +33 -28
- package/dist/runtime/services/assets.d.ts +18 -0
- package/dist/runtime/services/assets.mjs +30 -0
- package/dist/runtime/services/index.d.ts +3 -0
- package/dist/runtime/services/index.mjs +3 -0
- package/dist/runtime/{utils → services}/paths.d.ts +2 -3
- package/dist/runtime/{utils → services}/paths.mjs +6 -4
- 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 -0
- package/dist/runtime/services/sources.mjs +92 -0
- package/dist/runtime/utils/{assets.d.ts → assert.d.ts} +7 -3
- package/dist/runtime/utils/{assets.mjs → assert.mjs} +7 -4
- package/dist/runtime/utils/debug.d.ts +1 -1
- package/dist/runtime/utils/debug.mjs +5 -8
- package/dist/runtime/utils/fs.d.ts +7 -0
- package/dist/runtime/utils/fs.mjs +32 -0
- package/dist/runtime/utils/index.d.ts +3 -4
- package/dist/runtime/utils/index.mjs +3 -4
- package/dist/runtime/utils/string.d.ts +7 -0
- package/dist/runtime/utils/string.mjs +12 -0
- package/dist/runtime/watcher.d.ts +2 -0
- package/dist/runtime/watcher.mjs +18 -0
- package/package.json +12 -2
- package/dist/runtime/utils/config.d.ts +0 -4
- package/dist/runtime/utils/config.mjs +0 -3
- package/dist/runtime/utils/content.d.ts +0 -7
- package/dist/runtime/utils/content.mjs +0 -12
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,62 +95,34 @@ 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
|
-
images/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
|
---
|
|
120
102
|
title: Portfolio Item 1
|
|
121
103
|
images:
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
104
|
+
- assets/image-1.jpg
|
|
105
|
+
- assets/image-2.jpg
|
|
106
|
+
- assets/image-3.jpg
|
|
125
107
|
---
|
|
126
108
|
```
|
|
127
109
|
|
|
128
|
-
|
|
110
|
+
These values can then be passed to components:
|
|
129
111
|
|
|
130
112
|
```markdown
|
|
131
|
-
::gallery{:
|
|
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
|
-
// add 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,86 +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/content/[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/content/
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
The optional second part of the path indicates the relative location of each image:
|
|
229
|
-
|
|
230
|
-
| Token | Description | Example |
|
|
231
|
-
|-------------|--------------------------------------------|--------------------|
|
|
232
|
-
| `[folder]` | The relative folder of the file | `posts/2023-01-01` |
|
|
233
|
-
| `[file]` | The full filename of the file | `featured.jpg` |
|
|
234
|
-
| `[name]` | The name of the file without the extension | `featured` |
|
|
235
|
-
| `[hash]` | A hash of the absolute source path | `9M00N4l9A0` |
|
|
236
|
-
| `[extname]` | The full extension with the dot | `.jpg` |
|
|
237
|
-
| `[ext]` | The extension without the dot | `jpg` |
|
|
238
|
-
|
|
239
|
-
For example:
|
|
240
|
-
|
|
241
|
-
| Template | Output |
|
|
242
|
-
|--------------------------------------|----------------------------------------------------|
|
|
243
|
-
| `assets/img/content/[folder]/[file]` | `assets/img/content/posts/2023-01-01/featured.jpg` |
|
|
244
|
-
| `assets/img/[name]-[hash].[ext]` | `assets/img/featured-9M00N4l9A0.jpg` |
|
|
245
|
-
| `content/[hash].[ext]` | `content/9M00N4l9A0.jpg` |
|
|
246
|
-
|
|
247
|
-
Note that the module defaults to:
|
|
248
|
-
|
|
249
|
-
```
|
|
250
|
-
/assets/content/[folder]/[file]
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
### Extensions
|
|
254
|
-
|
|
255
|
-
You can add (or replace) supported extensions if you need to:
|
|
256
|
-
|
|
257
|
-
To add extensions, use `additionalExtensions`:
|
|
258
|
-
|
|
259
|
-
```ts
|
|
260
|
-
{
|
|
261
|
-
additionalExtensions: 'html' // add support for html
|
|
262
|
-
}
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
To replace extensions, use `extensions`:
|
|
266
|
-
|
|
267
|
-
```ts
|
|
268
|
-
{
|
|
269
|
-
extensions: 'png jpg' // serve png and jpg files only
|
|
270
|
-
}
|
|
271
|
-
```
|
|
192
|
+
Note that from version `0.9.0-alpha` the `output` location is no longer configurable; images are copied relative to their original locations.
|
|
272
193
|
|
|
273
194
|
### Image size
|
|
274
195
|
|
|
275
|
-
You can add image size hints to the generated images
|
|
276
|
-
|
|
277
|
-
To add `style` aspect-ratio:
|
|
196
|
+
You can add one or more image size hints to the generated images:
|
|
278
197
|
|
|
279
198
|
```ts
|
|
280
199
|
{
|
|
281
|
-
imageSize: '
|
|
200
|
+
imageSize: 'attrs url'
|
|
282
201
|
}
|
|
283
202
|
```
|
|
284
203
|
|
|
285
|
-
|
|
204
|
+
Pick from the following switches:
|
|
286
205
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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 |
|
|
292
211
|
|
|
293
|
-
|
|
212
|
+
Note: if you add `attrs` only, include the following CSS in your app:
|
|
294
213
|
|
|
295
214
|
```css
|
|
296
215
|
img {
|
|
@@ -299,16 +218,6 @@ img {
|
|
|
299
218
|
}
|
|
300
219
|
```
|
|
301
220
|
|
|
302
|
-
To pass size hints as parameters in the URL (frontmatter only, see [Demo](demo/components/content/Gallery.vue)):
|
|
303
|
-
|
|
304
|
-
```ts
|
|
305
|
-
{
|
|
306
|
-
imageSize: 'url'
|
|
307
|
-
}
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
Note that you can one, some or all keywords, i.e. `attrs url`.
|
|
311
|
-
|
|
312
221
|
### Debug
|
|
313
222
|
|
|
314
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