MCPcopy Create free account
hub / github.com/middleapi/orpc / buildSponsorsSection

Function buildSponsorsSection

scripts/sync-sponsor.ts:81–161  ·  view source on GitHub ↗
(sponsors: Sponsor[])

Source from the content-addressed store, hash-verified

79}
80
81function buildSponsorsSection(sponsors: Sponsor[]): string {
82 const activeSponsors = sponsors.filter(sponsor => sponsor.tierLevel > 0 && sponsor.amount > 0)
83 const pastSponsors = sponsors.filter(sponsor => sponsor.tierLevel <= 0 || sponsor.amount <= 0)
84
85 const groupedSponsors = new Map<number, Sponsor[]>()
86
87 for (const sponsor of activeSponsors) {
88 const group = groupedSponsors.get(sponsor.tierLevel)
89
90 if (group) {
91 group.push(sponsor)
92 continue
93 }
94
95 groupedSponsors.set(sponsor.tierLevel, [sponsor])
96 }
97
98 const lines = [
99 '## Sponsors',
100 '',
101 'If you find oRPC valuable and would like to support its development, you can do so here: [GitHub Sponsors](https://github.com/sponsors/dinwwwh).',
102 '',
103 ]
104
105 const tierLevels = [...groupedSponsors.keys()].sort((a, b) => b - a)
106
107 for (const tierLevel of tierLevels) {
108 const tierSponsors = groupedSponsors.get(tierLevel)
109
110 if (!tierSponsors || tierSponsors.length === 0) {
111 continue
112 }
113
114 const tierTitle = tierSponsors[0]?.tierTitle ?? `Tier ${tierLevel}`
115 const [columns, imageSize] = getTierImageSizeAndColumns(tierLevel, tierLevels)
116
117 lines.push(`### ${tierTitle}`)
118 lines.push('')
119 lines.push('<table>')
120 lines.push(' <tr>')
121
122 for (const [index, sponsor] of tierSponsors.entries()) {
123 const href = sponsor.link
124 const displayName = sponsor.name ?? sponsor.login
125 const escapedName = escapeHtml(displayName)
126
127 lines.push(` <td align="center"><a href="${escapeHtml(href)}" target="_blank" rel="noopener" title="${escapedName}"><img src="${escapeHtml(sponsor.avatar)}" width="${imageSize}" alt="${escapedName}"/><br />${escapedName}</a></td>`)
128
129 const isRowEnd = (index + 1) % columns === 0
130 const isLast = index === tierSponsors.length - 1
131
132 if (isRowEnd && !isLast) {
133 lines.push(' </tr>')
134 lines.push(' <tr>')
135 }
136 }
137
138 lines.push(' </tr>')

Callers 1

mainFunction · 0.85

Calls 5

escapeHtmlFunction · 0.85
pushMethod · 0.80
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected