nuxt-content-assets 1.2.0 → 1.3.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 CHANGED
@@ -203,6 +203,35 @@ The component will receive the size information as a query string which you can
203
203
 
204
204
  See demo component [here](demo/components/content/ContentImage.vue).
205
205
 
206
+ ### Nuxt Image compatibility
207
+
208
+ Nuxt Content Assets works with [Nuxt Image](https://v1.image.nuxtjs.org/) with just a little configuration.
209
+
210
+ First, configure Nuxt Image to use Nuxt Content Asset's public folder:
211
+
212
+ ```ts
213
+ // nuxt.config.ts
214
+ export default defineNuxtConfig({
215
+ image: {
216
+ dir: '.nuxt/content-assets/public'
217
+ }
218
+ }
219
+ ```
220
+
221
+ Then, create a `ProseImg` component like so:
222
+
223
+ ```vue
224
+ <!-- components/content/ProseImg.vue -->
225
+ <template>
226
+ <nuxt-img />
227
+ </template>
228
+ ```
229
+
230
+ Any images rendered by Nuxt Content will now use Nuxt Image.
231
+
232
+ > For a per-image solution, check the [override](demo/components/content/NuxtImg.ts) in the demo folder.
233
+
234
+
206
235
  ## Configuration
207
236
 
208
237
  The module has the following options:
package/dist/module.d.ts CHANGED
@@ -23,6 +23,7 @@ interface ModuleOptions {
23
23
  */
24
24
  debug?: boolean;
25
25
  }
26
+
26
27
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
27
28
 
28
- export { ModuleOptions, _default as default };
29
+ export { _default as default };
package/dist/module.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
- "moduleName": "nuxt-content-assets",
3
- "moduleKey": "contentAssets",
2
+ "name": "nuxt-content-assets",
3
+ "configKey": "contentAssets",
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "name": "nuxt-content-assets",
8
- "version": "1.2.0"
7
+ "version": "1.3.0"
9
8
  }
