为您的 Hugo 文章生成 TwitterCard (OGP) 图像。
Generate Twitter card (OGP) images for your blog posts. Supported front-matters are title, author, categories, tags, and date. Also, both toml and yaml formats are supported.
brew install Ladicle/tap/tcardgentcardgen parses a font style from the file name,so the font file must follow the naming rule (
-.ttf), and arrange font files as follows:
$ tree font/
font/
├── KintoSans-Bold.ttf
├── KintoSans-Medium.ttf
└── KintoSans-Regular.ttf
0 directories, 3 files
$ tcardgen -f path/to/fontDir \
-o path/to/hugo/static/imgDir \
-t path/to/templateFile \
path/to/hugo/content/posts/*.mdAfter successfully executing the command, a PNG image with the same name as the specified content name is generated in the output directory.
If you want to change the color, style, or position of text, you can pass a configuration file with the --config(-c) option.
Refer to the example/template3.config.yaml to see how to configure it.
$ tcardgen -c example/template3.config.yaml example/blog-post2.md
Load fonts from "font" directory
Load template from "example/template3.png"
Success to generate twitter card into out/blog-post2.pngOn my blog, I place the generated images in the static/tcard directory. In order to load this image, I set the following OGP information for my blog theme.
If the thumbnail is defined in the post, it is used first. Otherwise, the generated Twitter Card is used. If the page is not blog post, to set the default image.
You can generate only the image of the updated article by using git diff and tcardgen.
$ git diff --name-only HEAD content/post |\
xargs tcardgen -o static/tcard -f assets/fonts/kinto-sans -t assets/template.png…暂无开放 Issues,或尚未同步最近议题。