nuxt-content-assets 1.4.3 → 1.5.1

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.
Files changed (38) hide show
  1. package/README.md +12 -8
  2. package/dist/module.d.mts +1 -27
  3. package/dist/module.json +6 -2
  4. package/dist/module.mjs +11 -435
  5. package/dist/runtime/assets/public.d.ts +1 -1
  6. package/dist/runtime/assets/{public.mjs → public.js} +4 -4
  7. package/dist/runtime/assets/{source.mjs → source.js} +1 -1
  8. package/dist/runtime/content/parsed.d.ts +1 -1
  9. package/dist/runtime/content/{parsed.mjs → parsed.js} +1 -1
  10. package/dist/runtime/content/{plugin.mjs → plugin.js} +2 -2
  11. package/dist/runtime/sockets/factory.d.ts +1 -1
  12. package/dist/runtime/sockets/{factory.mjs → factory.js} +2 -2
  13. package/dist/runtime/sockets/plugin.d.ts +1 -1
  14. package/dist/runtime/sockets/{plugin.mjs → plugin.js} +1 -1
  15. package/dist/runtime/sockets/setup.d.ts +1 -1
  16. package/dist/runtime/sockets/{setup.mjs → setup.js} +1 -1
  17. package/dist/runtime/utils/build.d.ts +1 -1
  18. package/dist/runtime/utils/config.d.ts +1 -0
  19. package/dist/runtime/utils/{config.mjs → config.js} +3 -1
  20. package/dist/runtime/utils/content.d.ts +2 -2
  21. package/dist/runtime/utils/{content.mjs → content.js} +2 -2
  22. package/dist/runtime/utils/fs.d.ts +1 -1
  23. package/dist/runtime/utils/index.d.ts +8 -8
  24. package/dist/runtime/utils/index.js +8 -0
  25. package/dist/runtime/utils/path.d.ts +6 -1
  26. package/dist/runtime/utils/{path.mjs → path.js} +6 -4
  27. package/dist/runtime/utils/string.d.ts +1 -1
  28. package/dist/types.d.mts +4 -5
  29. package/package.json +29 -29
  30. package/dist/module.cjs +0 -5
  31. package/dist/module.d.ts +0 -29
  32. package/dist/runtime/utils/index.mjs +0 -8
  33. package/dist/types.d.ts +0 -8
  34. /package/dist/runtime/utils/{build.mjs → build.js} +0 -0
  35. /package/dist/runtime/utils/{debug.mjs → debug.js} +0 -0
  36. /package/dist/runtime/utils/{fs.mjs → fs.js} +0 -0
  37. /package/dist/runtime/utils/{object.mjs → object.js} +0 -0
  38. /package/dist/runtime/utils/{string.mjs → string.js} +0 -0
