Lewati ke konten

Customize the Contributor Table

By default, the All Contributors app and CLI create a contributor table that displays seven contributors per row. Each contributor has its own cell in the row containing three items: a 100x100-pixel avatar (which is the contributor’s GitHub profile picture), the contributor’s name (or username if they have no name listed in their GitHub profile), and a row of emojis representing different contribution types they have been credited for. You change the way the table is rendered in the .all-contributorsrc configuration file. After you have made changes to that file, the Bot will apply the new settings the next time it regenerates the table.

How to change the contributor table layout

Section titled “How to change the contributor table layout”

You can modify three table layout options (contributors per row, avatar size, and how contributors are sorted) by adjusting the values in the .all-contributorsrc configuration file. In the following example, the table is modified to show five contributors per row and 80-pixel avatars; contributors are also sorted alphabetically:

{
"contributorsPerLine": 5,
"imageSize": 80,
"contributorsSortAlphabetically": true
}

Without contributorsSortAlphabetically, contributors appear in the order they were added. With it, the table is sorted alphabetically by the person’s full display name (the name field in .all-contributorsrc, which usually comes from their GitHub profile). It is not sorted by first name or last name separately. If someone has no name, their GitHub username (login) is used instead.

If you want to provide a link in the last row of the contributor table with instructions for contributors to add their own contributions, set linkToUsage to true. This link is hidden by default unless you add it as a setting.

{
"linkToUsage": true
}

If you are using the CLI, you can use the types option to add your own contribution types, modify the emoji used to represent the contribution, or modify the symbol, description, or link for emoji types that already exist. Each key in the JSON structure is the name of the contribution type. Below you add a new type called mapping. The value lets you specify the symbol for that type (often an emoji), a description, and a link. The link value is optional. You can use it as a template for the address the emoji points to, and it can use symbol, description, contributor, and options:

{
"types": {
"mapping": {
"symbol": "🗺️",
"description": "Mapping",
"link": "https://example.org/maps?author=<%= contributor.login %>"
}
}
}

Customize the contributors table and badge

Section titled “Customize the contributors table and badge”

You can change how All Contributors writes the contributors table and badge into your README file (or any other file listed in files). You can:

  • Change the badge color
  • Remove avatars or resize them
  • Change how names and emojis are laid out
  • Restyle the table

To make these changes, add the following options to .all-contributorsrc:

  • contributorTemplate: the cell for one contributor
  • wrapperTemplate: the table that holds all the cells
  • badgeTemplate: the badge between the badge markers

These options only change the code that is written to create the contributor table. They don’t change how the Bot replies in issues or pull requests.

The badge color is part of the badge URL. The example below changes the badge to blue. You can use any color name or hex code (without the #):

{
"badgeTemplate": "[![All Contributors](https://img.shields.io/badge/all_contributors-<%= contributors.length %>-blue.svg?style=flat-square)](#contributors-)"
}

The badge is a shields.io image, so you can also change style=flat-square to flat, for-the-badge, and other standard shields.io styles. Here are a few examples with different colors and styles (the number is only a sample). Each block shows the markdown first, then how that badge renders:

Default orange, flat-square:

[![All Contributors](https://img.shields.io/badge/all_contributors-42-orange.svg?style=flat-square)](#contributors-)

All Contributors

Blue, flat-square:

[![All Contributors](https://img.shields.io/badge/all_contributors-42-blue.svg?style=flat-square)](#contributors-)

All Contributors

Bright green, flat:

[![All Contributors](https://img.shields.io/badge/all_contributors-42-brightgreen.svg?style=flat)](#contributors-)

All Contributors

Purple, for-the-badge:

[![All Contributors](https://img.shields.io/badge/all_contributors-42-purple.svg?style=for-the-badge)](#contributors-)

All Contributors

Hex color ee8449, plastic:

[![All Contributors](https://img.shields.io/badge/all_contributors-42-ee8449.svg?style=plastic)](#contributors-)

All Contributors

By default, each contributor looks like this:

<a href="https://github.com/jsmith">
<img src="https://avatars.githubusercontent.com/u/1?v=4" width="100px" alt="Jane Smith"/>
<br /><sub><b>Jane Smith</b></sub>
</a>
<br />💻 📖

To show only the name and emojis, add this to .all-contributorsrc:

{
"contributorTemplate": "<a href=\"<%= contributor.profile %>\"><b><%= contributor.name %></b></a> <%= contributions %>"
}

The result:

<a href="https://github.com/jsmith"><b>Jane Smith</b></a> 💻 📖

To make small changes, copy the default template and edit it. This template reproduces the default cell. It must stay on one line in JSON:

{
"contributorTemplate": "<a href=\"<%= contributor.profile %>\"><img src=\"<%= contributor.avatar_url %>\" width=\"<%= options.imageSize %>px\" alt=\"<%= contributor.name %>\"/><br /><sub><b><%= contributor.name %></b></sub></a><br /><%= contributions %>"
}

For full control, contributorTemplate, wrapperTemplate, and badgeTemplate replace the default HTML and badge text that All Contributors writes into your README (or other files listed in files). Each template is a string with \<%= value %> placeholders, and each option has its own placeholders:

Pilihan Placeholders What it replaces
contributorTemplate contributor, contributions, options The cell of one contributor
wrapperTemplate bodyContent, tableFooterContent The table around all rows
badgeTemplate contributors The badge between the badge markers

What the placeholders hold:

  • contributor: the login, name, avatar_url, and profile of the person
  • contributions: the row of emoji links, already formatted
  • options: your .all-contributorsrc configuration
  • bodyContent: all the contributor cells
  • tableFooterContent: the table footer
  • contributors: the list of contributors

Templates can’t use any value that isn’t listed here. For example, the badge template doesn’t know your repository name, so a badge for a particular repository has to spell the name out. Update the badge shows this.