nuxt-content-assets 1.3.3 → 1.4.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/README.md +62 -57
- package/dist/module.d.mts +29 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +44 -23
- package/dist/runtime/assets/public.d.ts +3 -2
- package/dist/runtime/assets/public.mjs +13 -7
- package/dist/runtime/assets/source.d.ts +3 -2
- package/dist/runtime/assets/source.mjs +7 -2
- package/dist/runtime/content/plugin.mjs +44 -43
- package/dist/runtime/sockets/factory.d.ts +1 -1
- package/dist/runtime/sockets/plugin.mjs +2 -2
- package/dist/runtime/sockets/setup.d.ts +1 -1
- package/dist/runtime/utils/content.d.ts +2 -2
- package/dist/types.d.mts +8 -0
- package/dist/types.d.ts +4 -2
- package/package.json +23 -21
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
> Enable locally-located assets in Nuxt Content
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
|
11
|
-
<img src="https://raw.githubusercontent.com/davestewart/nuxt-content-assets/main/
|
|
11
|
+
<img src="https://raw.githubusercontent.com/davestewart/nuxt-content-assets/main/playground/content/splash.png" alt="Nuxt Content Assets logo">
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
14
|
## Overview
|
|
@@ -63,26 +63,28 @@ Developer experience:
|
|
|
63
63
|
- image size injection
|
|
64
64
|
- zero config
|
|
65
65
|
|
|
66
|
-
##
|
|
66
|
+
## Playground
|
|
67
67
|
|
|
68
|
-
To
|
|
68
|
+
To test the module before installing, you can try out the Nuxt Content Assets playground.
|
|
69
|
+
|
|
70
|
+
To clone and run locally:
|
|
69
71
|
|
|
70
72
|
```bash
|
|
71
73
|
git clone https://github.com/davestewart/nuxt-content-assets.git
|
|
72
74
|
cd nuxt-content-assets
|
|
73
|
-
npm install
|
|
75
|
+
npm install && npm install --prefix ./playground
|
|
74
76
|
npm run dev
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
Then open the
|
|
79
|
+
Then open the playground in your browser at <a href="http://localhost:3000" target="_blank">localhost:3000</a>.
|
|
78
80
|
|
|
79
|
-
To run the
|
|
81
|
+
To run the playground online, visit:
|
|
80
82
|
|
|
81
|
-
- https://stackblitz.com/github/davestewart/nuxt-content-assets?file=
|
|
83
|
+
- https://stackblitz.com/github/davestewart/nuxt-content-assets?file=playground%2Fapp.vue
|
|
82
84
|
|
|
83
|
-
To browse the
|
|
85
|
+
To browse the playground folder:
|
|
84
86
|
|
|
85
|
-
- https://github.com/davestewart/nuxt-content-assets/tree/main/
|
|
87
|
+
- https://github.com/davestewart/nuxt-content-assets/tree/main/playground
|
|
86
88
|
|
|
87
89
|
## Setup
|
|
88
90
|
|
|
@@ -143,7 +145,7 @@ These values can then be passed to components:
|
|
|
143
145
|
:image-gallery{:data="images"}
|
|
144
146
|
```
|
|
145
147
|
|
|
146
|
-
See the
|
|
148
|
+
See the playground for [markup](playground/content/advanced/gallery.md) and [component](playground/components/content/ContentGallery.vue) examples.
|
|
147
149
|
|
|
148
150
|
### Live reload
|
|
149
151
|
|
|
@@ -171,7 +173,7 @@ Keeping this on prevents content jumps as your page loads.
|
|
|
171
173
|
|
|
172
174
|
#### Prose components
|
|
173
175
|
|
|
174
|
-
If you use [ProseImg](https://content.nuxtjs.org/api/components/prose) components, you can [hook into](
|
|
176
|
+
If you use [ProseImg](https://content.nuxtjs.org/api/components/prose) components, you can [hook into](playground/components/temp/ProseImg.vue) image size hints via the `$attrs` property:
|
|
175
177
|
|
|
176
178
|
```vue
|
|
177
179
|
<template>
|
|
@@ -189,7 +191,7 @@ export default {
|
|
|
189
191
|
|
|
190
192
|
#### Frontmatter
|
|
191
193
|
|
|
192
|
-
If you pass [frontmatter](
|
|
194
|
+
If you pass [frontmatter](playground/content/advanced/gallery.md) to [custom components](playground/components/content/ContentImage.vue) set `imageSize` to `'src'` to encode values in `src`:
|
|
193
195
|
|
|
194
196
|
```
|
|
195
197
|
:image-content{:src="image"}
|
|
@@ -201,24 +203,32 @@ The component will receive the size information as a query string which you can
|
|
|
201
203
|
<img class="image-content" src="/image.jpg?width=640&height=480">
|
|
202
204
|
```
|
|
203
205
|
|
|
204
|
-
See
|
|
205
|
-
|
|
206
|
-
### Nuxt Image compatibility
|
|
206
|
+
See playground component [here](playground/components/content/ContentImage.vue).
|
|
207
207
|
|
|
208
|
-
|
|
208
|
+
### Nuxt Image
|
|
209
209
|
|
|
210
|
-
|
|
210
|
+
Nuxt Content Assets works with [Nuxt Image](https://image.nuxtjs.org/) with just a little configuration:
|
|
211
211
|
|
|
212
212
|
```ts
|
|
213
213
|
// nuxt.config.ts
|
|
214
214
|
export default defineNuxtConfig({
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
modules: [
|
|
216
|
+
// Nuxt Image should be placed before Nuxt Content Assets
|
|
217
|
+
'@nuxt/image',
|
|
218
|
+
'nuxt-content-assets',
|
|
219
|
+
'@nuxt/content',
|
|
220
|
+
],
|
|
221
|
+
|
|
222
|
+
extends: [
|
|
223
|
+
// add Nuxt Content Assets build folder as a Nuxt Layer (since v1.4.0)
|
|
224
|
+
'.nuxt/content-assets',
|
|
225
|
+
],
|
|
218
226
|
}
|
|
219
227
|
```
|
|
220
228
|
|
|
221
|
-
|
|
229
|
+
> Note that the new Layers setup enables Nuxt Image to load images from both the project's `public` folder and from `content`.
|
|
230
|
+
|
|
231
|
+
To serve all images as Nuxt Image images, create a `ProseImg` component like so:
|
|
222
232
|
|
|
223
233
|
```vue
|
|
224
234
|
<!-- components/content/ProseImg.vue -->
|
|
@@ -227,9 +237,7 @@ Then, create a `ProseImg` component like so:
|
|
|
227
237
|
</template>
|
|
228
238
|
```
|
|
229
239
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
> For a per-image solution, check the [override](demo/components/content/NuxtImg.ts) in the demo folder.
|
|
240
|
+
See the playground folder for both the [global](playground/components/temp/ProseImg.vue) and a [per image](playground/components/content/NuxtImg.ts) solution.
|
|
233
241
|
|
|
234
242
|
|
|
235
243
|
## Configuration
|
|
@@ -264,12 +272,12 @@ You can add one or more image size hints to the generated images:
|
|
|
264
272
|
|
|
265
273
|
Pick from the following switches:
|
|
266
274
|
|
|
267
|
-
| Switch | What it does
|
|
268
|
-
|
|
269
|
-
| `'style'` | Adds `style="aspect-ratio:..."` to any `<img>` tag
|
|
270
|
-
| `'attrs'` | Adds `width` and `height` attributes to any `<img>` tag
|
|
275
|
+
| Switch | What it does |
|
|
276
|
+
|-----------|--------------------------------------------------------------------|
|
|
277
|
+
| `'style'` | Adds `style="aspect-ratio:..."` to any `<img>` tag |
|
|
278
|
+
| `'attrs'` | Adds `width` and `height` attributes to any `<img>` tag |
|
|
271
279
|
| `'src'` | Adds `?width=...&height=...` to `src` attribute (frontmatter only) |
|
|
272
|
-
| `false` | Disable image size hints
|
|
280
|
+
| `false` | Disable image size hints |
|
|
273
281
|
|
|
274
282
|
Note: if you add *only* `attrs`, include the following CSS in your app:
|
|
275
283
|
|
|
@@ -318,13 +326,16 @@ In development, file watching propagates asset changes to the public folder, upd
|
|
|
318
326
|
|
|
319
327
|
Should you wish to develop the project, the scripts are:
|
|
320
328
|
|
|
321
|
-
Develop the module
|
|
329
|
+
Develop the module (running the playground which uses the live module code):
|
|
322
330
|
|
|
323
331
|
```bash
|
|
324
332
|
# install dependencies
|
|
325
333
|
npm install
|
|
326
334
|
|
|
327
|
-
#
|
|
335
|
+
# generate playground type stubs (for the first time)
|
|
336
|
+
npm run dev:prepare
|
|
337
|
+
|
|
338
|
+
# develop (runs the playground app)
|
|
328
339
|
npm run dev
|
|
329
340
|
|
|
330
341
|
# run eslint
|
|
@@ -335,50 +346,44 @@ npm run test
|
|
|
335
346
|
npm run test:watch
|
|
336
347
|
```
|
|
337
348
|
|
|
338
|
-
Build and check the
|
|
349
|
+
Build and check the playground (simulating users' final build choices):
|
|
339
350
|
|
|
340
351
|
```bash
|
|
341
|
-
# generate
|
|
342
|
-
npm run
|
|
343
|
-
|
|
344
|
-
# generate the demo output
|
|
345
|
-
npm run demo:generate
|
|
352
|
+
# generate the playground
|
|
353
|
+
npm run dev:generate
|
|
346
354
|
|
|
347
|
-
#
|
|
348
|
-
npm run
|
|
355
|
+
# build the playground
|
|
356
|
+
npm run dev:build
|
|
349
357
|
|
|
350
|
-
#
|
|
351
|
-
npm run
|
|
358
|
+
# serve the generated / built playground
|
|
359
|
+
npm run dev:preview
|
|
352
360
|
```
|
|
353
361
|
|
|
354
|
-
Make a new release:
|
|
362
|
+
Make a new release (so users can install the module):
|
|
355
363
|
|
|
356
364
|
```bash
|
|
357
|
-
# release new version
|
|
358
|
-
npm run release
|
|
359
|
-
|
|
360
365
|
# dry run the release
|
|
361
366
|
npm run release:dry
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
Make sure to edit changelog and update `package.json` version first!
|
|
365
367
|
|
|
366
|
-
|
|
368
|
+
# release new version
|
|
369
|
+
npm run release
|
|
370
|
+
```
|
|
367
371
|
|
|
368
|
-
|
|
372
|
+
Make sure to edit changelog and update `package.json` version before releasing!
|
|
369
373
|
|
|
370
|
-
|
|
374
|
+
## Maintenance
|
|
371
375
|
|
|
372
|
-
|
|
376
|
+
This module was created using the Nuxt [Module Builder](https://github.com/nuxt/module-builder) command:
|
|
373
377
|
|
|
374
|
-
|
|
378
|
+
```bash
|
|
379
|
+
npx nuxi init -t module nuxt-content-assets
|
|
380
|
+
```
|
|
375
381
|
|
|
376
|
-
|
|
382
|
+
This created the module code from the starter template found here:
|
|
377
383
|
|
|
378
|
-
- https://github.com/nuxt/
|
|
379
|
-
- https://github.com/davestewart/nuxt-content-assets/issues/49
|
|
384
|
+
- https://github.com/nuxt/starter/tree/module
|
|
380
385
|
|
|
381
|
-
|
|
386
|
+
Both [Nuxi](https://github.com/nuxt/cli) and the module's dependencies and scripts are updated fairly regularly, so from time to time this module may need to be updated to keep in sync. So far, this has meant just updating the dependencies and scripts, which are found in the starter template code mentioned above.
|
|
382
387
|
|
|
383
388
|
<!-- Badges -->
|
|
384
389
|
[npm-version-src]: https://img.shields.io/npm/v/nuxt-content-assets/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
|
|
3
|
+
interface ModuleOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Image size hints
|
|
6
|
+
*
|
|
7
|
+
* @example 'attrs style url'
|
|
8
|
+
* @default 'style'
|
|
9
|
+
*/
|
|
10
|
+
imageSize?: string | string[] | false;
|
|
11
|
+
/**
|
|
12
|
+
* List of content extensions; anything else as an asset
|
|
13
|
+
*
|
|
14
|
+
* @example 'md'
|
|
15
|
+
* @default 'md csv ya?ml json'
|
|
16
|
+
*/
|
|
17
|
+
contentExtensions?: string | string[];
|
|
18
|
+
/**
|
|
19
|
+
* Display debug messages
|
|
20
|
+
*
|
|
21
|
+
* @example true
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
28
|
+
|
|
29
|
+
export { _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -376,22 +376,29 @@ function makeSourceManager(key, source, publicPath, callback) {
|
|
|
376
376
|
return paths;
|
|
377
377
|
}
|
|
378
378
|
const storage = makeSourceStorage(source, key);
|
|
379
|
-
storage.watch(onWatch);
|
|
379
|
+
void storage.watch(onWatch);
|
|
380
|
+
async function dispose() {
|
|
381
|
+
await storage.unwatch();
|
|
382
|
+
await storage.dispose();
|
|
383
|
+
}
|
|
380
384
|
return {
|
|
381
385
|
storage,
|
|
382
386
|
init,
|
|
383
|
-
keys: getKeys
|
|
387
|
+
keys: getKeys,
|
|
388
|
+
dispose
|
|
384
389
|
};
|
|
385
390
|
}
|
|
386
391
|
|
|
387
|
-
function makeAssetsManager(publicPath) {
|
|
392
|
+
function makeAssetsManager(publicPath, shouldWatch = true) {
|
|
388
393
|
const indexKey = "assets.json";
|
|
389
394
|
const storage = makeSourceStorage(Path.join(publicPath, ".."));
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
+
if (shouldWatch) {
|
|
396
|
+
void storage.watch(async (event, key) => {
|
|
397
|
+
if (event === "update" && key === indexKey) {
|
|
398
|
+
await load();
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
}
|
|
395
402
|
const assets = {};
|
|
396
403
|
async function load() {
|
|
397
404
|
const data = await storage.getItem(indexKey);
|
|
@@ -445,7 +452,11 @@ function makeAssetsManager(publicPath) {
|
|
|
445
452
|
setAsset,
|
|
446
453
|
getAsset,
|
|
447
454
|
removeAsset,
|
|
448
|
-
resolveAsset
|
|
455
|
+
resolveAsset,
|
|
456
|
+
dispose: async () => {
|
|
457
|
+
await storage.unwatch();
|
|
458
|
+
await storage.dispose();
|
|
459
|
+
}
|
|
449
460
|
};
|
|
450
461
|
}
|
|
451
462
|
function getAssetPaths(srcDir, srcAbs) {
|
|
@@ -515,21 +526,24 @@ const module = defineNuxtModule({
|
|
|
515
526
|
debug: false
|
|
516
527
|
},
|
|
517
528
|
async setup(options, nuxt) {
|
|
518
|
-
var _a, _b;
|
|
519
529
|
const buildPath = nuxt.options.buildDir;
|
|
520
530
|
const assetsPath = Path.join(buildPath, "content-assets");
|
|
521
531
|
const publicPath = Path.join(assetsPath, "public");
|
|
522
532
|
const contentPath = Path.join(buildPath, "content-cache/parsed");
|
|
523
|
-
|
|
533
|
+
const isDev = !!nuxt.options.dev;
|
|
534
|
+
const isDebug = !!options.debug;
|
|
535
|
+
if (isDebug) {
|
|
524
536
|
log("Removing cache folders...");
|
|
525
537
|
}
|
|
526
538
|
removeFolder(Path.join(buildPath, "content-cache"));
|
|
527
539
|
removeFolder(assetsPath);
|
|
540
|
+
createFolder(`${assetsPath}/public`);
|
|
541
|
+
writeFile(`${assetsPath}/nuxt.config.ts`, "export default {}");
|
|
528
542
|
const { contentExtensions } = options;
|
|
529
543
|
if (contentExtensions) {
|
|
530
|
-
|
|
544
|
+
nuxt.options.content ||= {};
|
|
531
545
|
if (nuxt.options.content) {
|
|
532
|
-
|
|
546
|
+
nuxt.options.content.ignores ||= [];
|
|
533
547
|
}
|
|
534
548
|
const ignores = makeIgnores(contentExtensions);
|
|
535
549
|
nuxt.options.content?.ignores.push(ignores);
|
|
@@ -550,7 +564,7 @@ const module = defineNuxtModule({
|
|
|
550
564
|
};
|
|
551
565
|
}
|
|
552
566
|
}
|
|
553
|
-
const assets = makeAssetsManager(publicPath);
|
|
567
|
+
const assets = makeAssetsManager(publicPath, isDev);
|
|
554
568
|
function onAssetChange(event, absTrg) {
|
|
555
569
|
let src = "";
|
|
556
570
|
let width;
|
|
@@ -580,10 +594,10 @@ const module = defineNuxtModule({
|
|
|
580
594
|
}
|
|
581
595
|
}
|
|
582
596
|
addPlugin(resolve("./runtime/sockets/plugin"));
|
|
583
|
-
const socket =
|
|
597
|
+
const socket = isDev ? await setupSocketServer("content-assets") : null;
|
|
584
598
|
const managers = {};
|
|
585
599
|
for (const [key, source] of Object.entries(sources)) {
|
|
586
|
-
if (
|
|
600
|
+
if (isDebug) {
|
|
587
601
|
log(`Creating source "${key}"`);
|
|
588
602
|
}
|
|
589
603
|
managers[key] = makeSourceManager(key, source, publicPath, onAssetChange);
|
|
@@ -592,29 +606,36 @@ const module = defineNuxtModule({
|
|
|
592
606
|
for (const [key, manager] of Object.entries(managers)) {
|
|
593
607
|
const paths = await manager.init();
|
|
594
608
|
paths.forEach((path) => assets.setAsset(path));
|
|
595
|
-
if (
|
|
609
|
+
if (isDebug) {
|
|
596
610
|
list(`Copied "${key}" assets`, paths.map((path) => Path.relative(publicPath, path)));
|
|
597
611
|
}
|
|
598
612
|
}
|
|
599
613
|
});
|
|
614
|
+
nuxt.hook("close", async () => {
|
|
615
|
+
await assets.dispose();
|
|
616
|
+
for (const key in managers) {
|
|
617
|
+
await managers[key].dispose();
|
|
618
|
+
}
|
|
619
|
+
});
|
|
600
620
|
const pluginPath = resolve("./runtime/content/plugin");
|
|
601
621
|
const makeVar = (name, value) => `export const ${name} = ${JSON.stringify(value)};`;
|
|
602
622
|
const virtualConfig = [
|
|
603
623
|
makeVar("publicPath", publicPath),
|
|
604
624
|
makeVar("imageSizes", imageSizes),
|
|
605
|
-
makeVar("debug",
|
|
625
|
+
makeVar("debug", isDebug)
|
|
606
626
|
].join("\n");
|
|
607
627
|
nuxt.hook("nitro:config", async (config) => {
|
|
608
|
-
config.plugins
|
|
628
|
+
config.plugins ||= [];
|
|
609
629
|
config.plugins.push(pluginPath);
|
|
610
|
-
config.virtual
|
|
630
|
+
config.virtual ||= {};
|
|
611
631
|
config.virtual[`#${meta.name}`] = () => {
|
|
612
632
|
return virtualConfig;
|
|
613
633
|
};
|
|
614
|
-
config.publicAssets
|
|
634
|
+
config.publicAssets ||= [];
|
|
615
635
|
config.publicAssets.push({
|
|
616
|
-
dir: publicPath
|
|
617
|
-
|
|
636
|
+
dir: publicPath,
|
|
637
|
+
maxAge: 60 * 60 * 24 * 7
|
|
638
|
+
// 7 days
|
|
618
639
|
});
|
|
619
640
|
});
|
|
620
641
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { ParsedContent, AssetConfig } from '../../types';
|
|
1
|
+
import type { ParsedContent, AssetConfig } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Manages the public assets
|
|
4
4
|
*/
|
|
5
|
-
export declare function makeAssetsManager(publicPath: string): {
|
|
5
|
+
export declare function makeAssetsManager(publicPath: string, shouldWatch?: boolean): {
|
|
6
6
|
setAsset: (path: string) => AssetConfig;
|
|
7
7
|
getAsset: (path: string) => AssetConfig | undefined;
|
|
8
8
|
removeAsset: (path: string) => AssetConfig | undefined;
|
|
9
9
|
resolveAsset: (content: ParsedContent, relAsset: string, registerContent?: boolean) => AssetConfig;
|
|
10
|
+
dispose: () => Promise<void>;
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* Hash of replacer functions
|
|
@@ -4,14 +4,16 @@ import debounce from "debounce";
|
|
|
4
4
|
import { hash } from "ohash";
|
|
5
5
|
import { makeSourceStorage } from "./source.mjs";
|
|
6
6
|
import { isImage, warn, log } from "../utils/index.mjs";
|
|
7
|
-
export function makeAssetsManager(publicPath) {
|
|
7
|
+
export function makeAssetsManager(publicPath, shouldWatch = true) {
|
|
8
8
|
const indexKey = "assets.json";
|
|
9
9
|
const storage = makeSourceStorage(Path.join(publicPath, ".."));
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
if (shouldWatch) {
|
|
11
|
+
void storage.watch(async (event, key) => {
|
|
12
|
+
if (event === "update" && key === indexKey) {
|
|
13
|
+
await load();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
15
17
|
const assets = {};
|
|
16
18
|
async function load() {
|
|
17
19
|
const data = await storage.getItem(indexKey);
|
|
@@ -65,7 +67,11 @@ export function makeAssetsManager(publicPath) {
|
|
|
65
67
|
setAsset,
|
|
66
68
|
getAsset,
|
|
67
69
|
removeAsset,
|
|
68
|
-
resolveAsset
|
|
70
|
+
resolveAsset,
|
|
71
|
+
dispose: async () => {
|
|
72
|
+
await storage.unwatch();
|
|
73
|
+
await storage.dispose();
|
|
74
|
+
}
|
|
69
75
|
};
|
|
70
76
|
}
|
|
71
77
|
export const replacers = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MountOptions } from '@nuxt/content';
|
|
2
|
-
import { WatchEvent, Storage } from 'unstorage';
|
|
1
|
+
import { type MountOptions } from '@nuxt/content';
|
|
2
|
+
import { type WatchEvent, type Storage } from 'unstorage';
|
|
3
3
|
/**
|
|
4
4
|
* Make a Storage instance that monitors assets from a single source
|
|
5
5
|
*/
|
|
@@ -8,6 +8,7 @@ export interface SourceManager {
|
|
|
8
8
|
storage: Storage;
|
|
9
9
|
init: () => Promise<string[]>;
|
|
10
10
|
keys: () => Promise<string[]>;
|
|
11
|
+
dispose: () => Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
13
14
|
* Make a SourceManager instance
|
|
@@ -90,10 +90,15 @@ export function makeSourceManager(key, source, publicPath, callback) {
|
|
|
90
90
|
return paths;
|
|
91
91
|
}
|
|
92
92
|
const storage = makeSourceStorage(source, key);
|
|
93
|
-
storage.watch(onWatch);
|
|
93
|
+
void storage.watch(onWatch);
|
|
94
|
+
async function dispose() {
|
|
95
|
+
await storage.unwatch();
|
|
96
|
+
await storage.dispose();
|
|
97
|
+
}
|
|
94
98
|
return {
|
|
95
99
|
storage,
|
|
96
100
|
init,
|
|
97
|
-
keys: getKeys
|
|
101
|
+
keys: getKeys,
|
|
102
|
+
dispose
|
|
98
103
|
};
|
|
99
104
|
}
|
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
import { buildQuery, buildStyle, isValidAsset, list, parseQuery, removeQuery, walkBody, walkMeta } from "../utils/index.mjs";
|
|
2
2
|
import { makeAssetsManager } from "../assets/public.mjs";
|
|
3
3
|
import { debug, imageSizes, publicPath } from "#nuxt-content-assets";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
function processBody(content, imageSizes2 = [], updated = []) {
|
|
18
|
-
walkBody(content, function(node) {
|
|
19
|
-
const { tag, props } = node;
|
|
20
|
-
for (const [prop, value] of Object.entries(props)) {
|
|
21
|
-
if (typeof value !== "string") {
|
|
22
|
-
return;
|
|
4
|
+
const plugin = async (nitro) => {
|
|
5
|
+
function processMeta(content, imageSizes2 = [], updated = []) {
|
|
6
|
+
walkMeta(content, (value, parent, key) => {
|
|
7
|
+
if (isValidAsset(value)) {
|
|
8
|
+
const { srcAttr, width, height } = resolveAsset(content, removeQuery(value), true);
|
|
9
|
+
if (srcAttr) {
|
|
10
|
+
const query = width && height && (imageSizes2.includes("src") || imageSizes2.includes("url")) ? `width=${width}&height=${height}` : "";
|
|
11
|
+
const srcUrl = query ? buildQuery(srcAttr, parseQuery(value), query) : srcAttr;
|
|
12
|
+
parent[key] = srcUrl;
|
|
13
|
+
updated.push(`meta: ${key} to "${srcUrl}"`);
|
|
14
|
+
}
|
|
23
15
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
node.props.
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function processBody(content, imageSizes2 = [], updated = []) {
|
|
19
|
+
walkBody(content, function(node) {
|
|
20
|
+
const { tag, props } = node;
|
|
21
|
+
for (const [prop, value] of Object.entries(props)) {
|
|
22
|
+
if (typeof value !== "string") {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const { srcAttr, width, height } = resolveAsset(content, value, true);
|
|
26
|
+
if (srcAttr) {
|
|
27
|
+
node.props[prop] = srcAttr;
|
|
28
|
+
if (node.tag === "img" || node.tag === "nuxt-img") {
|
|
29
|
+
if (width && height) {
|
|
30
|
+
if (imageSizes2.includes("attrs")) {
|
|
31
|
+
node.props.width = width;
|
|
32
|
+
node.props.height = height;
|
|
33
|
+
}
|
|
34
|
+
if (imageSizes2.includes("style")) {
|
|
35
|
+
const ratio = `${width}/${height}`;
|
|
36
|
+
if (typeof node.props.style === "string") {
|
|
37
|
+
node.props.style = buildStyle(node.props.style, `aspect-ratio: ${ratio}`);
|
|
38
|
+
} else {
|
|
39
|
+
node.props.style ||= {};
|
|
40
|
+
node.props.style.aspectRatio = ratio;
|
|
41
|
+
}
|
|
40
42
|
}
|
|
41
43
|
}
|
|
44
|
+
} else if (node.tag === "a") {
|
|
45
|
+
node.props.target ||= "_blank";
|
|
42
46
|
}
|
|
43
|
-
|
|
44
|
-
node.props.target ||= "_blank";
|
|
47
|
+
updated.push(`page: ${tag}[${prop}] to "${srcAttr}"`);
|
|
45
48
|
}
|
|
46
|
-
updated.push(`page: ${tag}[${prop}] to "${srcAttr}"`);
|
|
47
49
|
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const { resolveAsset } = makeAssetsManager(publicPath);
|
|
52
|
-
const plugin = async (nitro) => {
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const { resolveAsset, dispose } = makeAssetsManager(publicPath, import.meta.dev);
|
|
53
53
|
nitro.hooks.hook("content:file:afterParse", function(content) {
|
|
54
54
|
if (content._extension === "md") {
|
|
55
55
|
const updated = [];
|
|
@@ -61,5 +61,6 @@ const plugin = async (nitro) => {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
|
+
nitro.hooks.hook("close", dispose);
|
|
64
65
|
};
|
|
65
66
|
export default plugin;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineNuxtPlugin, refreshNuxtData, useRuntimeConfig } from "#imports";
|
|
2
2
|
export default defineNuxtPlugin(async () => {
|
|
3
|
-
if (
|
|
3
|
+
if (import.meta.client) {
|
|
4
4
|
const url = useRuntimeConfig().public.sockets?.wsUrl;
|
|
5
|
-
const socket = await import("./setup").then(({ setupSocketClient }) => {
|
|
5
|
+
const socket = await import("./setup.mjs").then(({ setupSocketClient }) => {
|
|
6
6
|
return setupSocketClient(url, "content-assets");
|
|
7
7
|
});
|
|
8
8
|
if (socket) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Callback, SocketInstance } from '../../types';
|
|
1
|
+
import type { Callback, SocketInstance } from '../../types';
|
|
2
2
|
export declare function setupSocketClient(url: string, channel: string, callback?: Callback): SocketInstance | null;
|
package/dist/types.d.mts
ADDED
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-content-assets",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Enable locally-located assets in Nuxt Content",
|
|
5
5
|
"repository": "davestewart/nuxt-content-assets",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,24 +18,23 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"dev": "nuxi dev
|
|
22
|
-
"
|
|
21
|
+
"dev": "nuxi dev playground",
|
|
22
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
23
|
+
"dev:generate": "nuxi generate playground",
|
|
24
|
+
"dev:build": "nuxi build playground",
|
|
25
|
+
"dev:preview": "nuxi preview playground",
|
|
26
|
+
"release:dry": "npm run lint && npm run test && nuxt-module-build build && npm publish --dry-run",
|
|
27
|
+
"release": "npm run lint && npm run test && nuxt-module-build build && changelogen --release && npm publish && git push --follow-tags",
|
|
23
28
|
"lint": "eslint .",
|
|
24
29
|
"test": "vitest run",
|
|
25
|
-
"test:watch": "vitest watch"
|
|
26
|
-
"demo:prepare": "nuxt-module-build --stub && nuxi prepare demo",
|
|
27
|
-
"demo:generate": "nuxt generate demo",
|
|
28
|
-
"demo:serve": "npx serve demo/dist",
|
|
29
|
-
"demo:build": "nuxi build demo",
|
|
30
|
-
"release": "npm run lint && npm run test && npm run build && npm publish && git push --follow-tags",
|
|
31
|
-
"release:dry": "npm run lint && npm run test && npm run build && npm publish --dry-run"
|
|
30
|
+
"test:watch": "vitest watch"
|
|
32
31
|
},
|
|
33
32
|
"dependencies": {
|
|
34
|
-
"@nuxt/kit": "^3.
|
|
33
|
+
"@nuxt/kit": "^3.11.2",
|
|
35
34
|
"crosspath": "^2.0.0",
|
|
36
35
|
"debounce": "^1.2.1",
|
|
37
36
|
"image-size": "^1.0.2",
|
|
38
|
-
"listhen": "^1.
|
|
37
|
+
"listhen": "^1.7.2",
|
|
39
38
|
"ohash": "^1.0.0",
|
|
40
39
|
"unist-util-visit": "^4.1.2",
|
|
41
40
|
"unstorage": "^1.4.1",
|
|
@@ -45,17 +44,20 @@
|
|
|
45
44
|
"@nuxt/content": "^2.0.0"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
|
-
"@
|
|
49
|
-
"@nuxt/
|
|
50
|
-
"@nuxt/
|
|
51
|
-
"@nuxt/
|
|
47
|
+
"@types/node": "^20.12.4",
|
|
48
|
+
"@nuxt/devtools": "latest",
|
|
49
|
+
"@nuxt/eslint-config": "^0.2.0",
|
|
50
|
+
"@nuxt/module-builder": "^0.5.5",
|
|
51
|
+
"@nuxt/schema": "^3.11.2",
|
|
52
|
+
"@nuxt/test-utils": "^3.12.0",
|
|
53
|
+
"changelogen": "^0.5.5",
|
|
54
|
+
"eslint": "^8.57.0",
|
|
55
|
+
"nuxt": "^3.11.2",
|
|
56
|
+
"vitest": "^1.4.0",
|
|
52
57
|
"@types/debounce": "^1.2.1",
|
|
53
|
-
"@types/ws": "^8.5.
|
|
54
|
-
"eslint": "^8.36.0",
|
|
55
|
-
"nuxt": "3.6.5",
|
|
56
|
-
"vitest": "^0.30.0"
|
|
58
|
+
"@types/ws": "^8.5.10"
|
|
57
59
|
},
|
|
58
60
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
61
|
+
"node": ">=16.0.0"
|
|
60
62
|
}
|
|
61
63
|
}
|