Skip to content

Commit ed36faa

Browse files
Bump image-size from 1.0.2 to 2.0.2 (#41384)
1 parent d01e66f commit ed36faa

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

package-lock.json

Lines changed: 4 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"globby": "^14.1.0",
146146
"hammer-simulator": "0.0.1",
147147
"htmlparser2": "^10.0.0",
148-
"image-size": "^1.0.2",
148+
"image-size": "^2.0.2",
149149
"ip": "^2.0.1",
150150
"jasmine": "^5.6.0",
151151
"jquery": "^3.7.1",

site/src/components/head/Social.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Props {
1414
const { description, layout, thumbnail, title } = Astro.props
1515
1616
const socialImageUrl = new URL(getVersionedDocsPath(`assets/${thumbnail}`), Astro.site)
17-
const socialImageSize = getStaticImageSize(`/docs/[version]/assets/${thumbnail}`)
17+
const socialImageSize = await getStaticImageSize(`/docs/[version]/assets/${thumbnail}`)
1818
---
1919

2020
<meta name="twitter:card" content="summary_large_image" />

site/src/libs/image.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import path from 'node:path'
2+
import { promises as fs } from 'node:fs'
23
import sizeOf from 'image-size'
34
import { getDocsStaticFsPath } from './path'
45

5-
export function getStaticImageSize(imagePath: string) {
6-
const size = sizeOf(path.join(getDocsStaticFsPath(), imagePath))
6+
export async function getStaticImageSize(imagePath: string) {
7+
const fullPath = path.join(getDocsStaticFsPath(), imagePath)
8+
const buffer = await fs.readFile(fullPath)
9+
const size = await sizeOf(buffer)
710

8-
if (!size.height || !size.width) {
11+
if (!size?.height || !size?.width) {
912
throw new Error(`Failed to get size of static image at '${imagePath}'.`)
1013
}
1114

0 commit comments

Comments
 (0)