nuxt-content-assets 1.6.0 → 1.8.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 +1 -1
- package/dist/module.d.mts +1 -27
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/assets/public.d.ts +2 -2
- package/dist/runtime/assets/public.js +13 -3
- package/dist/runtime/assets/source.d.ts +1 -1
- package/dist/runtime/assets/source.js +13 -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
|
@@ -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.d.mts
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
interface ModuleOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Image size hints
|
|
6
|
-
*
|
|
7
|
-
* @example 'attrs style url'
|
|
8
|
-
* @default 'style'
|
|
9
|
-
*/
|
|
10
|
-
imageSize?: string | string[] | false;
|
|
11
|
-
/**
|
|
12
|
-
* List of content extensions; anything else as an asset
|
|
13
|
-
*
|
|
14
|
-
* @example 'md'
|
|
15
|
-
* @default 'md csv ya?ml json'
|
|
16
|
-
*/
|
|
17
|
-
contentExtensions?: string | string[];
|
|
18
|
-
/**
|
|
19
|
-
* Display debug messages
|
|
20
|
-
*
|
|
21
|
-
* @example true
|
|
22
|
-
* @default false
|
|
23
|
-
*/
|
|
24
|
-
debug?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
1
|
+
declare const _default: any;
|
|
28
2
|
|
|
29
3
|
export { _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -221,7 +221,7 @@ const module$1 = defineNuxtModule({
|
|
|
221
221
|
nuxt.hook("close", async () => {
|
|
222
222
|
await assets.dispose();
|
|
223
223
|
for (const key in managers) {
|
|
224
|
-
await managers[key]
|
|
224
|
+
await managers[key]?.dispose();
|
|
225
225
|
}
|
|
226
226
|
});
|
|
227
227
|
const pluginPath = resolve("./runtime/content/plugin");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AssetConfig, ParsedContent } from '../../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Manages the public assets
|
|
4
4
|
*/
|
|
@@ -7,7 +7,7 @@ export declare function makeAssetsManager(publicPath: string, shouldWatch?: bool
|
|
|
7
7
|
setAsset: (path: string) => AssetConfig;
|
|
8
8
|
getAsset: (path: string) => AssetConfig | undefined;
|
|
9
9
|
removeAsset: (path: string) => AssetConfig | undefined;
|
|
10
|
-
resolveAsset: (content: ParsedContent, relAsset: string, registerContent?: boolean) =>
|
|
10
|
+
resolveAsset: (content: ParsedContent, relAsset: string, registerContent?: boolean) => AssetConfig;
|
|
11
11
|
dispose: () => Promise<void>;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
@@ -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, "..");
|
|
@@ -26,7 +26,8 @@ export function makeAssetsManager(publicPath, shouldWatch = true) {
|
|
|
26
26
|
}, 50);
|
|
27
27
|
function resolveAsset(content, relAsset, registerContent = false) {
|
|
28
28
|
const srcDir = Path.dirname(content._file);
|
|
29
|
-
const
|
|
29
|
+
const relAssetNoQuery = removeQuery(relAsset);
|
|
30
|
+
const srcAsset = removeOrdering(Path.join(srcDir, relAssetNoQuery));
|
|
30
31
|
const asset = assets[srcAsset];
|
|
31
32
|
if (asset && registerContent) {
|
|
32
33
|
const { _id } = content;
|
|
@@ -35,7 +36,16 @@ export function makeAssetsManager(publicPath, shouldWatch = true) {
|
|
|
35
36
|
save();
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
if (asset) {
|
|
40
|
+
if (relAsset.includes("?")) {
|
|
41
|
+
return {
|
|
42
|
+
...asset,
|
|
43
|
+
srcAttr: asset.srcAttr + "?" + relAsset.split("?").pop() || ""
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return asset;
|
|
47
|
+
}
|
|
48
|
+
return { srcAttr: "", content: [] };
|
|
39
49
|
}
|
|
40
50
|
function setAsset(path) {
|
|
41
51
|
const { srcRel, srcAttr } = getAssetPaths(publicPath, path);
|
|
@@ -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));
|
|
@@ -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
|
}
|