1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-16 10:34:07 +02:00

Bump image-size from 1.0.2 to 2.0.2 (#41384)

This commit is contained in:
Julien Déramond
2025-04-15 21:18:13 +02:00
committed by GitHub
parent d01e66f5f7
commit ed36faae9d
4 changed files with 12 additions and 22 deletions

View File

@@ -14,7 +14,7 @@ interface Props {
const { description, layout, thumbnail, title } = Astro.props
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" />

View File

@@ -1,11 +1,14 @@
import path from 'node:path'
import { promises as fs } from 'node:fs'
import sizeOf from 'image-size'
import { getDocsStaticFsPath } from './path'
export function getStaticImageSize(imagePath: string) {
const size = sizeOf(path.join(getDocsStaticFsPath(), imagePath))
export async function getStaticImageSize(imagePath: string) {
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}'.`)
}