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 +1 -1
- package/dist/runtime/plugin.mjs +22 -18
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -16,7 +16,7 @@ let assets = {};
|
|
|
16
16
|
void updateAssets();
|
|
17
17
|
const tags = {
|
|
18
18
|
// unlikely to contain assets
|
|
19
|
-
|
|
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
|
-
|
|
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
|
|
64
|
-
if (
|
|
63
|
+
const excluded = tags.exclude.includes(tag);
|
|
64
|
+
if (excluded) {
|
|
65
65
|
return SKIP;
|
|
66
66
|
}
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
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 (
|
|
83
|
-
|
|
84
|
-
|
|
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 (
|
|
87
|
-
node.props.
|
|
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
|
});
|