mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 13:24:05 -06:00
fix(ogImage): handle absolute paths for user defined og image paths
This commit is contained in:
parent
1b0e887df5
commit
d0d30f6245
@ -1,7 +1,13 @@
|
|||||||
import { QuartzEmitterPlugin } from "../types"
|
import { QuartzEmitterPlugin } from "../types"
|
||||||
import { i18n } from "../../i18n"
|
import { i18n } from "../../i18n"
|
||||||
import { unescapeHTML } from "../../util/escape"
|
import { unescapeHTML } from "../../util/escape"
|
||||||
import { FullSlug, getFileExtension, joinSegments, QUARTZ } from "../../util/path"
|
import {
|
||||||
|
FullSlug,
|
||||||
|
getFileExtension,
|
||||||
|
isAbsoluteFilePath,
|
||||||
|
joinSegments,
|
||||||
|
QUARTZ,
|
||||||
|
} from "../../util/path"
|
||||||
import { ImageOptions, SocialImageOptions, defaultImage, getSatoriFonts } from "../../util/og"
|
import { ImageOptions, SocialImageOptions, defaultImage, getSatoriFonts } from "../../util/og"
|
||||||
import sharp from "sharp"
|
import sharp from "sharp"
|
||||||
import satori, { SatoriOptions } from "satori"
|
import satori, { SatoriOptions } from "satori"
|
||||||
@ -144,9 +150,14 @@ export const CustomOgImages: QuartzEmitterPlugin<Partial<SocialImageOptions>> =
|
|||||||
additionalHead: [
|
additionalHead: [
|
||||||
(pageData) => {
|
(pageData) => {
|
||||||
const isRealFile = pageData.filePath !== undefined
|
const isRealFile = pageData.filePath !== undefined
|
||||||
const userDefinedOgImagePath = pageData.frontmatter?.socialImage
|
const socialImage = pageData.frontmatter?.socialImage
|
||||||
? `https://${baseUrl}/static/${pageData.frontmatter?.socialImage}`
|
|
||||||
: undefined
|
let userDefinedOgImagePath = undefined
|
||||||
|
if (socialImage) {
|
||||||
|
userDefinedOgImagePath = isAbsoluteFilePath(socialImage)
|
||||||
|
? socialImage
|
||||||
|
: `https://${baseUrl}/static/${socialImage}`
|
||||||
|
|
||||||
const generatedOgImagePath = isRealFile
|
const generatedOgImagePath = isRealFile
|
||||||
? `https://${baseUrl}/${pageData.slug!}-og-image.webp`
|
? `https://${baseUrl}/${pageData.slug!}-og-image.webp`
|
||||||
: undefined
|
: undefined
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user