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:
parent
d23c728a1a
commit
bcec699124
@ -863,6 +863,7 @@ packages/tools/update-readme-download.js
|
|||||||
packages/tools/update-readme-sponsors.js
|
packages/tools/update-readme-sponsors.js
|
||||||
packages/tools/updateMarkdownDoc.js
|
packages/tools/updateMarkdownDoc.js
|
||||||
packages/tools/utils/discourse.js
|
packages/tools/utils/discourse.js
|
||||||
|
packages/tools/utils/loadSponsors.js
|
||||||
packages/tools/utils/translation.js
|
packages/tools/utils/translation.js
|
||||||
packages/tools/website/build.js
|
packages/tools/website/build.js
|
||||||
packages/tools/website/buildTranslations.js
|
packages/tools/website/buildTranslations.js
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -850,6 +850,7 @@ packages/tools/update-readme-download.js
|
|||||||
packages/tools/update-readme-sponsors.js
|
packages/tools/update-readme-sponsors.js
|
||||||
packages/tools/updateMarkdownDoc.js
|
packages/tools/updateMarkdownDoc.js
|
||||||
packages/tools/utils/discourse.js
|
packages/tools/utils/discourse.js
|
||||||
|
packages/tools/utils/loadSponsors.js
|
||||||
packages/tools/utils/translation.js
|
packages/tools/utils/translation.js
|
||||||
packages/tools/website/build.js
|
packages/tools/website/build.js
|
||||||
packages/tools/website/buildTranslations.js
|
packages/tools/website/buildTranslations.js
|
||||||
|
@ -1,43 +1,9 @@
|
|||||||
import { readFile } from 'fs-extra';
|
|
||||||
import { insertContentIntoFile, rootDir } from './tool-utils';
|
import { insertContentIntoFile, rootDir } from './tool-utils';
|
||||||
import markdownUtils, { MarkdownTableHeader, MarkdownTableJustify, MarkdownTableRow } from '@joplin/lib/markdownUtils';
|
import markdownUtils, { MarkdownTableHeader, MarkdownTableJustify, MarkdownTableRow } from '@joplin/lib/markdownUtils';
|
||||||
import { GithubSponsor, GithubUser, OrgSponsor, Sponsors } from './website/utils/types';
|
import { GithubSponsor, loadSponsors, OrgSponsor } from './utils/loadSponsors';
|
||||||
import fetch from 'node-fetch';
|
|
||||||
const { escapeHtml } = require('@joplin/lib/string-utils');
|
const { escapeHtml } = require('@joplin/lib/string-utils');
|
||||||
|
|
||||||
const readmePath = `${rootDir}/README.md`;
|
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> {
|
async function createGitHubSponsorTable(sponsors: GithubSponsor[]): Promise<string> {
|
||||||
sponsors = sponsors.slice();
|
sponsors = sponsors.slice();
|
||||||
@ -70,9 +36,7 @@ async function createGitHubSponsorTable(sponsors: GithubSponsor[]): Promise<stri
|
|||||||
sponsorIndex++;
|
sponsorIndex++;
|
||||||
if (!sponsor) break;
|
if (!sponsor) break;
|
||||||
|
|
||||||
const userResponse = await fetchWithRetry(`https://api.github.com/users/${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})`;
|
||||||
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})`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(row)) rows.push(row);
|
if (Object.keys(row)) rows.push(row);
|
||||||
@ -94,7 +58,7 @@ async function createOrgSponsorTable(sponsors: OrgSponsor[]): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const sponsors: Sponsors = JSON.parse(await readFile(sponsorsPath, 'utf8'));
|
const sponsors = await loadSponsors();
|
||||||
|
|
||||||
await insertContentIntoFile(
|
await insertContentIntoFile(
|
||||||
readmePath,
|
readmePath,
|
||||||
|
39
packages/tools/utils/loadSponsors.ts
Normal file
39
packages/tools/utils/loadSponsors.ts
Normal 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;
|
||||||
|
};
|
@ -2,7 +2,7 @@ import { readFileSync, readFile, mkdirpSync, writeFileSync, remove, copy, pathEx
|
|||||||
import { rootDir } from '../tool-utils';
|
import { rootDir } from '../tool-utils';
|
||||||
import { pressCarouselItems } from './utils/pressCarousel';
|
import { pressCarouselItems } from './utils/pressCarousel';
|
||||||
import { getMarkdownIt, loadMustachePartials, markdownToPageHtml, renderMustache } from './utils/render';
|
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 { createFeatureTableMd, getPlans, loadStripeConfig } from '@joplin/lib/utils/joplinCloud';
|
||||||
import { stripOffFrontMatter } from './utils/frontMatter';
|
import { stripOffFrontMatter } from './utils/frontMatter';
|
||||||
import { dirname, basename } from 'path';
|
import { dirname, basename } from 'path';
|
||||||
@ -13,6 +13,7 @@ import { getNewsDateString } from './utils/news';
|
|||||||
import { parsePoFile, parseTranslations, Translations } from '../utils/translation';
|
import { parsePoFile, parseTranslations, Translations } from '../utils/translation';
|
||||||
import { countryCodeOnly, setLocale } from '@joplin/lib/locale';
|
import { countryCodeOnly, setLocale } from '@joplin/lib/locale';
|
||||||
import applyTranslations from './utils/applyTranslations';
|
import applyTranslations from './utils/applyTranslations';
|
||||||
|
import { loadSponsors } from '../utils/loadSponsors';
|
||||||
|
|
||||||
interface BuildConfig {
|
interface BuildConfig {
|
||||||
env: Env;
|
env: Env;
|
||||||
@ -175,16 +176,6 @@ function makeHomePageMd() {
|
|||||||
return md;
|
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 processNewsMarkdown = (md: string, mdFilePath: string): string => {
|
||||||
const info = stripOffFrontMatter(md);
|
const info = stripOffFrontMatter(md);
|
||||||
md = info.doc.trim();
|
md = info.doc.trim();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Plan, StripePublicConfig } from '@joplin/lib/utils/joplinCloud';
|
import { Plan, StripePublicConfig } from '@joplin/lib/utils/joplinCloud';
|
||||||
|
import { Sponsors } from '../../utils/loadSponsors';
|
||||||
import { OpenGraphTags } from './openGraph';
|
import { OpenGraphTags } from './openGraph';
|
||||||
|
|
||||||
export enum Env {
|
export enum Env {
|
||||||
@ -6,26 +7,10 @@ export enum Env {
|
|||||||
Prod = 'prod',
|
Prod = 'prod',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GithubSponsor {
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GithubUser {
|
export interface GithubUser {
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OrgSponsor {
|
|
||||||
url: string;
|
|
||||||
urlWebsite?: string;
|
|
||||||
title: string;
|
|
||||||
imageName: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Sponsors {
|
|
||||||
github: GithubSponsor[];
|
|
||||||
orgs: OrgSponsor[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PressCarouselItem {
|
interface PressCarouselItem {
|
||||||
active: string;
|
active: string;
|
||||||
body: string;
|
body: string;
|
||||||
|
28
packages/utils/net.ts
Normal file
28
packages/utils/net.ts
Normal 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;
|
||||||
|
};
|
@ -3,7 +3,10 @@
|
|||||||
"version": "2.10.0",
|
"version": "2.10.0",
|
||||||
"description": "Utilities for Joplin",
|
"description": "Utilities for Joplin",
|
||||||
"repository": "https://github.com/laurent22/joplin/tree/dev/packages/utils",
|
"repository": "https://github.com/laurent22/joplin/tree/dev/packages/utils",
|
||||||
"main": "dist/index.js",
|
"exports": {
|
||||||
|
".": "./dist/index.js",
|
||||||
|
"./net": "./dist/net.js"
|
||||||
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
5
packages/utils/time.ts
Normal file
5
packages/utils/time.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/* eslint-disable import/prefer-default-export */
|
||||||
|
|
||||||
|
export const sleep = (ms: number) => {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user