UNPKG

2.67 kBJavaScriptView Raw
1import { getPeopleHTML, getFileUrl, getLink } from './util.js'
2import { getBadgesInCategory } from './badge.js'
3function getSponsorsText(data) {
4 let result = ''
5 if (data.sponsors.length === 0) {
6 // ignore
7 result +=
8 'No sponsors yet! Will you be the first?\n\n' +
9 getBadgesInCategory('funding', data)
10 } else {
11 result +=
12 'These amazing people have contributed finances to this project:\n\n' +
13 getPeopleHTML(data.sponsors) +
14 `\n\nBecome a sponsor!\n\n${getBadgesInCategory('funding', data)}`
15 }
16 return result
17}
18function getMaintainersText(data) {
19 let result = ''
20 if (data.maintainers.length === 0) {
21 // ignore
22 result += 'No maintainers yet! Will you be the first?'
23 } else {
24 result +=
25 'These amazing people are maintaining this project:\n\n' +
26 getPeopleHTML(data.maintainers, {
27 displayContributions: true,
28 githubRepoSlug: data.github.slug,
29 })
30 }
31 return result
32}
33function getContributeLink(data, optional = false) {
34 // Prepare
35 const file = data.filenamesForReadmeFiles.contributing
36 if (!file) {
37 if (optional) {
38 return ''
39 } else {
40 throw new Error(
41 'Contributing section requires a CONTRIBUTING file to exist'
42 )
43 }
44 }
45 const url = getFileUrl(data, file)
46 const text = `Discover how you can contribute by heading on over to the <code>${file}</code> file.`
47 // Return
48 return getLink({ url, text })
49}
50function getContributorsText(data) {
51 let result = ''
52 if (data.contributors.length === 0) {
53 // ignore
54 result +=
55 'No contributors yet! Will you be the first?' +
56 `\n\n${getContributeLink(data, true)}`
57 } else {
58 result +=
59 'These amazing people have contributed code to this project:\n\n' +
60 getPeopleHTML(data.contributors, {
61 displayContributions: true,
62 githubRepoSlug: data.github.slug,
63 }) +
64 `\n\n${getContributeLink(data, true)}`
65 }
66 return result
67}
68export function getBackerSection(data) {
69 // Prepare
70 const result = [
71 '<h2>Backers</h2>',
72 '',
73 '<h3>Maintainers</h3>',
74 '',
75 getMaintainersText(data),
76 '',
77 '<h3>Sponsors</h3>',
78 '',
79 getSponsorsText(data),
80 '',
81 '<h3>Contributors</h3>',
82 '',
83 getContributorsText(data),
84 ].join('\n')
85 // Return
86 return result
87}
88export function getBackerFile(data) {
89 // Prepare
90 const result = [
91 '<h1>Backers</h1>',
92 '',
93 '<h2>Maintainers</h2>',
94 '',
95 getMaintainersText(data),
96 '',
97 '<h2>Sponsors</h2>',
98 '',
99 getSponsorsText(data),
100 '',
101 '<h2>Contributors</h2>',
102 '',
103 getContributorsText(data),
104 ].join('\n')
105 // Return
106 return result
107}
108export function getContributeSection(data) {
109 // Prepare
110 const result = ['<h2>Contribute</h2>', '', getContributeLink(data)].join('\n')
111 // Return
112 return result
113}