@libsrcdev/gatsby-remark-images-anywhere 0.1.5 → 0.1.7

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.
Files changed (2) hide show
  1. package/dist/index.js +27 -8
  2. package/package.json +69 -69
package/dist/index.js CHANGED
@@ -48,6 +48,7 @@ const downloadImage = async ({ id, url, getCache, getNode, touchNode, cache, cre
48
48
  const fileNode = getNode(fileNodeId);
49
49
  if (fileNode) {
50
50
  touchNode({ nodeId: fileNodeId });
51
+ reporter.verbose(`[gria] Using cached image for: ${url}`);
51
52
  imageFileNode = fileNode;
52
53
  }
53
54
  }
@@ -64,10 +65,11 @@ const downloadImage = async ({ id, url, getCache, getNode, touchNode, cache, cre
64
65
  });
65
66
  if (fileNode) {
66
67
  imageFileNode = fileNode;
68
+ reporter.verbose(`[gria] Downloaded and cached remote image: ${url}`);
67
69
  await cache.set(mediaDataCacheKey, { fileNodeId: fileNode.id });
68
70
  }
69
71
  } catch (e) {
70
- reporter.warn(`failed to download ${url} Error: ${e}`);
72
+ reporter.warn(`[gria] Failed to download ${url}: ${e}`);
71
73
  }
72
74
  return imageFileNode;
73
75
  };
