diff --git a/docs/features/social images.md b/docs/features/social images.md index 456f4fb59..ebcafed82 100644 --- a/docs/features/social images.md +++ b/docs/features/social images.md @@ -127,3 +127,114 @@ If you have `generateSocialImages` enabled, you can check out all generated imag Images will be generated as `.webp` files, which helps to keep images small (the average image takes ~`19kB`). They are also compressed further using [sharp](https://sharp.pixelplumbing.com/). When using images, the appropriate [Open Graph](https://ogp.me/) and [Twitter](https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started) meta tags will be set to ensure they work and look as expected. + +## Examples + +Besides the template for the default image generation (found under `quartz/util/socialImage.tsx`), you can also add your own! To do this, you can either edit the source code of that file (not recommended) or create a new one (e.g. `customSocialImage.tsx`, source shown below). + +After adding that file, you can update `quartz.config.ts` to use your image generation template as follows: + +```ts +// Import component at start of file +import { customImage } from "./quartz/util/customSocialImage.tsx" + +// In main config +const config: QuartzConfig = { + ... + generateSocialImages: { + ... + imageStructure: customImage, // tells quartz to use your component when generating images + }, +} +``` + +The following example will generate images that look as follows: + +| Light | Dark | +| ------------------------------------------ | ----------------------------------------- | +| ![[custom-social-image-preview-light.png]] | ![[custom-social-image-preview-dark.png]] | + +This example (and the default template) use colors and fonts from your theme specified in the quartz config. Fonts get passed in as a prop, where `fonts[0]` will contain the header font and `fonts[1]` will contain the body font (more info in the [[#fonts]] section). + +```tsx +import { SatoriOptions } from "satori/wasm" +import { GlobalConfiguration } from "../cfg" +import { SocialImageOptions, UserOpts } from "./imageHelper" +import { QuartzPluginData } from "../plugins/vfile" + +export const customImage: SocialImageOptions["imageStructure"] = ( + cfg: GlobalConfiguration, + userOpts: UserOpts, + title: string, + description: string, + fonts: SatoriOptions["fonts"], + fileData: QuartzPluginData, +) => { + // How many characters are allowed before switching to smaller font + const fontBreakPoint = 22 + const useSmallerFont = title.length > fontBreakPoint + + const { colorScheme } = userOpts + return ( +
+
+

+ {title} +

+

+ {description} +

+
+
+
+ ) +} +``` diff --git a/docs/images/custom-social-image-preview-dark.png b/docs/images/custom-social-image-preview-dark.png new file mode 100644 index 000000000..60c4e85c0 Binary files /dev/null and b/docs/images/custom-social-image-preview-dark.png differ diff --git a/docs/images/custom-social-image-preview-light.png b/docs/images/custom-social-image-preview-light.png new file mode 100644 index 000000000..046a40708 Binary files /dev/null and b/docs/images/custom-social-image-preview-light.png differ