mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-30 16:24:06 -06:00
feat: pass fileData to image generator
This commit is contained in:
parent
584893ebfa
commit
dbfd1a4280
@ -14,13 +14,13 @@ import { unescapeHTML } from "../util/escape"
|
|||||||
* @param opts options for generating image
|
* @param opts options for generating image
|
||||||
*/
|
*/
|
||||||
async function generateSocialImage(
|
async function generateSocialImage(
|
||||||
{ cfg, description, fileName, fontsPromise, title }: ImageOptions,
|
{ cfg, description, fileName, fontsPromise, title, fileData }: ImageOptions,
|
||||||
userOpts: SocialImageOptions,
|
userOpts: SocialImageOptions,
|
||||||
) {
|
) {
|
||||||
const fonts = await fontsPromise
|
const fonts = await fontsPromise
|
||||||
|
|
||||||
// JSX that will be used to generate satori svg
|
// JSX that will be used to generate satori svg
|
||||||
const imageElement = userOpts.imageStructure(cfg, userOpts, title, description, fonts)
|
const imageElement = userOpts.imageStructure(cfg, userOpts, title, description, fonts, fileData)
|
||||||
|
|
||||||
const svg = await satori(imageElement, {
|
const svg = await satori(imageElement, {
|
||||||
width: userOpts.width,
|
width: userOpts.width,
|
||||||
@ -101,6 +101,7 @@ export default (() => {
|
|||||||
fileExt: extension,
|
fileExt: extension,
|
||||||
fontsPromise,
|
fontsPromise,
|
||||||
cfg,
|
cfg,
|
||||||
|
fileData
|
||||||
},
|
},
|
||||||
fullOptions,
|
fullOptions,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import satori, { FontWeight, SatoriOptions } from "satori/wasm"
|
import { FontWeight, SatoriOptions } from "satori/wasm"
|
||||||
import { GlobalConfiguration } from "../cfg"
|
import { GlobalConfiguration } from "../cfg"
|
||||||
import { JSXInternal } from "preact/src/jsx"
|
import { JSXInternal } from "preact/src/jsx"
|
||||||
|
import { QuartzPluginData } from "../plugins/vfile"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an array of `FontOptions` (for satori) given google font names
|
* Get an array of `FontOptions` (for satori) given google font names
|
||||||
@ -70,6 +71,7 @@ export type SocialImageOptions = {
|
|||||||
* @param title title of current page
|
* @param title title of current page
|
||||||
* @param description description of current page
|
* @param description description of current page
|
||||||
* @param fonts global font that can be used for styling
|
* @param fonts global font that can be used for styling
|
||||||
|
* @param fileData full fileData of current page
|
||||||
* @returns prepared jsx to be used for generating image
|
* @returns prepared jsx to be used for generating image
|
||||||
*/
|
*/
|
||||||
imageStructure: (
|
imageStructure: (
|
||||||
@ -78,6 +80,7 @@ export type SocialImageOptions = {
|
|||||||
title: string,
|
title: string,
|
||||||
description: string,
|
description: string,
|
||||||
fonts: SatoriOptions["fonts"],
|
fonts: SatoriOptions["fonts"],
|
||||||
|
fileData: QuartzPluginData
|
||||||
) => JSXInternal.Element
|
) => JSXInternal.Element
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,4 +115,8 @@ export type ImageOptions = {
|
|||||||
* `GlobalConfiguration` of quartz (used for theme/typography)
|
* `GlobalConfiguration` of quartz (used for theme/typography)
|
||||||
*/
|
*/
|
||||||
cfg: GlobalConfiguration
|
cfg: GlobalConfiguration
|
||||||
|
/**
|
||||||
|
* full file data of current page
|
||||||
|
*/
|
||||||
|
fileData: QuartzPluginData
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { SatoriOptions } from "satori/wasm"
|
import { SatoriOptions } from "satori/wasm"
|
||||||
import { GlobalConfiguration } from "../cfg"
|
import { GlobalConfiguration } from "../cfg"
|
||||||
import { SocialImageOptions, UserOpts } from "./imageHelper"
|
import { SocialImageOptions, UserOpts } from "./imageHelper"
|
||||||
|
import { QuartzPluginData } from "../plugins/vfile"
|
||||||
|
|
||||||
export const defaultImage: SocialImageOptions["imageStructure"] = (
|
export const defaultImage: SocialImageOptions["imageStructure"] = (
|
||||||
cfg: GlobalConfiguration,
|
cfg: GlobalConfiguration,
|
||||||
@ -8,6 +9,7 @@ export const defaultImage: SocialImageOptions["imageStructure"] = (
|
|||||||
title: string,
|
title: string,
|
||||||
description: string,
|
description: string,
|
||||||
fonts: SatoriOptions["fonts"],
|
fonts: SatoriOptions["fonts"],
|
||||||
|
fileData: QuartzPluginData
|
||||||
) => {
|
) => {
|
||||||
// How many characters are allowed before switching to smaller font
|
// How many characters are allowed before switching to smaller font
|
||||||
const fontBreakPoint = 22
|
const fontBreakPoint = 22
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user