• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generate a TwitterCard(OGP) image for your Hugo posts.

Twitter Card Image Generator

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.

sample

Installation

Go version < 1.16

go get github.com/Ladicle/tcardgen@latest

Go 1.16+

go install github.com/Ladicle/tcardgen@latest

Getting Started

  1. Install tcardgen command
  2. Download your favorite TrueType fonts (the above sample use KintoSans)
  3. Create template image (The easyest way is to replace the author image of the template in the example directory.)
  4. Run the following command

NOTE: tcardgen parses a font style from the file name, so the font file must follow the naming rule (<name>-<style>.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/*.md

After successfully executing the command, a PNG image with the same name as the specified content name is generated in the output directory.

Advanced Generation

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.png

Result

OGP setting for Hugo Theme

On 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.

<!-- General -->
<meta property="og:url" content="{{ .Permalink }}" />
<meta property="og:type" content="{{ if .IsHome }}website{{ else }}article{{ end }}" />
<meta property="og:site_name" content="{{ .Site.Title }}" />
<meta property="og:title" content="{{ .Title }}" />
<meta property="og:description" content="{{ with .Description -}}{{ . }}{{ else -}}{{ if .IsPage }}{{ substr .Summary 0 300 }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}" />
<meta property="og:image" content="{{ if .Params.thumbnail -}}{{ .Params.thumbnail|absURL }}{{ else if hasPrefix .File.Path "post" -}}{{ path.Join "tcard" (print .File.BaseFileName ".png") | absURL }}{{ else -}}{{ "img/default.png" | absURL }}{{ end -}}" />
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@{{ .Site.Params.twitterName }}" />

Generate images of updated articles

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

Usage

$ tcardgen -h
Generate TwitterCard(OGP) images for your Hugo posts.
Supported front-matters are title, author, categories, tags, and date.

Usage:
  tcardgen [-f <FONTDIR>] [-o <OUTPUT>] [-t <TEMPLATE>] [-c <CONFIG>] <FILE>...

Examples:
# Generate a image and output to the example directory.
tcardgen --fontDir=font --output=example --template=example/template.png example/blog-post.md

# Generate a image and output to the example directory as "featured.png".
tcardgen --fontDir=font --output=example/featured.png --template=example/template.png example/blog-post.md

# Generate multiple images.
tcardgen --template=example/template.png example/*.md

# Genrate an image based on the drawing configuration.
tcardgen --config=config.yaml example/*.md

Flags:
  -c, --config string     Set a drawing configuration file.
  -f, --fontDir string    Set a font directory. (default "font")
  -h, --help              help for tcardgen
      --outDir string     (DEPRECATED) Set an output directory.
  -o, --output string     Set an output directory or filename (only png format). (default "out")
  -t, --template string   Set a template image file. (default example/template.png)

More Repositories

1

kubectl-rolesum

Summarize Kubernetes RBAC roles for the specified subjects.
Go
300
star
2

hydra-posframe

hydra-posframe is a hydra extension which shows hydra hints on posframe.
Emacs Lisp
120
star
3

fish-kubectl-prompt

Display information about the kubectl current context and namespace in fish prompt.
Shell
60
star
4

flymake-posframe

Showing flymake diagnostics at point using posframe
Emacs Lisp
29
star
5

mastodon-chart

The kubernetes chart of Mastodon
Smarty
17
star
6

consult-tramp

consult-tramp is a command to select tramp targets. Supported completion sources are ssh config, known hosts, and docker containers.
Emacs Lisp
15
star
7

godic

codic command line tool
Go
6
star
8

emoji

Slack emoji project
5
star
9

kubectl-check

Check kubernetes resources.
Go
4
star
10

hack

hack is a CLI tool for supporting programming competitions
Go
3
star
11

crd-sample

Shell
3
star
12

pocket2org

gets all articles and creates org tasks
Go
3
star
13

git-prompt

my cute fish prompt ;)
Go
2
star
14

kubernetes-helm-jp-doc

Kubernetes helm Japanese document
2
star
15

denon-avr

Operate Denon AVR via http API
Go
2
star
16

gin-template-for-azure

Sample application using Gin (golang web framework) for Azure Web App
HTML
2
star
17

http-handson

Sample HTTP server was written by Go
HTML
2
star
18

gflow

Light weight workflow engine written in Go.
Go
2
star
19

codecrafters-grep-go

Go
1
star
20

minnano-container

「みんなのDocker/Kubernetes」のDockerfileとサンプルコード
Dockerfile
1
star
21

tabwriter

Drop in replacement for https://golang.org/pkg/text/tabwriter with additional features
Go
1
star
22

Messenger-Beta

messenger on command prompt
C
1
star
23

eitanjiro

'eitanjiro' get your word list of eijiro pro that use selenium
Python
1
star
24

homebrew-gopls

Homebrew formula for Go Language Server (gopls)
Ruby
1
star
25

ghctl

The ghctl CLI tool for GitHub notifications, issue and pull-requests.
Go
1
star
26

opencensus-and-jaeger

Sample application to integrate with tracing and logging.
Go
1
star
27

codecrafters-git-go

Go
1
star
28

elastic-stack-for-docker

Run the basic Elastic stack (Elasticsearch, Kibana, Fluentd, Beats) with Docker and Docker-compose.
Shell
1
star
29

codecrafters-docker-go

Go
1
star
30

go-scheme-handler

A macOS application that handles the custom URL scheme `go: //`
Go
1
star