@@ -354,14 +356,20 @@ async function remarkImagesAnywhere({ markdownAST: mdast, markdownNode, actions,
354
356
  const imgNodes = (0, unist_util_select.selectAll)("image[url]", mdast).filter((node) => "src" in node);
355
357
  const htmlImgNodes = (0, unist_util_select.selectAll)("html, jsx", mdast).filter((node) => "value" in node).map((node, _, __) => toMdNode(node)).filter((node, _, __) => !!node);
356
358
  imgNodes.push(...htmlImgNodes);
357
- const processPromises = [...imgNodes, ...htmlImgNodes].map(async (node) => {
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) => {
358
362
  if (!node.url) return;
359
363
  let url = node.url;
360
364
  let gImgFileNode;
361
- if (isWhitelisted(url)) url = `https:${url}`;
365
+ if (isWhitelisted(url)) {
366
+ reporter.verbose(`[gria] Whitelisted protocol-relative URL, prepending https: ${url}`);
367
+ url = `https:${url}`;
368
+ }
362
369
  const remoteFullImageUrl = resolveFullUrl(url);
363
370
  const relativeImageUrl = resolveRelativeUrl(url);
364
371
  if (remoteFullImageUrl) {
372
+ reporter.verbose(`[gria] Downloading remote image: ${remoteFullImageUrl}`);
365
373
  const buildRequestHttpHeaders = dangerouslyBuildRequestHttpHeaders ?? buildRequestHttpHeadersWith(httpHeaderProviders);
366
374
  gImgFileNode = await downloadImage({
367
375
  id: markdownNode.id,
@@ -379,10 +387,17 @@ async function remarkImagesAnywhere({ markdownAST: mdast, markdownNode, actions,
379
387
  let filePath;
380
388
  if (dirPath && url[0] === ".") filePath = (0, slash.default)(path.default.join(dirPath, url));
381
389
  else filePath = path.default.join(directory, staticDir, url);
390
+ reporter.verbose(`[gria] Resolving local image: ${url} -> ${filePath}`);
382
391
  gImgFileNode = files.find((fileNode) => fileNode.absolutePath && fileNode.absolutePath === filePath);
383
- } else reporter.warn(`Skipping invalid image URL ${url}`);
384
- if (!gImgFileNode) return;
385
- if (!SUPPORT_EXTS.includes(gImgFileNode.extension)) return;
392
+ } else reporter.warn(`[gria] Skipping unrecognized image URL: ${url}`);
393
+ if (!gImgFileNode) {
394
+ reporter.verbose(`[gria] No file node found for: ${url}`);
395
+ return;
396
+ }
397
+ if (!SUPPORT_EXTS.includes(gImgFileNode.extension)) {
398
+ reporter.verbose(`[gria] Unsupported extension "${gImgFileNode.extension}" for: ${url}`);
399
+ return;
400
+ }
386
401
  const imageResult = await processImage({
387
402
  file: gImgFileNode,
388
403
  reporter,
@@ -391,7 +406,11 @@ async function remarkImagesAnywhere({ markdownAST: mdast, markdownNode, actions,
391
406
  sharpMethod,
392
407
  imageOptions
393
408
  });
394
- if (!imageResult) return;
409
+ if (!imageResult) {
410
+ reporter.warn(`[gria] Sharp processing returned no result for: ${url}`);
411
+ return;
412
+ }
413
+ reporter.verbose(`[gria] Successfully processed image: ${url}`);
395
414
  const data = {
396
415
  title: node.title,
397
416
  alt: node.alt,
@@ -411,7 +430,7 @@ async function remarkImagesAnywhere({ markdownAST: mdast, markdownNode, actions,
411
430
  });
412
431
  return null;
413
432
  });
414
- return Promise.all(processPromises);
433
+ return await Promise.all(processPromises);
415
434
  }
416
435
 
417
436
  //#endregion
package/package.json CHANGED
@@ -1,71 +1,71 @@
1
1
  {
2
- "name": "@libsrcdev/gatsby-remark-images-anywhere",
3
- "version": "0.1.5",
4
- "description": "Handle images with relative, absolute, remote path for gatsby-transformer-remark.",
5
- "keywords": [
6
- "gatsby",
7
- "gatsby-plugin",
8
- "transformer",
9
- "remark",
10
- "images",
11
- "anywhere",
12
- "fork",
13
- "v5",
14
- "remark-images"
15
- ],
16
- "homepage": "https://github.com/libsrcdev/gatsby-remark-images-anywhere",
17
- "bugs": {
18
- "url": "https://github.com/libsrcdev/gatsby-remark-images-anywhere/issues"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/libsrcdev/gatsby-remark-images-anywhere.git"
23
- },
24
- "license": "MIT",
25
- "author": "Derek Nguyen <derek@penandpillow.com>, @libsrcdev <git@libsrc.dev>",
26
- "main": "./dist/index.js",
27
- "files": [
28
- "dist"
29
- ],
30
- "scripts": {
31
- "dev": "nodemon --watch src --ext js,ts,mjs,cjs,json --exec \"tsdown\"",
32
- "build": "tsdown",
33
- "lint": "eslint . --ext .ts",
34
- "test": "vitest",
35
- "prepare": "npm run build"
36
- },
37
- "dependencies": {
38
- "is-relative-url": "^4.1.0",
39
- "parse5": "^8.0.0",
40
- "slash": "^3.0.0",
41
- "unist-util-select": "^5.1.0"
42
- },
43
- "devDependencies": {
44
- "@swc/core": "^1.15.3",
45
- "@types/fs-extra": "^8.0.0",
46
- "@types/mdast": "^4.0.4",
47
- "eslint": "^9.39.1",
48
- "gatsby": "^5.15.0",
49
- "gatsby-plugin-sharp": "^5.15.0",
50
- "gatsby-source-filesystem": "^5.15.0",
51
- "husky": "^9.1.7",
52
- "mdast": "^2.3.2",
53
- "nodemon": "^3.1.11",
54
- "tap": "^14.9.2",
55
- "tsdown": "^0.16.6",
56
- "tslib": "^2.8.1",
57
- "typescript": "^5.9.3"
58
- },
59
- "peerDependencies": {
60
- "gatsby": "^5.15.0",
61
- "gatsby-source-filesystem": "^5.15.0",
62
- "gatsby-plugin-sharp": "^5.15.0"
63
- },
64
- "typings": "dist/index.d.ts",
65
- "prettier": {
66
- "printWidth": 80,
67
- "semi": true,
68
- "singleQuote": true,
69
- "trailingComma": "es5"
70
- }
2
+ "name": "@libsrcdev/gatsby-remark-images-anywhere",
3
+ "version": "0.1.7",
4
+ "description": "Handle images with relative, absolute, remote path for gatsby-transformer-remark.",
5
+ "keywords": [
6
+ "gatsby",
7
+ "gatsby-plugin",
8
+ "transformer",
9
+ "remark",
10
+ "images",
11
+ "anywhere",
12
+ "fork",
13
+ "v5",
14
+ "remark-images"
15
+ ],
16
+ "homepage": "https://github.com/libsrcdev/gatsby-remark-images-anywhere",
17
+ "bugs": {
18
+ "url": "https://github.com/libsrcdev/gatsby-remark-images-anywhere/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/libsrcdev/gatsby-remark-images-anywhere.git"
23
+ },
24
+ "license": "MIT",
25
+ "author": "Derek Nguyen <derek@penandpillow.com>, @libsrcdev <git@libsrc.dev>",
26
+ "main": "./dist/index.js",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "scripts": {
31
+ "dev": "nodemon --watch src --ext js,ts,mjs,cjs,json --exec \"tsdown\"",
32
+ "build": "tsdown",
33
+ "lint": "eslint . --ext .ts",
34
+ "test": "vitest",
35
+ "prepare": "npm run build"
36
+ },
37
+ "dependencies": {
38
+ "is-relative-url": "^4.1.0",
39
+ "parse5": "^8.0.0",
40
+ "slash": "^3.0.0",
41
+ "unist-util-select": "^5.1.0"
42
+ },
43
+ "devDependencies": {
44
+ "@swc/core": "^1.15.3",
45
+ "@types/fs-extra": "^8.0.0",
46
+ "@types/mdast": "^4.0.4",
47
+ "eslint": "^9.39.1",
48
+ "gatsby": "^5.15.0",
49
+ "gatsby-plugin-sharp": "^5.15.0",
50
+ "gatsby-source-filesystem": "^5.15.0",
51
+ "husky": "^9.1.7",
52
+ "mdast": "^2.3.2",
53
+ "nodemon": "^3.1.11",
54
+ "tap": "^14.9.2",
55
+ "tsdown": "^0.16.6",
56
+ "tslib": "^2.8.1",
57
+ "typescript": "^5.9.3"
58
+ },
59
+ "peerDependencies": {
60
+ "gatsby": "^5.15.0",
61
+ "gatsby-source-filesystem": "^5.15.0",
62
+ "gatsby-plugin-sharp": "^5.15.0"
63
+ },
64
+ "typings": "dist/index.d.ts",
65
+ "prettier": {
66
+ "printWidth": 80,
67
+ "semi": true,
68
+ "singleQuote": true,
69
+ "trailingComma": "es5"
70
+ }
71
71
  }