package/dist/module.mjs CHANGED
@@ -503,20 +503,19 @@ function rewriteContent(path, asset) {
503
503
 
504
504
  const resolve = createResolver(import.meta.url).resolve;
505
505
  const meta = {
506
- moduleName: "nuxt-content-assets",
507
- moduleKey: "contentAssets",
506
+ name: "nuxt-content-assets",
507
+ configKey: "contentAssets",
508
508
  compatibility: {
509
509
  nuxt: "^3.0.0"
510
510
  }
511
511
  };
512
- const defaults = {
513
- imageSize: "style",
514
- contentExtensions: "md csv ya?ml json",
515
- debug: false
516
- };
517
512
  const module = defineNuxtModule({
518
513
  meta,
519
- defaults,
514
+ defaults: {
515
+ imageSize: "style",
516
+ contentExtensions: "md csv ya?ml json",
517
+ debug: false
518
+ },
520
519
  async setup(options, nuxt) {
521
520
  var _a, _b;
522
521
  const buildPath = nuxt.options.buildDir;
@@ -537,7 +536,7 @@ const module = defineNuxtModule({
537
536
  const ignores = makeIgnores(contentExtensions);
538
537
  nuxt.options.content?.ignores.push(ignores);
539
538
  }
540
- const imageFlags = matchTokens(options.imageSize);
539
+ const imageSizes = matchTokens(options.imageSize);
541
540
  const sources = Array.from(nuxt.options._layers).map((layer) => layer.config?.content?.sources).reduce((output, sources2) => {
542
541
  if (sources2) {
543
542
  Object.assign(output, sources2);
@@ -559,7 +558,7 @@ const module = defineNuxtModule({
559
558
  let width;
560
559
  let height;
561
560
  if (event === "update") {
562
- const oldAsset = isImage(absTrg) && imageFlags.length ? assets.getAsset(absTrg) : null;
561
+ const oldAsset = isImage(absTrg) && imageSizes.length ? assets.getAsset(absTrg) : null;
563
562
  const newAsset = assets.setAsset(absTrg);
564
563
  width = newAsset.width;
565
564
  height = newAsset.height;
@@ -604,14 +603,14 @@ const module = defineNuxtModule({
604
603
  const makeVar = (name, value) => `export const ${name} = ${JSON.stringify(value)};`;
605
604
  const virtualConfig = [
606
605
  makeVar("publicPath", publicPath),
607
- makeVar("imageFlags", imageFlags),
606
+ makeVar("imageSizes", imageSizes),
608
607
  makeVar("debug", options.debug)
609
608
  ].join("\n");
610
609
  nuxt.hook("nitro:config", async (config) => {
611
610
  config.plugins || (config.plugins = []);
612
611
  config.plugins.push(pluginPath);
613
612
  config.virtual || (config.virtual = {});
614
- config.virtual[`#${meta.moduleName}`] = () => {
613
+ config.virtual[`#${meta.name}`] = () => {
615
614
  return virtualConfig;
616
615
  };
617
616
  config.publicAssets || (config.publicAssets = []);
@@ -1,12 +1,12 @@
1
1
  import { buildQuery, buildStyle, isValidAsset, list, parseQuery, removeQuery, walkBody, walkMeta } from "../utils/index.mjs";
2
2
  import { makeAssetsManager } from "../assets/public.mjs";
3
- import { debug, imageFlags, publicPath } from "#nuxt-content-assets";
4
- function processMeta(content, imageFlags2 = [], updated = []) {
3
+ import { debug, imageSizes, publicPath } from "#nuxt-content-assets";
4
+ function processMeta(content, imageSizes2 = [], updated = []) {
5
5
  walkMeta(content, (value, parent, key) => {
6
6
  if (isValidAsset(value)) {
7
7
  const { srcAttr, width, height } = resolveAsset(content, removeQuery(value), true);
8
8
  if (srcAttr) {
9
- const query = width && height && (imageFlags2.includes("src") || imageFlags2.includes("url")) ? `width=${width}&height=${height}` : "";
9
+ const query = width && height && (imageSizes2.includes("src") || imageSizes2.includes("url")) ? `width=${width}&height=${height}` : "";
10
10
  const srcUrl = query ? buildQuery(srcAttr, parseQuery(value), query) : srcAttr;
11
11
  parent[key] = srcUrl;
12
12
  updated.push(`meta: ${key} to "${srcUrl}"`);
@@ -14,7 +14,7 @@ function processMeta(content, imageFlags2 = [], updated = []) {
14
14
  }
15
15
  });
16
16
  }
17
- function processBody(content, imageFlags2 = [], updated = []) {
17
+ function processBody(content, imageSizes2 = [], updated = []) {
18
18
  walkBody(content, function(node) {
19
19
  const { tag, props } = node;
20
20
  for (const [prop, value] of Object.entries(props)) {
@@ -24,13 +24,13 @@ function processBody(content, imageFlags2 = [], updated = []) {
24
24
  const { srcAttr, width, height } = resolveAsset(content, value, true);
25
25
  if (srcAttr) {
26
26
  node.props[prop] = srcAttr;
27
- if (node.tag === "img") {
27
+ if (node.tag === "img" || node.tag === "nuxt-img") {
28
28
  if (width && height) {
29
- if (imageFlags2.includes("attrs")) {
30
- node.props.width ||= width;
31
- node.props.height ||= height;
29
+ if (imageSizes2.includes("attrs")) {
30
+ node.props.width = width;
31
+ node.props.height = height;
32
32
  }
33
- if (imageFlags2.includes("style")) {
33
+ if (imageSizes2.includes("style")) {
34
34
  const ratio = `${width}/${height}`;
35
35
  if (typeof node.props.style === "string") {
36
36
  node.props.style = buildStyle(node.props.style, `aspect-ratio: ${ratio}`);
@@ -53,8 +53,8 @@ const plugin = async (nitro) => {
53
53
  nitro.hooks.hook("content:file:afterParse", function(content) {
54
54
  if (content._extension === "md") {
55
55
  const updated = [];
56
- processMeta(content, imageFlags, updated);
57
- processBody(content, imageFlags, updated);
56
+ processMeta(content, imageSizes, updated);
57
+ processBody(content, imageSizes, updated);
58
58
  if (debug && updated.length) {
59
59
  list(`Processed "/${content._file}"`, updated);
60
60
  console.log();
package/dist/types.d.ts CHANGED
@@ -3,4 +3,4 @@ import { } from './module'
3
3
 
4
4
 
5
5
 
6
- export { ModuleOptions, default } from './module'
6
+ export { default } from './module'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-content-assets",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Enable locally-located assets in Nuxt Content",
5
5
  "repository": "davestewart/nuxt-content-assets",
6
6
  "license": "MIT",