Skip to content
Source
Sign inSign up

Show a good link preview

Code and repositories / Repository settings

Show a good link preview on X, Slack and Discord

A link to your repository in X, Slack or Discord shows only its name and a small owner image, so few people click it. Give the repository a title, a short text and a large image, and every link to it shows that card.

5 min read

Search engines read the same title and text. Your organization can have its own card too (see Set the preview of an organization).

You need the maintain role or more on the repository.

1. Open Search and SEO

Open the repository, then Settings. Click Search and SEO under Repository, and find the card SEO and social preview.

2. Type a title and a description

Type a Title and a Description.

The Preview next to the fields shows the card while you type. An empty Title or Description shows its default in grey: the name or the description of the repository.

3. Add an image

Under Image, add an image with one of the three tabs:

  • Upload: drop a file. It goes into the social/ folder of the assets of the repository, and becomes the image.
  • Pick asset: open a folder of the assets, then click an image.
  • URL: type an https:// URL. To make an image for each page, see Generate an image for each page.
The SEO and social preview card of a repository: a title, a description, an image picked from the assets, and the preview of the link card next to the fields

These fields are optional:

  • Image alt text: what the image shows, for people who cannot see it. Without it, the card uses the title.
  • Card size: Large image shows the image wide, Small image shows it small. By default, the card is large when you set an image.
  • X handle: the X account of the project, with or without the @.

4. Save

Click Save SEO settings. The forge checks the image when you save (see Which images work).

Done

Paste a link to your repository in X, Slack or Discord. The card shows your title, your text and your large image. Each page of the repository shows its own card:

  • The home page: your title and your description. They are also the title of the browser tab and the description that search engines read.
  • Every other page (an issue, a pull request, a file): the title of that page, your description and your image.
  • No image set: a small card with the image of the owner.

Set the preview of an organization

Owners can do this, and members whose role lets them manage the settings.

  1. On the page of the organization, click Manage organization. The General tab opens.
  2. Find the card SEO and social preview.
  3. Type a Title and a Description.
  4. Under Image, open Upload. For the organization acme, click Upload to acme/.github, then drop a file.
  5. Click Save SEO settings.

For an organization, the image tabs and the defaults work like this:

  • Upload: the image goes into the social/ folder of the assets of the repository .github of the organization. If that repository does not exist, the forge makes it, as a public repository.
  • Pick asset: choose a repository of the organization first. The list shows only repositories whose assets everyone can open.
  • Defaults: an empty field uses the display name, the description and the image of the organization.

The card shows for links to the page of the organization. Each repository keeps its own settings.

Generate an image for each page

One image for every link works for the home page. But you want each issue and each pull request to show its own title in the image. If you run an image service that draws a card from a title, give the forge a URL with placeholders.

  1. Open the card SEO and social preview, then the URL tab.
  2. Type a URL with placeholders, for example https://og.example.com/card.png?title={title}&repo={repo}.
  3. Click Save SEO settings.

For each page, the forge puts these values in the URL:

PlaceholderValue
{owner}The name of the owner.
{repo}The name of the repository. It is empty on the page of an organization.
{title}The title of the card. On an issue page, that is the title of the issue and its number.
{description}The description of the card.
{path}The path of the page.

Each value is URL-encoded. For example, https://og.example.com/card.png?path={path} on the page /@acme/app/issues/12 becomes https://og.example.com/card.png?path=%2F%40acme%2Fapp%2Fissues%2F12. A name in braces that is not in this list stays as it is.

From the command line

src repo edit and src profile edit --org take the same --seo-* flags:

src repo edit acme/app --seo-title "Acme App" --seo-description "Rockets for everyone" --seo-image asset:social/card.png
src repo edit acme/app --seo-image-alt "The Acme rocket" --seo-card large --seo-x-handle @acme
src repo edit acme/app --seo-image "https://og.example.com/card.png?path={path}"
src profile edit --org acme --seo-image asset:.github/social/card.png
src repo view acme/app
src profile view acme
  • --seo-image takes an https:// URL, or asset:<path> for an asset of the repository. With --org, it is asset:<repo>/<path>.
  • --seo-card takes large or small.
  • An empty value removes a setting, for example --seo-title "". A flag that you leave out keeps its value.
  • src repo view and src profile view print the settings that are set.

Over REST, PATCH /api/v1/repos/{owner}/{repo} and PATCH /api/v1/orgs/{org} take a seo object, and the GET of each returns it:

{
  "seo": {
    "title": "Acme App",
    "image": { "kind": "asset", "repo": "app", "path": "social/card.png" },
    "card": "large"
  }
}

An image URL is { "kind": "url", "template": "https://..." }. A key that you leave out keeps its value, and null or an empty string removes it. Over MCP, update_repo and update_org_profile take the same seo object.

Reference

Which images work

The forge checks the image when you save. It refuses:

  • An asset of another repository. Use an asset of this repository.
  • An SVG file, because link previews do not show SVG. Use PNG, JPEG, WebP or GIF.
  • A hidden asset.
  • An asset of a private repository whose assets are not public, because a link preview cannot open it. To fix this, turn on Assets are public (see Who can see your assets).
  • A URL that does not start with https://.

Field limits

FieldMaximum
Title120 characters
Description300 characters
Image alt text300 characters
Image URL2048 characters
X handle15 letters, digits or underscores