Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"globby": "^14.1.0",
"hammer-simulator": "0.0.1",
"htmlparser2": "^10.0.0",
"image-size": "^1.0.2",
"image-size": "^2.0.2",
"ip": "^2.0.1",
"jasmine": "^5.6.0",
"jquery": "^3.7.1",
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/head/Social.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
9 changes: 6 additions & 3 deletions site/src/libs/image.ts
Original file line number Diff line number Diff line change
@@ -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}'.`)
}

Expand Down