惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

AstroPaper

AstroPaper 6.0 | AstroPaper AstroPaper 5.0 | AstroPaper How to add LaTeX Equations in Astro blog posts | AstroPaper How to integrate Giscus comments into AstroPaper | AstroPaper AstroPaper 4.0 | AstroPaper How to use Git Hooks to set Created and Modified Dates | AstroPaper AstroPaper 3.0 | AstroPaper How to update dependencies of AstroPaper | AstroPaper AstroPaper 2.0 | AstroPaper Predefined color schemes | AstroPaper Customizing AstroPaper theme color schemes | AstroPaper Adding new posts in AstroPaper theme | AstroPaper How to configure AstroPaper theme | AstroPaper Tailwind Typography Plugin | AstroPaper How Do I Develop My Terminal Portfolio Website with React | AstroPaper How Do I Develop My Portfolio Website & Blog | AstroPaper
Dynamic OG image generation in AstroPaper blog posts | AstroPaper
Sat Naing · 2022-12-28 · via AstroPaper

New feature in AstroPaper v1.4.0, introducing dynamic OG image generation for blog posts.

Dynamic OG image generation in AstroPaper blog posts

Table of contents

Open Table of contents
  • Intro
  • Default/Static OG image (the old way)
  • Dynamic OG Image
  • Anatomy of AstroPaper dynamic OG image
    • Issue with Non-Latin Characters

Intro

OG images (aka Social Images) play an important role in social media engagements. In case you don’t know what OG image means, it is an image displayed whenever we share our website URL on social media such as Facebook, Discord etc.

The Social Image used for Twitter is technically not called OG image. However, in this post, I’ll be using the term OG image for all types of Social Images.

Default/Static OG image (the old way)

AstroPaper already provided a way to add an OG image to a blog post. The author can specify the OG image in the frontmatter ogImage. Even when the author doesn’t define the OG image in the frontmatter, the default OG image will be used as a fallback (in this case public/default-og.jpg). But the problem is that the default OG image is static, which means every blog post that does not include an OG image in the frontmatter will always use the same default OG image despite each post title/content being different from others.

Dynamic OG Image

Generating a dynamic OG image for each post allows the author to avoid specifying an OG image for every single blog post. Besides, this will prevent the fallback OG image from being identical to all blog posts.

In AstroPaper v1.4.0, Vercel’s Satori package is used for dynamic OG image generation.

In AstroPaper v6+, the same idea remains (Satori renders SVG, then PNG is produced via Sharp), but fonts are sourced from Astro’s Fonts configuration and loaded via experimental_getFontFileURL() so OG generation can reuse the same font pipeline as the site.

Dynamic OG images will be generated at build time for blog posts that:

  • don’t include OG image in the frontmatter
  • are not marked as draft.

Anatomy of AstroPaper dynamic OG image

Dynamic OG images include the blog post title, author name, and site title. Author name and site title are retrieved from site.author and site.title in astro-paper.config.ts. The title is generated from the blog post frontmatter title.

Example Dynamic OG Image link

Issue with Non-Latin Characters

Titles with non-latin characters won’t display properly out of the box. Switch the Google font family to one that covers your writing system, and include both 400 and 700 weights — Satori uses separate buffers for regular and bold, so missing either causes mismatched rendering.

import { defineConfig, fontProviders } from "astro/config";

export default defineConfig({
  fonts: [
    {
      // Example: Japanese coverage (pick what you need for your audience)
      name: "Noto Sans JP",
      cssVariable: "--font-google-sans-code",
      provider: fontProviders.google(),
      fallbacks: ["monospace"],
      weights: [400, 700],
      styles: ["normal", "italic"],
      formats: ["woff", "ttf"],
    },
  ],
});astro.config.ts

If you change cssVariable, also update the matching key in:

  • src/pages/og.png.ts
  • src/pages/posts/[...slug]/index.png.ts

Check out this PR for more info.

  • Build time grows with content volume — one PNG per eligible post is generated at build time. Generation is faster in v6 (PR #632), but on very large sites you can disable it with features.dynamicOgImage: false in astro-paper.config.ts.
  • RTL languages are not supported yet.
  • Emoji in titles can be tricky — some may not render correctly.