@libsrcdev/gatsby-remark-images-anywhere 0.1.7 → 0.1.8
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/index.d.ts +14 -24
- package/dist/index.js +23 -8
- package/package.json +22 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node, NodePluginArgs } from "gatsby";
|
|
1
|
+
import { Node, NodePluginArgs, Reporter } from "gatsby";
|
|
2
2
|
import { FileSystemNode } from "gatsby-source-filesystem";
|
|
3
3
|
import { Literal, Literal as RemarkLiteral, Node as RemarkNode } from "mdast";
|
|
4
4
|
|
|
@@ -55,6 +55,15 @@ interface Options extends Partial<MarkupOptions>, HttpRequestHeaderOptions {
|
|
|
55
55
|
[key: string]: unknown;
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
|
+
//#region src/util-html-to-md.d.ts
|
|
59
|
+
type RemarkImageNode = RemarkLiteral & {
|
|
60
|
+
url?: string;
|
|
61
|
+
title?: string;
|
|
62
|
+
alt?: string;
|
|
63
|
+
data: Record<string, any>;
|
|
64
|
+
};
|
|
65
|
+
declare const toMdNode: (node: RemarkLiteral) => RemarkImageNode | null;
|
|
66
|
+
//#endregion
|
|
58
67
|
//#region src/constants.d.ts
|
|
59
68
|
declare const CLASS_WRAPPER = "gria-image-wrapper";
|
|
60
69
|
declare const CLASS_PADDING = "gria-image-padding";
|
|
@@ -113,15 +122,6 @@ declare const processImage: ({
|
|
|
113
122
|
[key: string]: any;
|
|
114
123
|
}) => Promise<SharpResult>;
|
|
115
124
|
//#endregion
|
|
116
|
-
//#region src/util-html-to-md.d.ts
|
|
117
|
-
type RemarkImageNode = RemarkLiteral & {
|
|
118
|
-
url?: string;
|
|
119
|
-
title?: string;
|
|
120
|
-
alt?: string;
|
|
121
|
-
data: Record<string, any>;
|
|
122
|
-
};
|
|
123
|
-
declare const toMdNode: (node: RemarkLiteral) => RemarkImageNode | null;
|
|
124
|
-
//#endregion
|
|
125
125
|
//#region src/utils.d.ts
|
|
126
126
|
/**
|
|
127
127
|
* Resolves a potentially incomplete URL to a full URL with protocol
|
|
@@ -137,18 +137,8 @@ declare function resolveFullUrl(url: string): string | undefined;
|
|
|
137
137
|
declare function resolveRelativeUrl(url: string): string | undefined;
|
|
138
138
|
//#endregion
|
|
139
139
|
//#region src/index.d.ts
|
|
140
|
-
declare
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
actions,
|
|
144
|
-
store,
|
|
145
|
-
files,
|
|
146
|
-
getNode,
|
|
147
|
-
getCache,
|
|
148
|
-
createNodeId,
|
|
149
|
-
reporter,
|
|
150
|
-
cache,
|
|
151
|
-
pathPrefix
|
|
152
|
-
}: Args, pluginOptions: Options): Promise<(null | undefined)[]>;
|
|
140
|
+
declare let localReporter: Reporter;
|
|
141
|
+
declare function extractAllImgNodesFromMdast(mdast: RemarkNode): RemarkImageNode[];
|
|
142
|
+
declare function remarkImagesAnywhere(gatsbyApis: Args, pluginOptions: Options): Promise<(null | undefined)[]>;
|
|
153
143
|
//#endregion
|
|
154
|
-
export { Args, CLASS_IMAGE, CLASS_LINK, CLASS_PADDING, CLASS_PLACEHOLDER, CLASS_WRAPPER, CreateMarkup, CreateMarkupArgs, HttpRequestHeaderOptions, HttpRequestHeaderProvider, MarkupOptions, Options, RemarkImageNode, type RemarkLiteral, type RemarkNode, SUPPORT_EXTS, SharpMethod, SharpResult, UrlCheckOptions, buildRequestHttpHeadersWith, remarkImagesAnywhere as default, defaultMarkup, downloadImage, forTrustedDomains, httpHeaderTrustedProvider, isTrustedUrl, isWhitelisted, makeWhitelistTest, processImage, resolveFullUrl, resolveRelativeUrl, toMdNode };
|
|
144
|
+
export { Args, CLASS_IMAGE, CLASS_LINK, CLASS_PADDING, CLASS_PLACEHOLDER, CLASS_WRAPPER, CreateMarkup, CreateMarkupArgs, HttpRequestHeaderOptions, HttpRequestHeaderProvider, MarkupOptions, Options, RemarkImageNode, type RemarkLiteral, type RemarkNode, SUPPORT_EXTS, SharpMethod, SharpResult, UrlCheckOptions, buildRequestHttpHeadersWith, remarkImagesAnywhere as default, defaultMarkup, downloadImage, extractAllImgNodesFromMdast, forTrustedDomains, httpHeaderTrustedProvider, isTrustedUrl, isWhitelisted, localReporter, makeWhitelistTest, processImage, resolveFullUrl, resolveRelativeUrl, toMdNode };
|
package/dist/index.js
CHANGED
|
@@ -343,7 +343,17 @@ function resolveRelativeUrl(url) {
|
|
|
343
343
|
|
|
344
344
|
//#endregion
|
|
345
345
|
//#region src/index.ts
|
|
346
|
-
|
|
346
|
+
let localReporter;
|
|
347
|
+
function extractAllImgNodesFromMdast(mdast) {
|
|
348
|
+
const imgNodes = (0, unist_util_select.selectAll)("image[url]", mdast).filter((node) => "url" in node);
|
|
349
|
+
const htmlImgNodes = (0, unist_util_select.selectAll)("html, jsx", mdast).filter((node) => "value" in node).map((node, _, __) => toMdNode(node)).filter((node, _, __) => !!node);
|
|
350
|
+
const allImgNodes = [...imgNodes, ...htmlImgNodes];
|
|
351
|
+
if (localReporter) localReporter.info(`[gria] Processing ${allImgNodes.length} image(s) (${imgNodes.length} markdown, ${htmlImgNodes.length} html)`);
|
|
352
|
+
return allImgNodes;
|
|
353
|
+
}
|
|
354
|
+
async function remarkImagesAnywhere(gatsbyApis, pluginOptions) {
|
|
355
|
+
const { markdownAST: mdast, markdownNode, actions, store, files, getNode, getCache, createNodeId, reporter, cache, pathPrefix } = gatsbyApis;
|
|
356
|
+
localReporter = reporter;
|
|
347
357
|
const { plugins, staticDir = "static", createMarkup = defaultMarkup, sharpMethod = "fluid", loading = "lazy", linkImagesToOriginal = false, showCaptions = false, wrapperStyle = "", backgroundColor = "#fff", tracedSVG = false, blurUp = true, dangerouslyBuildRequestHttpHeaders, httpHeaderProviders = [], ...imageOptions } = pluginOptions;
|
|
348
358
|
if ([
|
|
349
359
|
"fluid",
|
|
@@ -353,12 +363,7 @@ async function remarkImagesAnywhere({ markdownAST: mdast, markdownNode, actions,
|
|
|
353
363
|
const { touchNode, createNode } = actions;
|
|
354
364
|
const dirPath = markdownNode.parent && getNode(markdownNode.parent)?.dir;
|
|
355
365
|
const { directory } = store.getState().program;
|
|
356
|
-
const
|
|
357
|
-
const htmlImgNodes = (0, unist_util_select.selectAll)("html, jsx", mdast).filter((node) => "value" in node).map((node, _, __) => toMdNode(node)).filter((node, _, __) => !!node);
|
|
358
|
-
imgNodes.push(...htmlImgNodes);
|
|
359
|
-
const allImgNodes = [...imgNodes, ...htmlImgNodes];
|
|
360
|
-
reporter.info(`[gria] Processing ${allImgNodes.length} image(s) (${imgNodes.length} markdown, ${htmlImgNodes.length} html) using sharpMethod="${sharpMethod}"`);
|
|
361
|
-
const processPromises = allImgNodes.map(async (node) => {
|
|
366
|
+
const processPromises = extractAllImgNodesFromMdast(mdast).map(async (node) => {
|
|
362
367
|
if (!node.url) return;
|
|
363
368
|
let url = node.url;
|
|
364
369
|
let gImgFileNode;
|
|
@@ -389,7 +394,10 @@ async function remarkImagesAnywhere({ markdownAST: mdast, markdownNode, actions,
|
|
|
389
394
|
else filePath = path.default.join(directory, staticDir, url);
|
|
390
395
|
reporter.verbose(`[gria] Resolving local image: ${url} -> ${filePath}`);
|
|
391
396
|
gImgFileNode = files.find((fileNode) => fileNode.absolutePath && fileNode.absolutePath === filePath);
|
|
392
|
-
} else
|
|
397
|
+
} else {
|
|
398
|
+
reporter.warn(`[gria] Skipping unrecognized image URL: ${url}`);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
393
401
|
if (!gImgFileNode) {
|
|
394
402
|
reporter.verbose(`[gria] No file node found for: ${url}`);
|
|
395
403
|
return;
|
|
@@ -444,10 +452,17 @@ exports.buildRequestHttpHeadersWith = buildRequestHttpHeadersWith;
|
|
|
444
452
|
exports.default = remarkImagesAnywhere;
|
|
445
453
|
exports.defaultMarkup = defaultMarkup;
|
|
446
454
|
exports.downloadImage = downloadImage;
|
|
455
|
+
exports.extractAllImgNodesFromMdast = extractAllImgNodesFromMdast;
|
|
447
456
|
exports.forTrustedDomains = forTrustedDomains;
|
|
448
457
|
exports.httpHeaderTrustedProvider = httpHeaderTrustedProvider;
|
|
449
458
|
exports.isTrustedUrl = isTrustedUrl;
|
|
450
459
|
exports.isWhitelisted = isWhitelisted;
|
|
460
|
+
Object.defineProperty(exports, 'localReporter', {
|
|
461
|
+
enumerable: true,
|
|
462
|
+
get: function () {
|
|
463
|
+
return localReporter;
|
|
464
|
+
}
|
|
465
|
+
});
|
|
451
466
|
exports.makeWhitelistTest = makeWhitelistTest;
|
|
452
467
|
exports.processImage = processImage;
|
|
453
468
|
exports.resolveFullUrl = resolveFullUrl;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libsrcdev/gatsby-remark-images-anywhere",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Handle images with relative, absolute, remote path for gatsby-transformer-remark.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gatsby",
|
|
@@ -28,38 +28,47 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
|
-
"dev": "nodemon --watch src
|
|
31
|
+
"dev": "nodemon --watch package.json --watch src --ext js,ts,mjs,cjs,json --exec \"tsdown && yalc publish\"",
|
|
32
32
|
"build": "tsdown",
|
|
33
33
|
"lint": "eslint . --ext .ts",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
34
|
+
"prepare": "npm run build",
|
|
35
|
+
"test": "jest"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
38
|
+
"gatsby-source-filesystem": "^5.16.0",
|
|
39
|
+
"is-relative-url": "3.0.0",
|
|
40
|
+
"parse5": "5.0.0",
|
|
40
41
|
"slash": "^3.0.0",
|
|
41
|
-
"unist-util-select": "
|
|
42
|
+
"unist-util-select": "3.0.4"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
45
|
+
"@babel/core": "^7.29.0",
|
|
46
|
+
"@babel/preset-env": "^7.29.0",
|
|
47
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
44
48
|
"@swc/core": "^1.15.3",
|
|
45
49
|
"@types/fs-extra": "^8.0.0",
|
|
50
|
+
"@types/jest": "^30.0.0",
|
|
46
51
|
"@types/mdast": "^4.0.4",
|
|
52
|
+
"babel-preset-gatsby": "^3.16.0",
|
|
47
53
|
"eslint": "^9.39.1",
|
|
48
|
-
"gatsby": "^5.
|
|
49
|
-
"gatsby-plugin-sharp": "^5.
|
|
50
|
-
"gatsby-source-filesystem": "^5.15.0",
|
|
54
|
+
"gatsby": "^5.16.1",
|
|
55
|
+
"gatsby-plugin-sharp": "^5.16.0",
|
|
51
56
|
"husky": "^9.1.7",
|
|
57
|
+
"identity-obj-proxy": "^3.0.0",
|
|
58
|
+
"jest": "^30.2.0",
|
|
52
59
|
"mdast": "^2.3.2",
|
|
53
60
|
"nodemon": "^3.1.11",
|
|
54
61
|
"tap": "^14.9.2",
|
|
62
|
+
"ts-jest": "^29.4.6",
|
|
63
|
+
"ts-node-test": "^0.4.4",
|
|
55
64
|
"tsdown": "^0.16.6",
|
|
56
65
|
"tslib": "^2.8.1",
|
|
57
66
|
"typescript": "^5.9.3"
|
|
58
67
|
},
|
|
59
68
|
"peerDependencies": {
|
|
60
69
|
"gatsby": "^5.15.0",
|
|
61
|
-
"gatsby-
|
|
62
|
-
"gatsby-
|
|
70
|
+
"gatsby-plugin-sharp": "^5.15.0",
|
|
71
|
+
"gatsby-source-filesystem": "^5.15.0"
|
|
63
72
|
},
|
|
64
73
|
"typings": "dist/index.d.ts",
|
|
65
74
|
"prettier": {
|
|
@@ -68,4 +77,4 @@
|
|
|
68
77
|
"singleQuote": true,
|
|
69
78
|
"trailingComma": "es5"
|
|
70
79
|
}
|
|
71
|
-
}
|
|
80
|
+
}
|