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 +29 -0
- package/dist/module.d.ts +2 -1
- package/dist/module.json +3 -4
- package/dist/module.mjs +11 -12
- package/dist/runtime/content/plugin.mjs +11 -11
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
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
package/dist/module.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
2
|
+
"name": "nuxt-content-assets",
|
|
3
|
+
"configKey": "contentAssets",
|
|
4
4
|
"compatibility": {
|
|
5
5
|
"nuxt": "^3.0.0"
|
|
6
6
|
},
|
|
7
|
-
"
|
|
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
|
-
|
|
507
|
-
|
|
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
|
|
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) &&
|
|
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("
|
|
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.
|
|
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,
|
|
4
|
-
function processMeta(content,
|
|
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 && (
|
|
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,
|
|
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 (
|
|
30
|
-
node.props.width
|
|
31
|
-
node.props.height
|
|
29
|
+
if (imageSizes2.includes("attrs")) {
|
|
30
|
+
node.props.width = width;
|
|
31
|
+
node.props.height = height;
|
|
32
32
|
}
|
|
33
|
-
if (
|
|
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,
|
|
57
|
-
processBody(content,
|
|
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