Bump `image-size` from 1.0.2 to 2.0.2 (#41384)
BrowserStack / browserstack (push) Has been cancelled Details
Bundlewatch / bundlewatch (push) Has been cancelled Details
cspell / cspell (push) Has been cancelled Details
CSS / css (push) Has been cancelled Details
Docs / docs (push) Has been cancelled Details
JS Tests / JS Tests (push) Has been cancelled Details
Lint / lint (push) Has been cancelled Details
CSS (node-sass) / css (push) Has been cancelled Details
Release notes / update_release_draft (push) Has been cancelled Details
CodeQL / Analyze (push) Has been cancelled Details

This commit is contained in:
Julien Déramond 2025-04-15 21:18:13 +02:00 committed by GitHub
parent d01e66f5f7
commit ed36faae9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 22 deletions

21
package-lock.json generated
View File

@ -56,7 +56,7 @@
"globby": "^14.1.0", "globby": "^14.1.0",
"hammer-simulator": "0.0.1", "hammer-simulator": "0.0.1",
"htmlparser2": "^10.0.0", "htmlparser2": "^10.0.0",
"image-size": "^1.0.2", "image-size": "^2.0.2",
"ip": "^2.0.1", "ip": "^2.0.1",
"jasmine": "^5.6.0", "jasmine": "^5.6.0",
"jquery": "^3.7.1", "jquery": "^3.7.1",
@ -9450,14 +9450,11 @@
"license": "ISC" "license": "ISC"
}, },
"node_modules/image-size": { "node_modules/image-size": {
"version": "1.2.0", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/image-size/-/image-size-1.2.0.tgz", "resolved": "https://registry.npmjs.org/image-size/-/image-size-2.0.2.tgz",
"integrity": "sha512-4S8fwbO6w3GeCVN6OPtA9I5IGKkcDMPcKndtUlpJuCwu7JLjtj7JZpwqLuyY2nrmQT3AWsCJLSKPsc2mPBSl3w==", "integrity": "sha512-IRqXKlaXwgSMAMtpNzZa1ZAe8m+Sa1770Dhk8VkSsP9LS+iHD62Zd8FQKs8fbPiagBE7BzoFX23cxFnwshpV6w==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": {
"queue": "6.0.2"
},
"bin": { "bin": {
"image-size": "bin/image-size.js" "image-size": "bin/image-size.js"
}, },
@ -14949,16 +14946,6 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/queue": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/queue/-/queue-6.0.2.tgz",
"integrity": "sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==",
"dev": true,
"license": "MIT",
"dependencies": {
"inherits": "~2.0.3"
}
},
"node_modules/queue-microtask": { "node_modules/queue-microtask": {
"version": "1.2.3", "version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",

View File

@ -145,7 +145,7 @@
"globby": "^14.1.0", "globby": "^14.1.0",
"hammer-simulator": "0.0.1", "hammer-simulator": "0.0.1",
"htmlparser2": "^10.0.0", "htmlparser2": "^10.0.0",
"image-size": "^1.0.2", "image-size": "^2.0.2",
"ip": "^2.0.1", "ip": "^2.0.1",
"jasmine": "^5.6.0", "jasmine": "^5.6.0",
"jquery": "^3.7.1", "jquery": "^3.7.1",

View File

@ -14,7 +14,7 @@ interface Props {
const { description, layout, thumbnail, title } = Astro.props const { description, layout, thumbnail, title } = Astro.props
const socialImageUrl = new URL(getVersionedDocsPath(`assets/${thumbnail}`), Astro.site) const socialImageUrl = new URL(getVersionedDocsPath(`assets/${thumbnail}`), Astro.site)
const socialImageSize = getStaticImageSize(`/docs/[version]/assets/${thumbnail}`) const socialImageSize = await getStaticImageSize(`/docs/[version]/assets/${thumbnail}`)
--- ---
<meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:card" content="summary_large_image" />

View File

@ -1,11 +1,14 @@
import path from 'node:path' import path from 'node:path'
import { promises as fs } from 'node:fs'
import sizeOf from 'image-size' import sizeOf from 'image-size'
import { getDocsStaticFsPath } from './path' import { getDocsStaticFsPath } from './path'
export function getStaticImageSize(imagePath: string) { export async function getStaticImageSize(imagePath: string) {
const size = sizeOf(path.join(getDocsStaticFsPath(), imagePath)) const fullPath = path.join(getDocsStaticFsPath(), imagePath)
const buffer = await fs.readFile(fullPath)
const size = await sizeOf(buffer)
if (!size.height || !size.width) { if (!size?.height || !size?.width) {
throw new Error(`Failed to get size of static image at '${imagePath}'.`) throw new Error(`Failed to get size of static image at '${imagePath}'.`)
} }