社交卡片(Open Graph)¶
social插件自 v0.0.67 起原生支持,为页面生成社交卡片(social cards)及 Open Graph / Twitter 元数据。分享到微信、X、Slack 等平台时能显示漂亮的预览图。
启用¶
zensical.toml
[project.plugins.social]
先设置 site_url
社交卡片会链接到页面元数据,建议先配置 site_url,否则分享时可能拿不到正确的绝对地址:
[project]
site_url = "https://wcowin.work/Zensical-Chinese-Tutorial/"
官方配置项¶
| 配置项 | 默认值 | 说明 |
|---|---|---|
enabled |
true |
启用社交卡片生成 |
cards |
true |
为页面生成卡片 |
cards_dir |
assets/images/social |
生成卡片的站点目录 |
cards_layout |
default |
卡片布局 |
cards_layout_dir |
layouts |
自定义布局的项目目录 |
cards_layout_options |
{} |
传给布局的值 |
cards_include |
[] |
选择生成卡片的源路径模式 |
cards_exclude |
[] |
排除生成卡片的源路径模式 |
cache |
true |
构建间缓存生成的卡片 |
cache_dir |
.cache/plugin/social |
缓存目录 |
自定义布局¶
在项目中创建 layouts/ 目录并放入自定义布局文件,然后:
[project.plugins.social]
cards_layout = "custom"
cards_layout_dir = "layouts"
[project.plugins.social.cards_layout_options]
title_font = "path/to/font.ttf"
页面级覆盖¶
页面 front matter 可覆盖 cards、cards_layout、cards_layout_options:
docs/某篇文章.md
---
title: 我的文章
social:
cards_layout: custom
cards: true
---
只给部分页面生成¶
[project.plugins.social]
cards_include = ["blog/**/*.md"]
cards_exclude = ["blog/drafts/*.md"]
生成结果¶
构建后在 site/assets/images/social/ 下查看生成的卡片图片,HTML 中会注入 Open Graph / Twitter 元数据。