nuxt-content-assets 1.7.0 → 1.8.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 +3 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +4 -2
- package/dist/runtime/assets/public.d.ts +1 -1
- package/dist/runtime/assets/public.js +2 -2
- package/dist/runtime/assets/source.d.ts +1 -1
- package/dist/runtime/assets/source.js +13 -2
- package/dist/runtime/utils/config.d.ts +1 -2
- package/dist/runtime/utils/config.js +6 -2
- package/dist/runtime/utils/path.d.ts +4 -0
- package/dist/runtime/utils/path.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -215,7 +215,7 @@ See playground component [here](playground/components/content/ContentImage.vue).
|
|
|
215
215
|
|
|
216
216
|
### Nuxt Image
|
|
217
217
|
|
|
218
|
-
[Nuxt Image](https://image.nuxtjs.org/)
|
|
218
|
+
To support [Nuxt Image](https://image.nuxtjs.org/), add Nuxt Content Asset's cache folder as a Nuxt Layer:
|
|
219
219
|
|
|
220
220
|
```ts
|
|
221
221
|
// nuxt.config.ts
|
|
@@ -291,7 +291,7 @@ img {
|
|
|
291
291
|
### Content extensions
|
|
292
292
|
|
|
293
293
|
> [!NOTE]
|
|
294
|
-
> Generally, you shouldn't need to touch this setting
|
|
294
|
+
> Generally, you shouldn't need to touch this setting, however, if you're looking to support custom content types [by way of transformers](https://v2.content.nuxt.com/recipes/transformers) then you'll need to add those extensions here.
|
|
295
295
|
|
|
296
296
|
This setting tells Nuxt Content to ignore anything that is **not** one of the supported content types:
|
|
297
297
|
|
|
@@ -317,7 +317,7 @@ If you want to see what the module does as it runs, set `debug` to true:
|
|
|
317
317
|
|
|
318
318
|
## How it works
|
|
319
319
|
|
|
320
|
-
When Nuxt builds, the module scans all content sources for assets, copies them to a temporary layer folder (`
|
|
320
|
+
When Nuxt builds, the module scans all content sources for assets, copies them to a temporary layer folder (`node_modules/nuxt-content-assets/cache`), and indexes path and image metadata.
|
|
321
321
|
|
|
322
322
|
After Nuxt Content has run, the parsed content (`.nuxt/content-cache`) is traversed, and both element attributes and frontmatter properties are checked to see if they resolve to the previously-indexed asset paths.
|
|
323
323
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -152,7 +152,9 @@ const module$1 = defineNuxtModule({
|
|
|
152
152
|
nuxt.options.content.ignores ||= [];
|
|
153
153
|
}
|
|
154
154
|
const ignores = makeIgnores(contentExtensions);
|
|
155
|
-
|
|
155
|
+
if (ignores.length) {
|
|
156
|
+
nuxt.options.content?.ignores.push(ignores);
|
|
157
|
+
}
|
|
156
158
|
}
|
|
157
159
|
const imageSizes = matchTokens(options.imageSize);
|
|
158
160
|
const sources = Array.from(nuxt.options._layers).map((layer) => layer.config?.content?.sources).reduce((output, sources2) => {
|
|
@@ -221,7 +223,7 @@ const module$1 = defineNuxtModule({
|
|
|
221
223
|
nuxt.hook("close", async () => {
|
|
222
224
|
await assets.dispose();
|
|
223
225
|
for (const key in managers) {
|
|
224
|
-
await managers[key]
|
|
226
|
+
await managers[key]?.dispose();
|
|
225
227
|
}
|
|
226
228
|
});
|
|
227
229
|
const pluginPath = resolve("./runtime/content/plugin");
|
|
@@ -4,7 +4,7 @@ import getImageSize from "image-size";
|
|
|
4
4
|
import debounce from "debounce";
|
|
5
5
|
import { hash } from "ohash";
|
|
6
6
|
import { makeSourceStorage } from "./source.js";
|
|
7
|
-
import { isImage,
|
|
7
|
+
import { isImage, log, removeEntry, removeOrdering, removeQuery, warn } from "../utils/index.js";
|
|
8
8
|
export function makeAssetsManager(publicPath, shouldWatch = true) {
|
|
9
9
|
const assetsKey = "assets.json";
|
|
10
10
|
const assetsPath = Path.join(publicPath, "..");
|
|
@@ -27,7 +27,7 @@ export function makeAssetsManager(publicPath, shouldWatch = true) {
|
|
|
27
27
|
function resolveAsset(content, relAsset, registerContent = false) {
|
|
28
28
|
const srcDir = Path.dirname(content._file);
|
|
29
29
|
const relAssetNoQuery = removeQuery(relAsset);
|
|
30
|
-
const srcAsset = Path.join(srcDir, relAssetNoQuery);
|
|
30
|
+
const srcAsset = removeOrdering(Path.join(srcDir, relAssetNoQuery));
|
|
31
31
|
const asset = assets[srcAsset];
|
|
32
32
|
if (asset && registerContent) {
|
|
33
33
|
const { _id } = content;
|
|
@@ -2,7 +2,18 @@ import Path from "crosspath";
|
|
|
2
2
|
import githubDriver from "unstorage/drivers/github";
|
|
3
3
|
import fsDriver from "unstorage/drivers/fs";
|
|
4
4
|
import { createStorage } from "unstorage";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
copyFile,
|
|
7
|
+
deKey,
|
|
8
|
+
isAsset,
|
|
9
|
+
isExcluded,
|
|
10
|
+
removeFile,
|
|
11
|
+
removeOrdering,
|
|
12
|
+
toPath,
|
|
13
|
+
warn,
|
|
14
|
+
writeBlob,
|
|
15
|
+
writeFile
|
|
16
|
+
} from "../utils/index.js";
|
|
6
17
|
function isAssetId(id) {
|
|
7
18
|
const path = toPath(id);
|
|
8
19
|
return !isExcluded(path) && isAsset(path);
|
|
@@ -46,7 +57,7 @@ export function makeSourceManager(key, source, publicPath, callback) {
|
|
|
46
57
|
return Path.join(source.base, getRelSrc(key2));
|
|
47
58
|
}
|
|
48
59
|
function getRelTrg(key2) {
|
|
49
|
-
return Path.join(source.prefix || "", toPath(deKey(key2)));
|
|
60
|
+
return Path.join(source.prefix || "", removeOrdering(toPath(deKey(key2))));
|
|
50
61
|
}
|
|
51
62
|
function getAbsTrg(key2) {
|
|
52
63
|
return Path.join(publicPath, getRelTrg(key2));
|
|
@@ -9,7 +9,6 @@ export declare const extensions: {
|
|
|
9
9
|
/**
|
|
10
10
|
* Create a Nuxt Content ignore string
|
|
11
11
|
*
|
|
12
|
-
* @see https://
|
|
13
|
-
* @see https://regex101.com/r/gC3HXz/1
|
|
12
|
+
* @see https://regex101.com/r/gC3HXz/2
|
|
14
13
|
*/
|
|
15
14
|
export declare function makeIgnores(extensions: string | string[]): string;
|
|
@@ -8,6 +8,10 @@ export const extensions = {
|
|
|
8
8
|
media: matchTokens("mp3 m4a wav mp4 mov webm ogg avi flv avchd")
|
|
9
9
|
};
|
|
10
10
|
export function makeIgnores(extensions2) {
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const tokens = matchTokens(extensions2);
|
|
12
|
+
if (tokens.length === 0) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
const disallowTail = tokens.join("$|") + "$";
|
|
16
|
+
return `\\.(?!${disallowTail})[^.]+$`;
|
|
13
17
|
}
|
|
@@ -6,6 +6,10 @@ export declare function parseQuery(path: string): string;
|
|
|
6
6
|
* Removes the query string from a path
|
|
7
7
|
*/
|
|
8
8
|
export declare function removeQuery(path: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Remove ordering from a path
|
|
11
|
+
*/
|
|
12
|
+
export declare function removeOrdering(path: string): string;
|
|
9
13
|
/**
|
|
10
14
|
* Gets the extension of a path
|
|
11
15
|
* @param path
|
|
@@ -7,6 +7,9 @@ export function parseQuery(path) {
|
|
|
7
7
|
export function removeQuery(path) {
|
|
8
8
|
return path.replace(/\?.*$/, "");
|
|
9
9
|
}
|
|
10
|
+
export function removeOrdering(path) {
|
|
11
|
+
return path.split("/").map((segment) => segment.replace(/^\d+\./, "")).join("/");
|
|
12
|
+
}
|
|
10
13
|
export function getExt(path) {
|
|
11
14
|
return Path.extname(removeQuery(path)).substring(1);
|
|
12
15
|
}
|