nuxt-content-assets 0.10.2 → 0.10.3

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/dist/module.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.10.2"
7
+ "version": "0.10.3"
8
8
  }
@@ -16,7 +16,7 @@ let assets = {};
16
16
  void updateAssets();
17
17
  const tags = {
18
18
  // unlikely to contain assets
19
- content: matchTokens({
19
+ exclude: matchTokens({
20
20
  container: "pre code code-inline",
21
21
  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",
22
22
  headers: "h1 h2 h3 h4 h5 h6",
@@ -26,7 +26,7 @@ const tags = {
26
26
  empty: "hr br"
27
27
  }),
28
28
  // may contain assets
29
- props: matchTokens({
29
+ include: matchTokens({
30
30
  content: "main header footer section article aside details dialog summary data object nav blockquote div span p",
31
31
  table: "table caption th tr td thead tbody tfoot col colgroup",
32
32
  media: "figcaption figure picture",
@@ -60,15 +60,12 @@ const plugin = async (nitro) => {
60
60
  }, filter);
61
61
  visit(file.body, (node) => node.type === "element", (node) => {
62
62
  const { tag, props } = node;
63
- const noContent = tags.content.includes(tag);
64
- if (noContent) {
63
+ const excluded = tags.exclude.includes(tag);
64
+ if (excluded) {
65
65
  return SKIP;
66
66
  }
67
- const noProps = tags.props.includes(tag);
68
- if (noProps) {
69
- return CONTINUE;
70
- }
71
- if (!props) {
67
+ const included = tags.include.includes(tag);
68
+ if (included || !props) {
72
69
  return CONTINUE;
73
70
  }
74
71
  for (const [prop, value] of Object.entries(props)) {
@@ -77,18 +74,25 @@ const plugin = async (nitro) => {
77
74
  }
78
75
  const { srcAttr, width, height, ratio } = getAsset(value);
79
76
  if (srcAttr) {
80
- updated.push(`page: ${tag}[${prop}] to "${srcAttr}"`);
81
77
  node.props[prop] = srcAttr;
82
- if (width && height) {
83
- node.props.width = width;
84
- node.props.height = height;
78
+ if (node.tag === "img") {
79
+ if (width && height) {
80
+ node.props.width ||= width;
81
+ node.props.height ||= height;
82
+ }
83
+ if (ratio) {
84
+ if (typeof node.props.style === "string") {
85
+ node.props.style += `; aspect-ratio: ${ratio};`;
86
+ } else {
87
+ node.props.style ||= {};
88
+ node.props.style.aspectRatio = ratio;
89
+ }
90
+ }
85
91
  }
86
- if (ratio) {
87
- node.props.style = `aspect-ratio:${ratio}`;
88
- }
89
- if (node.tag === "a" && !node.props.target) {
90
- node.props.target = "_blank";
92
+ if (node.tag === "a") {
93
+ node.props.target ||= "_blank";
91
94
  }
95
+ updated.push(`page: ${tag}[${prop}] to "${srcAttr}"`);
92
96
  }
93
97
  }
94
98
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-content-assets",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "Enable locally-located assets in Nuxt Content",
5
5
  "repository": "davestewart/nuxt-content-assets",
6
6
  "license": "MIT",