1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Doc: Added script to build Sponsors table

This commit is contained in:
Laurent Cozic 2021-05-27 15:24:56 +02:00
parent 907ac7c1f8
commit c0683ca4c3
7 changed files with 192 additions and 14 deletions

View File

@ -1613,4 +1613,7 @@ packages/tools/release-server.js.map
packages/tools/tool-utils.d.ts
packages/tools/tool-utils.js
packages/tools/tool-utils.js.map
packages/tools/update-readme-sponsors.d.ts
packages/tools/update-readme-sponsors.js
packages/tools/update-readme-sponsors.js.map
# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD

3
.gitignore vendored
View File

@ -1599,4 +1599,7 @@ packages/tools/release-server.js.map
packages/tools/tool-utils.d.ts
packages/tools/tool-utils.js
packages/tools/tool-utils.js.map
packages/tools/update-readme-sponsors.d.ts
packages/tools/update-readme-sponsors.js
packages/tools/update-readme-sponsors.js.map
# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD

View File

@ -68,13 +68,15 @@ The Web Clipper is a browser extension that allows you to save web pages and scr
* * *
| | | |
| :---: | :---: | :---: |
| <img width="50" src="https://avatars0.githubusercontent.com/u/6979755?s=96&v=4"/></br>[Devon Zuegel](https://github.com/devonzuegel) | <img width="50" src="https://avatars2.githubusercontent.com/u/24908652?s=96&v=4"/></br>[小西 孝宗](https://github.com/konishi-t) | <img width="50" src="https://avatars2.githubusercontent.com/u/215668?s=96&v=4"/></br>[Alexander van der Berg](https://github.com/avanderberg)
| <img width="50" src="https://avatars0.githubusercontent.com/u/1168659?s=96&v=4"/></br>[Nicholas Head](https://github.com/nicholashead) | <img width="50" src="https://avatars2.githubusercontent.com/u/1439535?s=96&v=4"/></br>[Frank Bloise](https://github.com/fbloise) | <img width="50" src="https://avatars2.githubusercontent.com/u/15859362?s=96&v=4"/></br>[Thomas Broussard](https://github.com/thomasbroussard)
| <img width="50" src="https://avatars2.githubusercontent.com/u/1307332?s=96&v=4"/></br>[Brandon Johnson](https://github.com/dbrandonjohnson) | <img width="50" src="https://avatars1.githubusercontent.com/u/3061769?s=96&v=4"/></br>[@cnagy](https://github.com/c-nagy) | <img width="50" src="https://avatars3.githubusercontent.com/u/53228972?s=96&v=4"/></br>[clmntsl](https://github.com/clmntsl)
| <img width="50" src="https://avatars1.githubusercontent.com/u/29300939?s=96&v=4"/></br>[mcejp](https://github.com/mcejp) | <img width="50" src="https://avatars.githubusercontent.com/u/1248504?s=96&v=4"/></br>[joesfer](https://github.com/joesfer) | <img width="50" src="https://avatars.githubusercontent.com/u/67130?s=96&v=4"/></br>[chr15m](https://github.com/chr15m)
| <img width="50" src="https://avatars.githubusercontent.com/u/5782817?s=96&v=4"/></br>[piccobit](https://github.com/piccobit) | <img width="50" src="https://avatars3.githubusercontent.com/u/37297218?s=96&v=4"/></br>[Jess Sullivan](https://github.com/jesssullivan)
<!-- SPONSORS -->
| | | | |
| :---: | :---: | :---: | :---: |
| <img width="50" src="https://avatars2.githubusercontent.com/u/215668?s=96&v=4"/></br>[avanderberg](https://github.com/avanderberg) | <img width="50" src="https://avatars2.githubusercontent.com/u/3061769?s=96&v=4"/></br>[c-nagy](https://github.com/c-nagy) | <img width="50" src="https://avatars2.githubusercontent.com/u/70780798?s=96&v=4"/></br>[cabottech](https://github.com/cabottech) | <img width="50" src="https://avatars2.githubusercontent.com/u/67130?s=96&v=4"/></br>[chr15m](https://github.com/chr15m) |
| <img width="50" src="https://avatars2.githubusercontent.com/u/4862947?s=96&v=4"/></br>[chrootlogin](https://github.com/chrootlogin) | <img width="50" src="https://avatars2.githubusercontent.com/u/1307332?s=96&v=4"/></br>[dbrandonjohnson](https://github.com/dbrandonjohnson) | <img width="50" src="https://avatars2.githubusercontent.com/u/1439535?s=96&v=4"/></br>[fbloise](https://github.com/fbloise) | <img width="50" src="https://avatars2.githubusercontent.com/u/38898566?s=96&v=4"/></br>[h4sh5](https://github.com/h4sh5) |
| <img width="50" src="https://avatars2.githubusercontent.com/u/37297218?s=96&v=4"/></br>[Jesssullivan](https://github.com/Jesssullivan) | <img width="50" src="https://avatars2.githubusercontent.com/u/1248504?s=96&v=4"/></br>[joesfer](https://github.com/joesfer) | <img width="50" src="https://avatars2.githubusercontent.com/u/24908652?s=96&v=4"/></br>[konishi-t](https://github.com/konishi-t) | <img width="50" src="https://avatars2.githubusercontent.com/u/1788010?s=96&v=4"/></br>[maxtruxa](https://github.com/maxtruxa) |
| <img width="50" src="https://avatars2.githubusercontent.com/u/29300939?s=96&v=4"/></br>[mcejp](https://github.com/mcejp) | <img width="50" src="https://avatars2.githubusercontent.com/u/1168659?s=96&v=4"/></br>[nicholashead](https://github.com/nicholashead) | <img width="50" src="https://avatars2.githubusercontent.com/u/5782817?s=96&v=4"/></br>[piccobit](https://github.com/piccobit) | <img width="50" src="https://avatars2.githubusercontent.com/u/47742?s=96&v=4"/></br>[ravenscroftj](https://github.com/ravenscroftj) |
| <img width="50" src="https://avatars2.githubusercontent.com/u/73081837?s=96&v=4"/></br>[thismarty](https://github.com/thismarty) | <img width="50" src="https://avatars2.githubusercontent.com/u/15859362?s=96&v=4"/></br>[thomasbroussard](https://github.com/thomasbroussard) | <img width="50" src="https://avatars2.githubusercontent.com/u/53228972?s=96&v=4"/></br>[wasteisobscene](https://github.com/wasteisobscene) | |
<!-- SPONSORS -->
<!-- TOC -->
# Table of contents

View File

@ -7,10 +7,18 @@ const MarkdownIt = require('markdown-it');
const listRegex = /^(\s*)([*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]\s))(\s*)/;
const emptyListRegex = /^(\s*)([*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s+)$/;
export enum MarkdownTableJustify {
Left = 'left',
Center = 'center',
Right = 'right,',
}
export interface MarkdownTableHeader {
name: string;
label: string;
filter?: Function;
disableEscape?: boolean;
justify?: MarkdownTableJustify;
}
export interface MarkdownTableRow {
@ -120,26 +128,38 @@ const markdownUtils = {
createMarkdownTable(headers: MarkdownTableHeader[], rows: MarkdownTableRow[]): string {
const output = [];
const minCellWidth = 5;
const headersMd = [];
const lineMd = [];
for (let i = 0; i < headers.length; i++) {
const h = headers[i];
headersMd.push(stringPadding(h.label, 3, ' ', stringPadding.RIGHT));
lineMd.push('---');
headersMd.push(stringPadding(h.label, minCellWidth, ' ', stringPadding.RIGHT));
const justify = h.justify ? h.justify : MarkdownTableJustify.Left;
if (justify === MarkdownTableJustify.Left) {
lineMd.push('-----');
} else if (justify === MarkdownTableJustify.Center) {
lineMd.push(':---:');
} else {
lineMd.push('----:');
}
}
output.push(headersMd.join(' | '));
output.push(lineMd.join(' | '));
output.push(`| ${headersMd.join(' | ')} |`);
output.push(`| ${lineMd.join(' | ')} |`);
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const rowMd = [];
for (let j = 0; j < headers.length; j++) {
const h = headers[j];
const valueMd = markdownUtils.escapeTableCell(h.filter ? h.filter(row[h.name]) : row[h.name]);
rowMd.push(stringPadding(valueMd, 3, ' ', stringPadding.RIGHT));
const value = (h.filter ? h.filter(row[h.name]) : row[h.name]) || '';
const valueMd = h.disableEscape ? value : markdownUtils.escapeTableCell(value);
rowMd.push(stringPadding(valueMd, minCellWidth, ' ', stringPadding.RIGHT));
}
output.push(rowMd.join(' | '));
output.push(`| ${rowMd.join(' | ')} |`);
}
return output.join('\n');

View File

@ -20,6 +20,11 @@ echo "$ROOT_DIR/build-welcome.js..."
echo "---------------------------------------------------"
node "$ROOT_DIR/build-welcome.js"
echo "---------------------------------------------------"
echo "$ROOT_DIR/update-readme-sponsors.js..."
echo "---------------------------------------------------"
node "$ROOT_DIR/update-readme-sponsors.js"
cd "$ROOT_DIR/.."
echo "---------------------------------------------------"
echo "npm run buildWebsite..."

View File

@ -0,0 +1,80 @@
{
"github": [
{
"name": "nicholashead",
"id": "1168659"
},
{
"name": "avanderberg",
"id": "215668"
},
{
"name": "fbloise",
"id": "1439535"
},
{
"name": "thomasbroussard",
"id": "15859362"
},
{
"name": "dbrandonjohnson",
"id": "1307332"
},
{
"name": "c-nagy",
"id": "3061769"
},
{
"name": "wasteisobscene",
"id": "53228972"
},
{
"name": "mcejp",
"id": "29300939"
},
{
"name": "joesfer",
"id": "1248504"
},
{
"name": "chr15m",
"id": "67130"
},
{
"name": "piccobit",
"id": "5782817"
},
{
"name": "chrootlogin",
"id": "4862947"
},
{
"name": "maxtruxa",
"id": "1788010"
},
{
"name": "Jesssullivan",
"id": "37297218"
},
{
"name": "cabottech",
"id": "70780798"
},
{
"name": "h4sh5",
"id": "38898566"
},
{
"name": "ravenscroftj",
"id": "47742"
},
{
"name": "thismarty",
"id": "73081837"
},
{
"name": "konishi-t",
"id": "24908652"
}
]
}

View File

@ -0,0 +1,65 @@
import { readFile } from 'fs-extra';
import { insertContentIntoFile, rootDir } from './tool-utils';
import markdownUtils, { MarkdownTableHeader, MarkdownTableJustify, MarkdownTableRow } from '@joplin/lib/markdownUtils';
const readmePath = `${rootDir}/README.md`;
const sponsorsPath = `${rootDir}/packages/tools/sponsors.json`;
interface Sponsor {
name: string;
id: string;
}
async function main() {
const sponsors: Sponsor[] = (JSON.parse(await readFile(sponsorsPath, 'utf8'))).github;
sponsors.sort((a, b) => {
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : +1;
});
const sponsorsPerRow = 4;
const headers: MarkdownTableHeader[] = [];
for (let colIndex = 0; colIndex < sponsorsPerRow; colIndex++) {
headers.push({
label: '',
name: `col${colIndex}`,
disableEscape: true,
justify: MarkdownTableJustify.Center,
});
}
const rows: MarkdownTableRow[] = [];
let sponsorIndex = 0;
for (let rowIndex = 0; rowIndex < 9999; rowIndex++) {
let sponsor = null;
const row: MarkdownTableRow = {};
for (let colIndex = 0; colIndex < sponsorsPerRow; colIndex++) {
sponsor = sponsors[sponsorIndex];
sponsorIndex++;
if (!sponsor) break;
row[`col${colIndex}`] = `<img width="50" src="https://avatars2.githubusercontent.com/u/${sponsor.id}?s=96&v=4"/></br>[${sponsor.name}](https://github.com/${sponsor.name})`;
}
if (Object.keys(row)) rows.push(row);
if (!sponsor) break;
}
const mdTable = markdownUtils.createMarkdownTable(headers, rows);
await insertContentIntoFile(
readmePath,
'<!-- SPONSORS -->\n',
'\n<!-- SPONSORS -->',
mdTable
);
}
main().catch((error) => {
console.error('Fatal error', error);
process.exit(1);
});