@prunellejs/images 0.9.0 → 0.10.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/package.json +2 -2
- package/src/plugin.ts +14 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prunellejs/images",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Build-time responsive AVIF/WebP image optimization plugin for Prunelle",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"directory": "packages/plugin-images"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"prunelle": "^0.
|
|
25
|
+
"prunelle": "^0.10.0"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/plugin.ts
CHANGED
|
@@ -469,6 +469,15 @@ export interface MarkdownImageResolverOptions extends OptimizeImageFileOptions {
|
|
|
469
469
|
root?: string | undefined
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
+
function percentDecoded(src: string): string {
|
|
473
|
+
try {
|
|
474
|
+
return decodeURIComponent(src)
|
|
475
|
+
}
|
|
476
|
+
catch {
|
|
477
|
+
return src
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
472
481
|
/** Creates a `@prunellejs/content` `resolveImage` function backed by `optimizeImageFile()`. Automatically wired by `images()`. */
|
|
473
482
|
export function createMarkdownImageResolver(options: MarkdownImageResolverOptions = {}) {
|
|
474
483
|
const sizes = options.sizes ?? '(min-width: 48rem) 42rem, 100vw'
|
|
@@ -487,12 +496,11 @@ export function createMarkdownImageResolver(options: MarkdownImageResolverOption
|
|
|
487
496
|
: dirname(absFile)
|
|
488
497
|
}
|
|
489
498
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if (!existsSync(abs))
|
|
499
|
+
// The renderer percent-encodes a src (`my%20image.png`), so the decoded name is tried first and the literal one next, for a file really named with a `%`.
|
|
500
|
+
const abs = [percentDecoded(src), src]
|
|
501
|
+
.map(candidate => resolve(dirname(absFile), candidate))
|
|
502
|
+
.find(candidate => isInside(boundary, candidate) && ALLOWED_IMAGE_EXTS.has(extname(candidate).toLowerCase()) && existsSync(candidate))
|
|
503
|
+
if (abs === undefined)
|
|
496
504
|
return undefined
|
|
497
505
|
|
|
498
506
|
let realBoundary: string
|