nuxt-content-assets 1.2.1 → 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.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "1.2.1"
7
+ "version": "1.3.0"
8
8
  }
package/dist/module.mjs CHANGED
@@ -536,7 +536,7 @@ const module = defineNuxtModule({
536
536
  const ignores = makeIgnores(contentExtensions);
537
537
  nuxt.options.content?.ignores.push(ignores);
538
538
  }
539
- const imageFlags = matchTokens(options.imageSize);
539
+ const imageSizes = matchTokens(options.imageSize);
540
540
  const sources = Array.from(nuxt.options._layers).map((layer) => layer.config?.content?.sources).reduce((output, sources2) => {
541
541
  if (sources2) {
542
542
  Object.assign(output, sources2);
@@ -558,7 +558,7 @@ const module = defineNuxtModule({
558
558
  let width;
559
559
  let height;
560
560
  if (event === "update") {
561
- const oldAsset = isImage(absTrg) && imageFlags.length ? assets.getAsset(absTrg) : null;
561
+ const oldAsset = isImage(absTrg) && imageSizes.length ? assets.getAsset(absTrg) : null;
562
562
  const newAsset = assets.setAsset(absTrg);
563
563
  width = newAsset.width;
564
564
  height = newAsset.height;
@@ -603,7 +603,7 @@ const module = defineNuxtModule({
603
603
  const makeVar = (name, value) => `export const ${name} = ${JSON.stringify(value)};`;
604
604
  const virtualConfig = [
605
605
  makeVar("publicPath", publicPath),
606
- makeVar("imageFlags", imageFlags),
606
+ makeVar("imageSizes", imageSizes),
607
607
  makeVar("debug", options.debug)
608
608
  ].join("\n");
609
609
  nuxt.hook("nitro:config", async (config) => {
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-content-assets",
3
- "version": "1.2.1",
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",