fix: cleanup table footer (#341)

This commit is contained in:
Angel Aviel Domaoan 2022-10-06 22:20:28 +08:00 committed by GitHub
parent 8fc7c7e689
commit 0be7a63481
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 9 deletions

View file

@ -18,9 +18,6 @@ These people contributed to the project:
<td align=\\"center\\">Jeroen Engels is awesome!</td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
<!-- markdownlint-restore -->
@ -68,6 +65,34 @@ These people contributed to the project:
Thanks a lot everyone!"
`;
exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors without linkToUsage 1`] = `
"# project
Description
## Contributors
These people contributed to the project:
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Divjot Singh is awesome!</td>
<td align=\\"center\\">Jeroen Engels is awesome!</td>
</tr>
</tbody>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
Thanks a lot everyone!"
`;
exports[`split contributors into multiples lines when there are too many 1`] = `
"# project
@ -92,9 +117,6 @@ These people contributed to the project:
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
<!-- markdownlint-restore -->

View file

@ -47,7 +47,24 @@ test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of c
const {kentcdodds, bogas04} = contributors
const {options, jfmengels, content} = fixtures()
const contributorList = [kentcdodds, bogas04, jfmengels]
const result = generate(Object.assign(options, { linkToUsage: true }), contributorList, content)
const result = generate(
Object.assign(options, {linkToUsage: true}),
contributorList,
content,
)
expect(result).toMatchSnapshot()
})
test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors without linkToUsage', () => {
const {kentcdodds, bogas04} = contributors
const {options, jfmengels, content} = fixtures()
const contributorList = [kentcdodds, bogas04, jfmengels]
const result = generate(
Object.assign(options, {linkToUsage: false}),
contributorList,
content,
)
expect(result).toMatchSnapshot()
})
@ -81,7 +98,11 @@ test('split contributors into multiples lines when there are too many with linkT
kentcdodds,
kentcdodds,
]
const result = generate(Object.assign(options, { linkToUsage: true }), contributorList, content)
const result = generate(
Object.assign(options, {linkToUsage: true}),
contributorList,
content,
)
expect(result).toMatchSnapshot()
})

View file

@ -62,6 +62,7 @@ function formatFooter(options) {
function generateContributorsList(options, contributors) {
const tableFooter = formatFooter(options)
let tableFooterContent = ''
return _.flow(
_.sortBy(contributor => {
@ -76,7 +77,10 @@ function generateContributorsList(options, contributors) {
_.map(formatLine),
_.join('\n </tr>\n <tr>\n '),
newContent => {
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n <tfoot>\n ${tableFooter}\n </tfoot>\n</table>\n\n`
if (options.linkToUsage) {
tableFooterContent = ` <tfoot>\n ${tableFooter}\n </tfoot>\n`
}
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n${tableFooterContent}</table>\n\n`
},
)(contributors)
}