1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-02 12:47:41 +02:00

Doc: Fixed sponsor avatars

This commit is contained in:
Laurent Cozic 2023-03-21 17:29:22 +00:00
parent d23c728a1a
commit bcec699124
9 changed files with 84 additions and 67 deletions

View File

@ -863,6 +863,7 @@ packages/tools/update-readme-download.js
packages/tools/update-readme-sponsors.js
packages/tools/updateMarkdownDoc.js
packages/tools/utils/discourse.js
packages/tools/utils/loadSponsors.js
packages/tools/utils/translation.js
packages/tools/website/build.js
packages/tools/website/buildTranslations.js

1
.gitignore vendored
View File

@ -850,6 +850,7 @@ packages/tools/update-readme-download.js
packages/tools/update-readme-sponsors.js
packages/tools/updateMarkdownDoc.js
packages/tools/utils/discourse.js
packages/tools/utils/loadSponsors.js
packages/tools/utils/translation.js
packages/tools/website/build.js
packages/tools/website/buildTranslations.js

View File

@ -1,43 +1,9 @@
import { readFile } from 'fs-extra';
import { insertContentIntoFile, rootDir } from './tool-utils';
import markdownUtils, { MarkdownTableHeader, MarkdownTableJustify, MarkdownTableRow } from '@joplin/lib/markdownUtils';
import { GithubSponsor, GithubUser, OrgSponsor, Sponsors } from './website/utils/types';
import fetch from 'node-fetch';
import { GithubSponsor, loadSponsors, OrgSponsor } from './utils/loadSponsors';
const { escapeHtml } = require('@joplin/lib/string-utils');
const readmePath = `${rootDir}/README.md`;
const sponsorsPath = `${rootDir}/packages/tools/sponsors.json`;
const sleep = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms));
};
const fetchWithRetry = async (url: string, opts: any = null) => {
if (!opts) opts = {};
let retry = opts && opts.retry || 3;
while (retry > 0) {
try {
return fetch(url, opts);
} catch (e) {
if (opts && opts.callback) {
opts.callback(retry);
}
retry = retry - 1;
if (retry === 0) {
throw e;
}
if (opts && opts.pause) {
if (opts && !opts.silent) console.log('pausing..');
await sleep(opts.pause);
if (opts && !opts.silent) console.log('done pausing...');
}
}
}
return null;
};
async function createGitHubSponsorTable(sponsors: GithubSponsor[]): Promise<string> {
sponsors = sponsors.slice();
@ -70,9 +36,7 @@ async function createGitHubSponsorTable(sponsors: GithubSponsor[]): Promise<stri
sponsorIndex++;
if (!sponsor) break;
const userResponse = await fetchWithRetry(`https://api.github.com/users/${sponsor.name}`);
const user = await userResponse.json() as GithubUser;
row[`col${colIndex}`] = `<img width="50" src="https://avatars2.githubusercontent.com/u/${user.id}?s=96&v=4"/></br>[${sponsor.name}](https://github.com/${sponsor.name})`;
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);
@ -94,7 +58,7 @@ async function createOrgSponsorTable(sponsors: OrgSponsor[]): Promise<string> {
}
async function main() {
const sponsors: Sponsors = JSON.parse(await readFile(sponsorsPath, 'utf8'));
const sponsors = await loadSponsors();
await insertContentIntoFile(
readmePath,

View File

@ -0,0 +1,39 @@
import { readFile } from 'fs-extra';
import { rootDir } from '@joplin/utils';
import { fetchWithRetry } from '@joplin/utils/net';
const sponsorsPath = `${rootDir}/packages/tools/sponsors.json`;
export interface GithubSponsor {
name: string;
id: string;
}
export interface Sponsors {
github: GithubSponsor[];
orgs: OrgSponsor[];
}
export interface OrgSponsor {
url: string;
urlWebsite?: string;
title: string;
imageName: string;
}
export const loadSponsors = async (): Promise<Sponsors> => {
const output: Sponsors = JSON.parse(await readFile(sponsorsPath, 'utf8'));
output.orgs = output.orgs.map(o => {
if (o.urlWebsite) o.url = o.urlWebsite;
return o;
});
for (const ghSponsor of output.github) {
const userResponse = await fetchWithRetry(`https://api.github.com/users/${ghSponsor.name}`);
const user = await userResponse.json();
ghSponsor.id = user.id;
}
return output;
};

View File

@ -2,7 +2,7 @@ import { readFileSync, readFile, mkdirpSync, writeFileSync, remove, copy, pathEx
import { rootDir } from '../tool-utils';
import { pressCarouselItems } from './utils/pressCarousel';
import { getMarkdownIt, loadMustachePartials, markdownToPageHtml, renderMustache } from './utils/render';
import { AssetUrls, Env, Partials, PlanPageParams, Sponsors, TemplateParams } from './utils/types';
import { AssetUrls, Env, Partials, PlanPageParams, TemplateParams } from './utils/types';
import { createFeatureTableMd, getPlans, loadStripeConfig } from '@joplin/lib/utils/joplinCloud';
import { stripOffFrontMatter } from './utils/frontMatter';
import { dirname, basename } from 'path';
@ -13,6 +13,7 @@ import { getNewsDateString } from './utils/news';
import { parsePoFile, parseTranslations, Translations } from '../utils/translation';
import { countryCodeOnly, setLocale } from '@joplin/lib/locale';
import applyTranslations from './utils/applyTranslations';
import { loadSponsors } from '../utils/loadSponsors';
interface BuildConfig {
env: Env;
@ -175,16 +176,6 @@ function makeHomePageMd() {
return md;
}
async function loadSponsors(): Promise<Sponsors> {
const sponsorsPath = `${rootDir}/packages/tools/sponsors.json`;
const output: Sponsors = JSON.parse(await readFile(sponsorsPath, 'utf8'));
output.orgs = output.orgs.map(o => {
if (o.urlWebsite) o.url = o.urlWebsite;
return o;
});
return output;
}
const processNewsMarkdown = (md: string, mdFilePath: string): string => {
const info = stripOffFrontMatter(md);
md = info.doc.trim();

View File

@ -1,4 +1,5 @@
import { Plan, StripePublicConfig } from '@joplin/lib/utils/joplinCloud';
import { Sponsors } from '../../utils/loadSponsors';
import { OpenGraphTags } from './openGraph';
export enum Env {
@ -6,26 +7,10 @@ export enum Env {
Prod = 'prod',
}
export interface GithubSponsor {
name: string;
}
export interface GithubUser {
id: string;
}
export interface OrgSponsor {
url: string;
urlWebsite?: string;
title: string;
imageName: string;
}
export interface Sponsors {
github: GithubSponsor[];
orgs: OrgSponsor[];
}
interface PressCarouselItem {
active: string;
body: string;

28
packages/utils/net.ts Normal file
View File

@ -0,0 +1,28 @@
/* eslint-disable import/prefer-default-export */
import { sleep } from './time';
export const fetchWithRetry = async (url: string, opts: any = null) => {
if (!opts) opts = {};
let retry = opts && opts.retry || 3;
while (retry > 0) {
try {
return fetch(url, opts);
} catch (e) {
if (opts && opts.callback) {
opts.callback(retry);
}
retry = retry - 1;
if (retry === 0) {
throw e;
}
if (opts && opts.pause) {
await sleep(opts.pause);
}
}
}
return null;
};

View File

@ -3,7 +3,10 @@
"version": "2.10.0",
"description": "Utilities for Joplin",
"repository": "https://github.com/laurent22/joplin/tree/dev/packages/utils",
"main": "dist/index.js",
"exports": {
".": "./dist/index.js",
"./net": "./dist/net.js"
},
"publishConfig": {
"access": "public"
},

5
packages/utils/time.ts Normal file
View File

@ -0,0 +1,5 @@
/* eslint-disable import/prefer-default-export */
export const sleep = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms));
};