Skip to content

Commit b41e668

Browse files
authoredSep 28, 2022
feat: add footer with link to usage (#163)
1 parent 7a9150f commit b41e668

File tree

7 files changed

+214
-64
lines changed

7 files changed

+214
-64
lines changed
 

‎.all-contributorsrc

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"repoType": "github",
66
"commit": false,
77
"contributorsPerLine": 6,
8+
"linkToUsage": true,
89
"files": [
910
"README.md"
1011
],

‎README.md

+73-61
Large diffs are not rendered by default.

‎assets/logo-small.svg

+6
Loading

‎src/generate/__tests__/__snapshots__/index.js.snap

+86
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,46 @@ These people contributed to the project:
1818
<td align=\\"center\\">Jeroen Engels is awesome!</td>
1919
</tr>
2020
</tbody>
21+
<tfoot>
22+
23+
</tfoot>
24+
</table>
25+
26+
<!-- markdownlint-restore -->
27+
<!-- prettier-ignore-end -->
28+
29+
<!-- ALL-CONTRIBUTORS-LIST:END -->
30+
31+
Thanks a lot everyone!"
32+
`;
33+
34+
exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors with linkToUsage 1`] = `
35+
"# project
36+
37+
Description
38+
39+
## Contributors
40+
These people contributed to the project:
41+
<!-- ALL-CONTRIBUTORS-LIST:START -->
42+
<!-- prettier-ignore-start -->
43+
<!-- markdownlint-disable -->
44+
<table>
45+
<tbody>
46+
<tr>
47+
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
48+
<td align=\\"center\\">Divjot Singh is awesome!</td>
49+
<td align=\\"center\\">Jeroen Engels is awesome!</td>
50+
</tr>
51+
</tbody>
52+
<tfoot>
53+
<tr>
54+
<td align=\\"center\\" size=\\"13px\\" colspan=\\"5\\">
55+
<img src=\\"https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg\\">
56+
<a href=\\"https://all-contributors.js.org/docs/en/bot/usage\\">Add your contributions</a>
57+
</img>
58+
</td>
59+
</tr>
60+
</tfoot>
2161
</table>
2262
2363
<!-- markdownlint-restore -->
@@ -52,6 +92,52 @@ These people contributed to the project:
5292
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
5393
</tr>
5494
</tbody>
95+
<tfoot>
96+
97+
</tfoot>
98+
</table>
99+
100+
<!-- markdownlint-restore -->
101+
<!-- prettier-ignore-end -->
102+
103+
<!-- ALL-CONTRIBUTORS-LIST:END -->
104+
105+
Thanks a lot everyone!"
106+
`;
107+
108+
exports[`split contributors into multiples lines when there are too many with linkToUsage 1`] = `
109+
"# project
110+
111+
Description
112+
113+
## Contributors
114+
These people contributed to the project:
115+
<!-- ALL-CONTRIBUTORS-LIST:START -->
116+
<!-- prettier-ignore-start -->
117+
<!-- markdownlint-disable -->
118+
<table>
119+
<tbody>
120+
<tr>
121+
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
122+
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
123+
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
124+
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
125+
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
126+
</tr>
127+
<tr>
128+
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
129+
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
130+
</tr>
131+
</tbody>
132+
<tfoot>
133+
<tr>
134+
<td align=\\"center\\" size=\\"13px\\" colspan=\\"5\\">
135+
<img src=\\"https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg\\">
136+
<a href=\\"https://all-contributors.js.org/docs/en/bot/usage\\">Add your contributions</a>
137+
</img>
138+
</td>
139+
</tr>
140+
</tfoot>
55141
</table>
56142
57143
<!-- markdownlint-restore -->

‎src/generate/__tests__/index.js

+26
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of c
4343
expect(result).toMatchSnapshot()
4444
})
4545

46+
test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors with linkToUsage', () => {
47+
const {kentcdodds, bogas04} = contributors
48+
const {options, jfmengels, content} = fixtures()
49+
const contributorList = [kentcdodds, bogas04, jfmengels]
50+
const result = generate(Object.assign(options, { linkToUsage: true }), contributorList, content)
51+
52+
expect(result).toMatchSnapshot()
53+
})
54+
4655
test('split contributors into multiples lines when there are too many', () => {
4756
const {kentcdodds} = contributors
4857
const {options, content} = fixtures()
@@ -60,6 +69,23 @@ test('split contributors into multiples lines when there are too many', () => {
6069
expect(result).toMatchSnapshot()
6170
})
6271

72+
test('split contributors into multiples lines when there are too many with linkToUsage', () => {
73+
const {kentcdodds} = contributors
74+
const {options, content} = fixtures()
75+
const contributorList = [
76+
kentcdodds,
77+
kentcdodds,
78+
kentcdodds,
79+
kentcdodds,
80+
kentcdodds,
81+
kentcdodds,
82+
kentcdodds,
83+
]
84+
const result = generate(Object.assign(options, { linkToUsage: true }), contributorList, content)
85+
86+
expect(result).toMatchSnapshot()
87+
})
88+
6389
test('sorts the list of contributors if contributorsSortAlphabetically=true', () => {
6490
const {kentcdodds, bogas04} = contributors
6591
const {options, jfmengels, content} = fixtures()

‎src/generate/index.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,20 @@ function formatLine(contributors) {
4949
)}</td>`
5050
}
5151

52+
function formatFooter(options) {
53+
if (!options.linkToUsage) {
54+
return ''
55+
}
56+
const smallLogoURL =
57+
'https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg'
58+
const linkToBotAdd = 'https://all-contributors.js.org/docs/en/bot/usage'
59+
60+
return `<tr>\n <td align="center" size="13px" colspan="${options.contributorsPerLine}">\n <img src="${smallLogoURL}">\n <a href="${linkToBotAdd}">Add your contributions</a>\n </img>\n </td>\n </tr>`
61+
}
62+
5263
function generateContributorsList(options, contributors) {
53-
const contributorsPerLine = options.contributorsPerLine || 7
64+
const tableFooter = formatFooter(options)
65+
5466
return _.flow(
5567
_.sortBy(contributor => {
5668
if (options.contributorsSortAlphabetically) {
@@ -60,11 +72,11 @@ function generateContributorsList(options, contributors) {
6072
_.map(function formatEveryContributor(contributor) {
6173
return formatContributor(options, contributor)
6274
}),
63-
_.chunk(contributorsPerLine),
75+
_.chunk(options.contributorsPerLine),
6476
_.map(formatLine),
6577
_.join('\n </tr>\n <tr>\n '),
6678
newContent => {
67-
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n</table>\n\n`
79+
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n <tfoot>\n ${tableFooter}\n </tfoot>\n</table>\n\n`
6880
},
6981
)(contributors)
7082
}

‎src/init/prompt.js

+7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ const questions = [
8686
choices: Object.values(conventions),
8787
default: 'angular',
8888
},
89+
{
90+
type: 'confirm',
91+
name: 'linkToUsage',
92+
message: 'Do you want to add a footer with link to usage?',
93+
default: true,
94+
},
8995
]
9096

9197
const uniqueFiles = _.flow(_.compact, _.uniq)
@@ -113,6 +119,7 @@ module.exports = function prompt() {
113119
commitConvention: answers.commitConvention,
114120
contributors: [],
115121
contributorsPerLine: 7,
122+
linkToUsage: answers.linkToUsage,
116123
},
117124
contributorFile: answers.contributorFile,
118125
badgeFile: answers.badgeFile,

0 commit comments

Comments
 (0)
Please sign in to comment.