nuxt-content-assets 1.2.1 → 1.3.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.
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.1"
8
8
  }
package/dist/module.mjs CHANGED
@@ -41,9 +41,8 @@ const extensions = {
41
41
  media: matchTokens("mp3 m4a wav mp4 mov webm ogg avi flv avchd")
42
42
  };
43
43
  function makeIgnores(extensions2) {
44
- const matched = matchTokens(extensions2);
45
- const ignored = matched.join("|");
46
- return `[^:]+\\.(?!(${ignored})$)`;
44
+ const included = matchTokens(extensions2).join("|");
45
+ return `^(?:(?!(${included})).)+$`;
47
46
  }
48
47
 
49
48
  function removeQuery(path) {
@@ -536,7 +535,7 @@ const module = defineNuxtModule({
536
535
  const ignores = makeIgnores(contentExtensions);
537
536
  nuxt.options.content?.ignores.push(ignores);
538
537
  }
539
- const imageFlags = matchTokens(options.imageSize);
538
+ const imageSizes = matchTokens(options.imageSize);
540
539
  const sources = Array.from(nuxt.options._layers).map((layer) => layer.config?.content?.sources).reduce((output, sources2) => {
541
540
  if (sources2) {
542
541
  Object.assign(output, sources2);
@@ -558,7 +557,7 @@ const module = defineNuxtModule({
558
557
  let width;
559
558
  let height;
560
559
  if (event === "update") {
561
- const oldAsset = isImage(absTrg) && imageFlags.length ? assets.getAsset(absTrg) : null;
560
+ const oldAsset = isImage(absTrg) && imageSizes.length ? assets.getAsset(absTrg) : null;
562
561
  const newAsset = assets.setAsset(absTrg);
563
562
  width = newAsset.width;
564
563
  height = newAsset.height;
@@ -603,7 +602,7 @@ const module = defineNuxtModule({
603
602
  const makeVar = (name, value) => `export const ${name} = ${JSON.stringify(value)};`;
604
603
  const virtualConfig = [
605
604
  makeVar("publicPath", publicPath),
606
- makeVar("imageFlags", imageFlags),
605
+ makeVar("imageSizes", imageSizes),
607
606
  makeVar("debug", options.debug)
608
607
  ].join("\n");
609
608
  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();
@@ -7,5 +7,8 @@ export declare const extensions: {
7
7
  };
8
8
  /**
9
9
  * Create a Nuxt Content ignore string
10
+ *
11
+ * @see https://stackoverflow.com/questions/10052032/regex-pattern-that-does-not-match-certain-extensions
12
+ * @see https://regex101.com/r/gC3HXz/1
10
13
  */
11
14
  export declare function makeIgnores(extensions: string | string[]): string;
@@ -6,7 +6,6 @@ export const extensions = {
6
6
  media: matchTokens("mp3 m4a wav mp4 mov webm ogg avi flv avchd")
7
7
  };
8
8
  export function makeIgnores(extensions2) {
9
- const matched = matchTokens(extensions2);
10
- const ignored = matched.join("|");
11
- return `[^:]+\\.(?!(${ignored})$)`;
9
+ const included = matchTokens(extensions2).join("|");
10
+ return `^(?:(?!(${included})).)+$`;
12
11
  }
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.1",
4
4
  "description": "Enable locally-located assets in Nuxt Content",
5
5
  "repository": "davestewart/nuxt-content-assets",
6
6
  "license": "MIT",