package/README.md CHANGED
@@ -249,7 +249,7 @@ export default defineNuxtConfig({
249
249
  imageSize: 'style',
250
250
 
251
251
  // treat these extensions as content
252
- contentExtensions: 'md csv ya?ml json',
252
+ contentExtensions: 'mdx? csv ya?ml json',
253
253
 
254
254
  // output debug messages
255
255
  debug: false,
@@ -259,6 +259,10 @@ export default defineNuxtConfig({
259
259
 
260
260
  ### Image size
261
261
 
262
+ > [!Note]
263
+ >
264
+ > Since `v1.4.1` image size hints are now opt-in. This was done to maximise compatibiility with Nuxt Image.
265
+
262
266
  You can add one _or more_ image size hints to the generated images:
263
267
 
264
268
  ```ts
@@ -284,22 +288,22 @@ img {
284
288
  }
285
289
  ```
286
290
 
287
- > [!Note]
288
- >
289
- > Since `v1.4.1` image size hints are now opt-in. This was done to maximise compatibiility with Nuxt Image.
290
-
291
291
  ### Content extensions
292
292
 
293
293
  > [!NOTE]
294
294
  > Generally, you shouldn't need to touch this setting
295
295
 
296
- This setting tells Nuxt Content to ignore anything that is **not** one of these file extensions:
296
+ This setting tells Nuxt Content to ignore anything that is **not** one of the supported content types:
297
297
 
298
298
  ```
299
- md csv ya?ml json
299
+ mdx? csv ya?ml json
300
300
  ```
301
301
 
302
- This way, you can use any **other** file type as an asset, without needing to explicitly configure extensions.
302
+ This way, you can use any **other** file type as an asset, without needing to explicitly configure Nuxt Content's [ignores](https://content.nuxt.com/get-started/configuration#ignores) list.
303
+
304
+ Without this, Nuxt Content would warn about unsupported file types:
305
+
306
+ > [WARN] .jpg files are not supported, "content:path:to:some-asset.jpg" falling back to raw content
303
307
 
304
308
  ### Debug
305
309
 
package/dist/module.d.mts CHANGED
@@ -1,29 +1,3 @@
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>;
1
+ declare const _default: any;
28
2
 
29
3
  export { _default as default };
package/dist/module.json CHANGED
@@ -2,7 +2,11 @@
2
2
  "name": "nuxt-content-assets",
3
3
  "configKey": "contentAssets",
4
4
  "compatibility": {
5
- "nuxt": "^3.0.0"
5
+ "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "1.4.3"
7
+ "version": "1.5.1",
8
+ "builder": {
9
+ "@nuxt/module-builder": "1.0.2",
10
+ "unbuild": "3.6.1"
11
+ }
8
12
  }
package/dist/module.mjs CHANGED
@@ -1,200 +1,12 @@
1
1
  import * as Fs from 'fs';
2
- import Fs__default from 'fs';
3
2
  import Path from 'crosspath';
4
3
  import { useNuxt, createResolver, defineNuxtModule, addPlugin } from '@nuxt/kit';
5
- import { visit, SKIP, CONTINUE } from 'unist-util-visit';
4
+ import { isObject, log, warn, removeEntry, makeIgnores, matchTokens, list, isImage, toPath } from '../dist/runtime/utils/index.js';
6
5
  import { listen } from 'listhen';
7
6
  import { WebSocketServer, WebSocket } from 'ws';
8
- import githubDriver from 'unstorage/drivers/github';
9
- import fsDriver from 'unstorage/drivers/fs';
10
- import { createStorage } from 'unstorage';
11
- import getImageSize from 'image-size';
12
- import debounce from 'debounce';
13
- import 'ohash';
14
-
15
- function matchTokens(value) {
16
- let tokens = [];
17
- if (typeof value === "string") {
18
- tokens = value.match(/[^\s,|]+/g) || [];
19
- } else if (Array.isArray(value)) {
20
- tokens = value.filter((value2) => typeof value2 === "string").reduce((output, input) => {
21
- return [...output, ...matchTokens(input)];
22
- }, []);
23
- } else if (!!value && typeof value === "object") {
24
- tokens = Object.values(value).reduce((output, value2) => {
25
- return [...output, ...matchTokens(value2)];
26
- }, []);
27
- }
28
- return tokens.length ? Array.from(new Set(tokens)) : tokens;
29
- }
30
- function toPath(key) {
31
- return key.replaceAll(":", "/");
32
- }
33
- function deKey(path) {
34
- return path.replace(/^[^:]+:/, "");
35
- }
36
-
37
- const extensions = {
38
- // used to get image size
39
- image: matchTokens("png jpg jpeg gif svg webp ico"),
40
- // unused for now
41
- media: matchTokens("mp3 m4a wav mp4 mov webm ogg avi flv avchd")
42
- };
43
- function makeIgnores(extensions2) {
44
- const included = matchTokens(extensions2).join("|");
45
- return `^(?:(?!(${included})).)+$`;
46
- }
47
-
48
- function removeQuery(path) {
49
- return path.replace(/\?.*$/, "");
50
- }
51
- function isExcluded(path) {
52
- return path.split("/").some((segment) => segment.startsWith(".") || segment.startsWith("_"));
53
- }
54
- function isImage(path) {
55
- const ext = Path.extname(path).substring(1);
56
- return extensions.image.includes(ext);
57
- }
58
- function isArticle(path) {
59
- return removeQuery(path).endsWith(".md");
60
- }
61
- function isAsset(path) {
62
- return !isArticle(path);
63
- }
64
-
65
- function walk(node, callback, filter) {
66
- function visit(node2, callback2, parent, key) {
67
- if (filter) {
68
- const result = filter(node2, key);
69
- if (result === false) {
70
- return;
71
- }
72
- }
73
- if (Array.isArray(node2)) {
74
- node2.forEach((value, index) => {
75
- visit(value, callback2, node2, index);
76
- });
77
- } else if (isObject(node2)) {
78
- Object.keys(node2).forEach((key2) => {
79
- visit(node2[key2], callback2, node2, key2);
80
- });
81
- } else {
82
- callback2(node2, parent, key);
83
- }
84
- }
85
- visit(node, callback, { node }, "node");
86
- }
87
- function isObject(data) {
88
- return data && typeof data === "object" && !Array.isArray(data);
89
- }
90
-
91
- function walkMeta(content, callback) {
92
- walk(content, callback, (value, key) => !(String(key).startsWith("_") || key === "body"));
93
- }
94
- function walkBody(content, callback) {
95
- visit(content.body, (node) => node.type === "element", (node) => {
96
- const { tag, props } = node;
97
- const excluded = tags.exclude.includes(tag);
98
- if (excluded) {
99
- return SKIP;
100
- }
101
- const included = tags.include.includes(tag);
102
- if (included || !props) {
103
- return CONTINUE;
104
- }
105
- callback(node);
106
- });
107
- }
108
- const tags = {
109
- // unlikely to contain assets
110
- exclude: matchTokens({
111
- container: "pre code code-inline",
112
- formatting: "acronym abbr address bdi bdo big center cite del dfn font ins kbd mark meter progress q rp rt ruby s samp small strike sub sup time tt u var wbr",
113
- headers: "h1 h2 h3 h4 h5 h6",
114
- controls: "input textarea button select optgroup option label legend datalist output",
115
- media: "map area canvas svg",
116
- other: "style script noscript template",
117
- empty: "hr br"
118
- }),
119
- // may contain assets
120
- include: matchTokens({
121
- content: "main header footer section article aside details dialog summary data object nav blockquote div span p",
122
- table: "table caption th tr td thead tbody tfoot col colgroup",
123
- media: "figcaption figure picture",
124
- form: "form fieldset",
125
- list: "ul ol li dir dl dt dd",
126
- formatting: "strong b em i"
127
- }),
128
- // assets
129
- assets: "a img audio source track video embed"
130
- };
131
-
132
- const label = "[content-assets]";
133
- function log(...data) {
134
- console.info(label, ...data);
135
- }
136
- function warn(...data) {
137
- console.warn(label, ...data);
138
- }
139
- function list(message, items) {
140
- log(`${message}:
141
-
142
- ${items.map((item) => ` - ${item}`).join("\n")}
143
- `);
144
- }
145
-
146
- function buildQuery(...expr) {
147
- const output = expr.map((expr2) => expr2.replace(/^[?&]+|&+$/g, "")).filter((s) => s);
148
- if (output.length) {
149
- const [first, ...rest] = output;
150
- const isParam = (expr2) => /^[^?]+=[^=]+$/.test(expr2);
151
- return !isParam(first) ? rest.length > 0 ? first + (first.includes("?") ? "&" : "?") + rest.join("&") : first : "?" + output.join("&");
152
- }
153
- return "";
154
- }
155
-
156
- function readFile(path, asJson = false) {
157
- const text = Fs__default.readFileSync(path, { encoding: "utf8" });
158
- return asJson ? JSON.parse(text) : text;
159
- }
160
- function writeFile(path, data) {
161
- const text = typeof data === "object" ? JSON.stringify(data, null, " ") : String(data);
162
- createFolder(Path.dirname(path));
163
- Fs__default.writeFileSync(path, text, { encoding: "utf8" });
164
- }
165
- async function writeBlob(path, data) {
166
- const buffer = Buffer.from(await data.arrayBuffer());
167
- createFolder(Path.dirname(path));
168
- Fs__default.writeFileSync(path, buffer);
169
- }
170
- function copyFile(src, trg) {
171
- createFolder(Path.dirname(trg));
172
- Fs__default.copyFileSync(src, trg);
173
- }
174
- function removeFile(src) {
175
- Fs__default.rmSync(src);
176
- }
177
- function createFolder(path) {
178
- Fs__default.mkdirSync(path, { recursive: true });
179
- }
180
- function removeFolder(path) {
181
- const isDownstream = path.startsWith(Path.resolve());
182
- if (isDownstream) {
183
- Fs__default.rmSync(path, { recursive: true, force: true });
184
- }
185
- }
186
- function removeEntry(path) {
187
- if (Fs__default.existsSync(path)) {
188
- if (isFile(path)) {
189
- removeFile(path);
190
- } else {
191
- removeFolder(path);
192
- }
193
- }
194
- }
195
- function isFile(path) {
196
- return Fs__default.lstatSync(path).isFile();
197
- }
7
+ import { makeSourceManager } from '../dist/runtime/assets/source.js';
8
+ import { makeAssetsManager } from '../dist/runtime/assets/public.js';
9
+ import { rewriteContent } from '../dist/runtime/content/parsed.js';
198
10
 
199
11
  function createWebSocket() {
200
12
  const wss = new WebSocketServer({ noServer: true });
@@ -216,7 +28,7 @@ function createWebSocket() {
216
28
  let data;
217
29
  try {
218
30
  data = JSON.parse(event.data || "{}");
219
- } catch (err) {
31
+ } catch {
220
32
  }
221
33
  if (data) {
222
34
  handlers.forEach((callback) => callback(data));
@@ -296,258 +108,22 @@ async function setupSocketServer(channel, handler) {
296
108
  return this;
297
109
  }
298
110
  };
299
- if (handler) {
300
- instance.addHandler(handler);
301
- }
302
111
  return instance;
303
112
  }
304
113
 
305
- function isAssetId(id) {
306
- const path = toPath(id);
307
- return !isExcluded(path) && isAsset(path);
308
- }
309
- function makeSourceStorage(source, key = "") {
310
- const storage = createStorage();
311
- const options = typeof source === "string" ? { driver: "fs", base: source } : source;
312
- switch (options.driver) {
313
- case "fs":
314
- storage.mount(key, fsDriver({
315
- ...options,
316
- ignore: [
317
- "[^:]+?\\.md",
318
- "_dir\\.yml"
319
- ]
320
- }));
321
- break;
322
- case "github":
323
- storage.mount(key, githubDriver({
324
- branch: "main",
325
- dir: "/",
326
- ...options
327
- }));
328
- break;
329
- }
330
- return storage;
331
- }
332
- function makeSourceManager(key, source, publicPath, callback) {
333
- async function onWatch(event, key2) {
334
- if (isAssetId(key2)) {
335
- const path = event === "update" ? await copyItem(key2) : removeItem(key2);
336
- if (callback) {
337
- callback(event, path);
338
- }
339
- }
340
- }
341
- function getRelSrc(key2) {
342
- return toPath(key2).replace(/\w+/, "").replace(source.prefix || "", "");
343
- }
344
- function getAbsSrc(key2) {
345
- return Path.join(source.base, getRelSrc(key2));
346
- }
347
- function getRelTrg(key2) {
348
- return Path.join(source.prefix || "", toPath(deKey(key2)));
349
- }
350
- function getAbsTrg(key2) {
351
- return Path.join(publicPath, getRelTrg(key2));
352
- }
353
- function removeItem(key2) {
354
- const absTrg = getAbsTrg(key2);
355
- removeFile(absTrg);
356
- return absTrg;
357
- }
358
- async function copyItem(key2) {
359
- const absTrg = getAbsTrg(key2);
360
- const driver = source.driver;
361
- if (driver === "fs") {
362
- const absSrc = getAbsSrc(key2);
363
- copyFile(absSrc, absTrg);
364
- } else if (driver === "github") {
365
- try {
366
- const data = await storage.getItem(key2);
367
- if (data) {
368
- data?.constructor.name === "Blob" ? await writeBlob(absTrg, data) : writeFile(absTrg, data);
369
- } else {
370
- warn(`No data for key "${key2}"`);
371
- }
372
- } catch (err) {
373
- warn(err.message);
374
- }
375
- }
376
- return absTrg;
377
- }
378
- async function getKeys() {
379
- const keys = await storage.getKeys();
380
- return keys.filter(isAssetId);
381
- }
382
- async function init() {
383
- const keys = await getKeys();
384
- const paths = [];
385
- for (const key2 of keys) {
386
- const path = await copyItem(key2);
387
- paths.push(path);
388
- }
389
- return paths;
390
- }
391
- const storage = makeSourceStorage(source, key);
392
- void storage.watch(onWatch);
393
- async function dispose() {
394
- await storage.unwatch();
395
- await storage.dispose();
396
- }
397
- return {
398
- storage,
399
- init,
400
- keys: getKeys,
401
- dispose
402
- };
403
- }
404
-
405
- function makeAssetsManager(publicPath, shouldWatch = true) {
406
- const assetsKey = "assets.json";
407
- const assetsPath = Path.join(publicPath, "..");
408
- const storage = makeSourceStorage(assetsPath);
409
- if (shouldWatch) {
410
- void storage.watch(async (event, key) => {
411
- if (event === "update" && key === assetsKey) {
412
- await load();
413
- }
414
- });
415
- }
416
- const assets = {};
417
- async function load() {
418
- const data = await storage.getItem(assetsKey);
419
- Object.assign(assets, data || {});
420
- }
421
- const save = debounce(function() {
422
- void storage.setItem(assetsKey, assets);
423
- }, 50);
424
- function resolveAsset(content, relAsset, registerContent = false) {
425
- const srcDir = Path.dirname(content._file);
426
- const srcAsset = Path.join(srcDir, relAsset);
427
- const asset = assets[srcAsset];
428
- if (asset && registerContent) {
429
- const { _id } = content;
430
- if (!asset.content.includes(_id)) {
431
- asset.content.push(_id);
432
- save();
433
- }
434
- }
435
- return asset || {};
436
- }
437
- function setAsset(path) {
438
- const { srcRel, srcAttr } = getAssetPaths(publicPath, path);
439
- const { width, height } = getAssetSize(path);
440
- const oldAsset = assets[srcRel];
441
- const newAsset = {
442
- srcAttr,
443
- content: oldAsset?.content || [],
444
- width,
445
- height
446
- };
447
- assets[srcRel] = newAsset;
448
- save();
449
- return newAsset;
450
- }
451
- function getAsset(path) {
452
- const { srcRel } = getAssetPaths(publicPath, path);
453
- return srcRel ? { ...assets[srcRel] } : void 0;
454
- }
455
- function removeAsset(path) {
456
- const { srcRel } = getAssetPaths(publicPath, path);
457
- const asset = assets[srcRel];
458
- if (asset) {
459
- delete assets[srcRel];
460
- save();
461
- }
462
- return asset;
463
- }
464
- const init = () => {
465
- if (Fs.existsSync(publicPath)) {
466
- const names = Fs.readdirSync(publicPath);
467
- for (const name of names) {
468
- if (!/^\.git(ignore|keep)$/.test(name)) {
469
- removeEntry(Path.join(publicPath, name));
470
- }
471
- }
472
- }
473
- };
474
- void load();
475
- return {
476
- init,
477
- setAsset,
478
- getAsset,
479
- removeAsset,
480
- resolveAsset,
481
- dispose: async () => {
482
- await storage.unwatch();
483
- await storage.dispose();
484
- }
485
- };
486
- }
487
- function getAssetPaths(srcDir, srcAbs) {
488
- const srcRel = Path.relative(srcDir, srcAbs);
489
- const srcAttr = "/" + srcRel;
490
- return {
491
- srcRel,
492
- srcAttr
493
- };
494
- }
495
- function getAssetSize(srcAbs) {
496
- if (isImage(srcAbs)) {
497
- try {
498
- return getImageSize(srcAbs);
499
- } catch (err) {
500
- warn(`could not read image "${srcAbs}`);
501
- }
502
- }
503
- return {};
504
- }
505
-
506
- function rewriteContent(path, asset) {
507
- const { parsed } = readFile(path, true);
508
- const { srcAttr, width, height } = asset;
509
- walkMeta(parsed, (value, parent, key) => {
510
- if (value.startsWith(srcAttr)) {
511
- parent[key] = parent[key].replace(/width=\d+&height=\d+/, `width=${width}&height=${height}`);
512
- }
513
- });
514
- walkBody(parsed, function(node) {
515
- const { tag, props } = node;
516
- if (tag === "img" && props?.src?.startsWith(srcAttr)) {
517
- props.src = buildQuery(srcAttr, `time=${Date.now()}`);
518
- if (props.width) {
519
- props.width = width;
520
- }
521
- if (props.height) {
522
- props.height = height;
523
- }
524
- if (props.style) {
525
- const ratio = `${width}/${height}`;
526
- if (typeof props.style === "string") {
527
- props.style = props.style.replace(/aspect-ratio: \d+\/\d+/, `aspect-ratio: ${ratio}`);
528
- } else if (props.style.aspectRatio) {
529
- props.style.aspectRatio = ratio;
530
- }
531
- }
532
- }
533
- });
534
- writeFile(path, { module: true, parsed });
535
- return parsed;
536
- }
537
-
538
114
  const resolve = createResolver(import.meta.url).resolve;
539
115
  const meta = {
540
116
  name: "nuxt-content-assets",
541
117
  configKey: "contentAssets",
542
118
  compatibility: {
543
- nuxt: "^3.0.0"
119
+ nuxt: ">=3.0.0"
544
120
  }
545
121
  };
546
- const module = defineNuxtModule({
122
+ const module$1 = defineNuxtModule({
547
123
  meta,
548
124
  defaults: {
549
125
  imageSize: "",
550
- contentExtensions: "md csv ya?ml json",
126
+ contentExtensions: "mdx? csv ya?ml json",
551
127
  debug: false
552
128
  },
553
129
  async setup(options, nuxt) {
@@ -555,7 +131,7 @@ const module = defineNuxtModule({
555
131
  const modulesPath = nuxt.options.modulesDir.find((path) => Fs.existsSync(`${path}/nuxt-content-assets/cache`)) || "";
556
132
  if (!modulesPath) {
557
133
  warn("Unable to find cache folder!");
558
- if (nuxt.options.srcDir.endsWith("/playground")) {
134
+ if (nuxt.options.rootDir.endsWith("/playground")) {
559
135
  warn('Run "npm run dev:setup" to generate a new cache folder');
560
136
  }
561
137
  }
@@ -586,7 +162,7 @@ const module = defineNuxtModule({
586
162
  return output;
587
163
  }, {});
588
164
  if (Object.keys(sources).length === 0 || !sources.content) {
589
- const content = nuxt.options.srcDir + "/content";
165
+ const content = nuxt.options.rootDir + "/content";
590
166
  if (Fs.existsSync(content)) {
591
167
  sources.content = {
592
168
  driver: "fs",
@@ -672,4 +248,4 @@ const module = defineNuxtModule({
672
248
  }
673
249
  });
674
250
 
675
- export { module as default };
251
+ export { module$1 as default };
@@ -1,4 +1,4 @@
1
- import type { ParsedContent, AssetConfig } from '../../types';
1
+ import type { ParsedContent, AssetConfig } from '../../types.js';
2
2
  /**
3
3
  * Manages the public assets
4
4
  */
@@ -3,8 +3,8 @@ import Path from "crosspath";
3
3
  import getImageSize from "image-size";
4
4
  import debounce from "debounce";
5
5
  import { hash } from "ohash";
6
- import { makeSourceStorage } from "./source.mjs";
7
- import { isImage, warn, log, removeEntry } from "../utils/index.mjs";
6
+ import { makeSourceStorage } from "./source.js";
7
+ import { isImage, warn, log, removeEntry } from "../utils/index.js";
8
8
  export function makeAssetsManager(publicPath, shouldWatch = true) {
9
9
  const assetsKey = "assets.json";
10
10
  const assetsPath = Path.join(publicPath, "..");
@@ -53,7 +53,7 @@ export function makeAssetsManager(publicPath, shouldWatch = true) {
53
53
  }
54
54
  function getAsset(path) {
55
55
  const { srcRel } = getAssetPaths(publicPath, path);
56
- return srcRel ? { ...assets[srcRel] } : void 0;
56
+ return srcRel && assets[srcRel] ? { ...assets[srcRel] } : void 0;
57
57
  }
58
58
  function removeAsset(path) {
59
59
  const { srcRel } = getAssetPaths(publicPath, path);
@@ -122,7 +122,7 @@ export function getAssetSize(srcAbs) {
122
122
  if (isImage(srcAbs)) {
123
123
  try {
124
124
  return getImageSize(srcAbs);
125
- } catch (err) {
125
+ } catch {
126
126
  warn(`could not read image "${srcAbs}`);
127
127
  }
128
128
  }
@@ -2,7 +2,7 @@ import Path from "crosspath";
2
2
  import githubDriver from "unstorage/drivers/github";
3
3
  import fsDriver from "unstorage/drivers/fs";
4
4
  import { createStorage } from "unstorage";
5
- import { warn, isAsset, toPath, removeFile, copyFile, writeBlob, writeFile, deKey, isExcluded } from "../utils/index.mjs";
5
+ import { warn, isAsset, toPath, removeFile, copyFile, writeBlob, writeFile, deKey, isExcluded } from "../utils/index.js";
6
6
  function isAssetId(id) {
7
7
  const path = toPath(id);
8
8
  return !isExcluded(path) && isAsset(path);
@@ -1,4 +1,4 @@
1
- import type { AssetConfig, ParsedContent } from '../../types';
1
+ import type { AssetConfig, ParsedContent } from '../../types.js';
2
2
  /**
3
3
  * Rewrite cached content with updated image sizes
4
4
  */
@@ -1,4 +1,4 @@
1
- import { walkBody, walkMeta, buildQuery, readFile, writeFile } from "../utils/index.mjs";
1
+ import { walkBody, walkMeta, buildQuery, readFile, writeFile } from "../utils/index.js";
2
2
  export function rewriteContent(path, asset) {
3
3
  const { parsed } = readFile(path, true);
4
4
  const { srcAttr, width, height } = asset;
@@ -1,5 +1,5 @@
1
- import { buildQuery, buildStyle, isValidAsset, list, parseQuery, removeQuery, walkBody, walkMeta } from "../utils/index.mjs";
2
- import { makeAssetsManager } from "../assets/public.mjs";
1
+ import { buildQuery, buildStyle, isValidAsset, list, parseQuery, removeQuery, walkBody, walkMeta } from "../utils/index.js";
2
+ import { makeAssetsManager } from "../assets/public.js";
3
3
  import { debug, imageSizes, publicPath } from "#nuxt-content-assets";
4
4
  const plugin = async (nitro) => {
5
5
  function processMeta(content, imageSizes2 = [], updated = []) {
@@ -1,4 +1,4 @@
1
- import type { Callback } from '../../types';
1
+ import type { Callback } from '../../types.js';
2
2
  export interface Logger {
3
3
  log: (...args: any[]) => void;
4
4
  warn: (...args: any[]) => void;
@@ -29,7 +29,7 @@ export function createWebSocket(url, logger = { log, warn: log }) {
29
29
  let data;
30
30
  try {
31
31
  data = JSON.parse(message.data);
32
- } catch (err) {
32
+ } catch {
33
33
  logger.warn("Error parsing message:", message.data);
34
34
  return;
35
35
  }
@@ -55,7 +55,7 @@ export function createWebSocket(url, logger = { log, warn: log }) {
55
55
  if (ws) {
56
56
  try {
57
57
  ws.close();
58
- } catch (err) {
58
+ } catch {
59
59
  }
60
60
  ws = void 0;
61
61
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * Client-side plugin to support asset live-reload
3
3
  */
4
- declare const _default: any;
4
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
5
5
  export default _default;
@@ -2,7 +2,7 @@ import { defineNuxtPlugin, refreshNuxtData, useRuntimeConfig } from "#imports";
2
2
  export default defineNuxtPlugin(async () => {
3
3
  if (import.meta.client) {
4
4
  const url = useRuntimeConfig().public.sockets?.wsUrl;
5
- const socket = await import("./setup.mjs").then(({ setupSocketClient }) => {
5
+ const socket = await import("./setup.js").then(({ setupSocketClient }) => {
6
6
  return setupSocketClient(url, "content-assets");
7
7
  });
8
8
  if (socket) {
@@ -1,2 +1,2 @@
1
- import type { Callback, SocketInstance } from '../../types';
1
+ import type { Callback, SocketInstance } from '../../types.js';
2
2
  export declare function setupSocketClient(url: string, channel: string, callback?: Callback): SocketInstance | null;
@@ -1,4 +1,4 @@
1
- import { createWebSocket } from "./factory.mjs";
1
+ import { createWebSocket } from "./factory.js";
2
2
  let client;
3
3
  const plugin = "[Content Assets]";
4
4
  const logger = {
@@ -5,4 +5,4 @@ export declare function buildStyle(...expr: string[]): string;
5
5
  /**
6
6
  * Build a query string by passing multiple independent expressions
7
7
  */
8
- export declare function buildQuery(...expr: string[]): string;
8
+ export declare function buildQuery(...expr: string[]): string | undefined;
@@ -3,6 +3,7 @@
3
3
  */
4
4
  export declare const extensions: {
5
5
  image: string[];
6
+ content: string[];
6
7
  media: string[];
7
8
  };
8
9
  /**
@@ -1,7 +1,9 @@
1
- import { matchTokens } from "./string.mjs";
1
+ import { matchTokens } from "./string.js";
2
2
  export const extensions = {
3
3
  // used to get image size
4
4
  image: matchTokens("png jpg jpeg gif svg webp ico"),
5
+ // used to recognise content
6
+ content: matchTokens("md mdx json yml yaml csv"),
5
7
  // unused for now
6
8
  media: matchTokens("mp3 m4a wav mp4 mov webm ogg avi flv avchd")
7
9
  };
@@ -1,5 +1,5 @@
1
- import type { ParsedContent } from '../../types';
2
- import { type WalkCallback } from './object';
1
+ import type { ParsedContent } from '../../types.js';
2
+ import { type WalkCallback } from './object.js';
3
3
  /**
4
4
  * Walk parsed content meta, only processing relevant properties
5
5
  *
@@ -1,6 +1,6 @@
1
1
  import { CONTINUE, SKIP, visit } from "unist-util-visit";
2
- import { walk } from "./object.mjs";
3
- import { matchTokens } from "./string.mjs";
2
+ import { walk } from "./object.js";
3
+ import { matchTokens } from "./string.js";
4
4
  export function walkMeta(content, callback) {
5
5
  walk(content, callback, (value, key) => !(String(key).startsWith("_") || key === "body"));
6
6
  }
@@ -6,4 +6,4 @@ export declare function removeFile(src: string): void;
6
6
  export declare function createFolder(path: string): void;
7
7
  export declare function removeFolder(path: string): void;
8
8
  export declare function removeEntry(path: string): void;
9
- export declare function isFile(path: string): any;
9
+ export declare function isFile(path: string): boolean;
@@ -1,8 +1,8 @@
1
- export * from './path';
2
- export * from './content';
3
- export * from './config';
4
- export * from './debug';
5
- export * from './build';
6
- export * from './fs';
7
- export * from './string';
8
- export * from './object';
1
+ export * from './path.js';
2
+ export * from './content.js';
3
+ export * from './config.js';
4
+ export * from './debug.js';
5
+ export * from './build.js';
6
+ export * from './fs.js';
7
+ export * from './string.js';
8
+ export * from './object.js';
@@ -0,0 +1,8 @@
1
+ export * from "./path.js";
2
+ export * from "./content.js";
3
+ export * from "./config.js";
4
+ export * from "./debug.js";
5
+ export * from "./build.js";
6
+ export * from "./fs.js";
7
+ export * from "./string.js";
8
+ export * from "./object.js";
@@ -6,6 +6,11 @@ export declare function parseQuery(path: string): string;
6
6
  * Removes the query string from a path
7
7
  */
8
8
  export declare function removeQuery(path: string): string;
9
+ /**
10
+ * Gets the extension of a path
11
+ * @param path
12
+ */
13
+ export declare function getExt(path: string): string;
9
14
  /**
10
15
  * Test path to be relative
11
16
  */
@@ -20,7 +25,7 @@ export declare function isExcluded(path: string): boolean;
20
25
  */
21
26
  export declare function isImage(path: string): boolean;
22
27
  /**
23
- * Test path is markdown
28
+ * Test path is markdown or data
24
29
  */
25
30
  export declare function isArticle(path: string): boolean;
26
31
  /**
@@ -1,5 +1,5 @@
1
1
  import Path from "crosspath";
2
- import { extensions } from "./config.mjs";
2
+ import { extensions } from "./config.js";
3
3
  export function parseQuery(path) {
4
4
  const matches = path.match(/\?.+$/);
5
5
  return matches ? matches[0] : "";
@@ -7,6 +7,9 @@ export function parseQuery(path) {
7
7
  export function removeQuery(path) {
8
8
  return path.replace(/\?.*$/, "");
9
9
  }
10
+ export function getExt(path) {
11
+ return Path.extname(removeQuery(path)).substring(1);
12
+ }
10
13
  export function isRelative(path) {
11
14
  return !(path.startsWith("http") || Path.isAbsolute(path));
12
15
  }
@@ -14,11 +17,10 @@ export function isExcluded(path) {
14
17
  return path.split("/").some((segment) => segment.startsWith(".") || segment.startsWith("_"));
15
18
  }
16
19
  export function isImage(path) {
17
- const ext = Path.extname(path).substring(1);
18
- return extensions.image.includes(ext);
20
+ return extensions.image.includes(getExt(path));
19
21
  }
20
22
  export function isArticle(path) {
21
- return removeQuery(path).endsWith(".md");
23
+ return extensions.content.includes(getExt(path));
22
24
  }
23
25
  export function isAsset(path) {
24
26
  return !isArticle(path);
@@ -5,5 +5,5 @@
5
5
  */
6
6
  export declare function matchTokens(value: any): string[];
7
7
  export declare function toPath(key: string): string;
8
- export declare function toKey(path: string): any;
8
+ export declare function toKey(path: string): string;
9
9
  export declare function deKey(path: string): string;
package/dist/types.d.mts CHANGED
@@ -1,8 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
1
2
 
2
- import type { } from './module.js'
3
+ import type { default as Module } from './module.mjs'
3
4
 
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
4
6
 
5
-
6
-
7
-
8
- export type { default } from './module.js'
7
+ export { default } from './module.mjs'
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "nuxt-content-assets",
3
- "version": "1.4.3",
3
+ "version": "1.5.1",
4
4
  "description": "Enable locally-located assets in Nuxt Content",
5
- "repository": "davestewart/nuxt-content-assets",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/davestewart/nuxt-content-assets.git"
8
+ },
6
9
  "license": "MIT",
7
10
  "type": "module",
8
11
  "exports": {
9
12
  ".": {
10
- "types": "./dist/types.d.ts",
11
- "import": "./dist/module.mjs",
12
- "require": "./dist/module.cjs"
13
+ "types": "./dist/types.d.mts",
14
+ "import": "./dist/module.mjs"
13
15
  }
14
16
  },
15
- "main": "./dist/module.cjs",
16
- "types": "./dist/types.d.ts",
17
+ "main": "./dist/module.mjs",
17
18
  "files": [
18
19
  "cache",
19
20
  "dist"
@@ -37,33 +38,32 @@
37
38
  "test:watch": "vitest watch"
38
39
  },
39
40
  "dependencies": {
40
- "@nuxt/kit": "^3.11.2",
41
+ "@nuxt/kit": "^3.20.2",
41
42
  "crosspath": "^2.0.0",
42
- "debounce": "^1.2.1",
43
- "image-size": "^1.0.2",
44
- "listhen": "^1.7.2",
45
- "ohash": "^1.0.0",
46
- "unist-util-visit": "^4.1.2",
47
- "unstorage": "^1.4.1",
48
- "ws": "^8.13.0"
43
+ "debounce": "^3.0.0",
44
+ "image-size": "^1.1.1",
45
+ "listhen": "^1.9.0",
46
+ "ohash": "^2.0.11",
47
+ "unist-util-visit": "^5.0.0",
48
+ "unstorage": "^1.17.3",
49
+ "ws": "^8.19.0"
49
50
  },
50
51
  "peerDependencies": {
51
- "@nuxt/content": "^2.0.0"
52
+ "@nuxt/content": "^2.13.0"
52
53
  },
53
54
  "devDependencies": {
54
- "@nuxt/devtools": "latest",
55
- "@nuxt/eslint-config": "^0.2.0",
56
- "@nuxt/module-builder": "^0.5.5",
57
- "@nuxt/schema": "^3.11.2",
58
- "@nuxt/test-utils": "^3.12.0",
59
- "@types/debounce": "^1.2.1",
60
- "@types/node": "^20.12.4",
61
- "@types/ws": "^8.5.10",
62
- "changelogen": "^0.5.5",
63
- "cpy-cli": "^5.0.0",
64
- "eslint": "^8.57.0",
65
- "nuxt": "^3.11.2",
66
- "vitest": "^1.4.0"
55
+ "@nuxt/devtools": "^1.7.0",
56
+ "@nuxt/eslint-config": "^0.7.6",
57
+ "@nuxt/module-builder": "^1.0.2",
58
+ "@nuxt/schema": "^3.20.2",
59
+ "@nuxt/test-utils": "^3.23.0",
60
+ "@types/debounce": "^1.2.4",
61
+ "@types/node": "^25.0.3",
62
+ "@types/ws": "^8.18.1",
63
+ "cpy-cli": "^6.0.0",
64
+ "eslint": "^8.39.2",
65
+ "nuxt": "^3.20.2",
66
+ "vitest": "^3.2.4"
67
67
  },
68
68
  "engines": {
69
69
  "node": ">=16.0.0"
package/dist/module.cjs DELETED
@@ -1,5 +0,0 @@
1
- module.exports = function(...args) {
2
- return import('./module.mjs').then(m => m.default.call(this, ...args))
3
- }
4
- const _meta = module.exports.meta = require('./module.json')
5
- module.exports.getMeta = () => Promise.resolve(_meta)
package/dist/module.d.ts DELETED
@@ -1,29 +0,0 @@
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 };
@@ -1,8 +0,0 @@
1
- export * from "./path.mjs";
2
- export * from "./content.mjs";
3
- export * from "./config.mjs";
4
- export * from "./debug.mjs";
5
- export * from "./build.mjs";
6
- export * from "./fs.mjs";
7
- export * from "./string.mjs";
8
- export * from "./object.mjs";
package/dist/types.d.ts DELETED
@@ -1,8 +0,0 @@
1
-
2
- import type { } from './module'
3
-
4
-
5
-
6
-
7
-
8
- export type { default } from './module'
File without changes
File without changes
File without changes
File without changes
File without changes