Skip to content

Commit a3709bb

Browse files
authored
feat: update readme (zoo-js#76)
* add more pets * fix num * feat: update readme * feat: add update readme * delete test * add number * change path * change * update temp * test 6 * test * fix await * update
1 parent 5c4d6aa commit a3709bb

File tree

7 files changed

+664
-117
lines changed

7 files changed

+664
-117
lines changed

README.en-US.md

+245-54
Large diffs are not rendered by default.

README.md

+246-55
Large diffs are not rendered by default.

active-script/update-readme.js

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// node ./active-script/update-readme.js
2+
const { readFileSync, writeFileSync } = require('fs');
3+
const axios = require('axios');
4+
const { format } = require('prettier');
5+
const { stripIndent } = require('common-tags');
6+
7+
const url = 'https://raw.githubusercontent.com/zoo-js/zoo-data/main/json/organizations.json';
8+
var organizations = [];
9+
10+
function main() {
11+
const baseReadme = readFileSync('./base/README.base.md', { encoding:'utf8', flag:'r' });
12+
const baseReadmeEn = readFileSync('./base/README.en-US.base.md', { encoding:'utf8', flag:'r' });
13+
if (organizations.length == 0) {
14+
console.log(`❌ Get organizations error`);
15+
return false;
16+
}
17+
let content = '';
18+
let row = organizations.length / 6;
19+
const lastNo = organizations.length % 6;
20+
if (lastNo != 0) row += 1;
21+
for (var j = 1; j <= row; j++) {
22+
let data = '';
23+
data = stripIndent`
24+
<tr>
25+
<td align="center">${getFullName(organizations[(j-1)*6])}</td>
26+
<td align="center">${getFullName(organizations[(j-1)*6+1])}</td>
27+
<td align="center">${getFullName(organizations[(j-1)*6+2])}</td>
28+
<td align="center">${getFullName(organizations[(j-1)*6+3])}</td>
29+
<td align="center">${getFullName(organizations[(j-1)*6+4])}</td>
30+
<td align="center">${getFullName(organizations[(j-1)*6+5])}</td>
31+
</tr>
32+
<tr>
33+
<td width="160" align="center">${getCnName(organizations[(j-1)*6])}</td>
34+
<td width="160" align="center">${getCnName(organizations[(j-1)*6+1])}</td>
35+
<td width="160" align="center">${getCnName(organizations[(j-1)*6+2])}</td>
36+
<td width="160" align="center">${getCnName(organizations[(j-1)*6+3])}</td>
37+
<td width="160" align="center">${getCnName(organizations[(j-1)*6+4])}</td>
38+
<td width="160" align="center">${getCnName(organizations[(j-1)*6+5])}</td>
39+
</tr>
40+
`;
41+
content += data
42+
}
43+
44+
let newReadme = baseReadme.replace('UPDATE_README_NUMBER', organizations.length);
45+
newReadme = newReadme.replace('UPDATE_README_TABLE', `<table>${content}</table>`);
46+
const newReadmeFormatted = format(newReadme, {
47+
parser: 'markdown',
48+
});
49+
writeFileSync('./README.md', newReadmeFormatted);
50+
console.log(`🎉 Done readme`);
51+
52+
let newReadmeEn = baseReadmeEn.replace('UPDATE_README_NUMBER', organizations.length);
53+
newReadmeEn = newReadmeEn.replace('UPDATE_README_TABLE', `<table>${content}</table>`);
54+
const newReadmeEnFormatted = format(newReadmeEn, {
55+
parser: 'markdown',
56+
});
57+
writeFileSync('./README.en-US.md', newReadmeEnFormatted);
58+
console.log(`🎉 Done readme-us`);
59+
};
60+
61+
function getFullName(pet) {
62+
if (pet) {
63+
return `<a href="https://github.com/${pet.fullName}" target="_blank"><img src="https://avatars0.githubusercontent.com/u/${pet.code}?s=200&v=4" width="50" /></a>`;
64+
}
65+
return '';
66+
};
67+
68+
function getCnName(pet) {
69+
if (pet) {
70+
return `${pet.name}<br />${pet.cnName}`;
71+
}
72+
return '';
73+
};
74+
75+
async function getOrganizations() {
76+
try {
77+
const res = await axios.get(url);
78+
organizations = res.data.data;
79+
} catch(err) {
80+
console.log(err);
81+
}
82+
};
83+
84+
(async () => {
85+
await getOrganizations();
86+
main();
87+
})();

base/README.base.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 🌈 萌宠乐园
2+
3+
萌宠乐园开业啦,想拥有下面各种萌宠吗?快来领养哦。
4+
5+
简体中文 | [English](./README.en-US.md)
6+
7+
在线预览领取:https://zoo-js.github.io/zoo-issue-helper/
8+
9+
人员分布图表:https://zoo-js.github.io/zoo-charts/
10+
11+
若您心仪的萌宠没在以下列表内,欢迎在 [issue][issue-new] 中提出。
12+
13+
## ✨ 萌宠列表 ( UPDATE_README_NUMBER )
14+
15+
<!-- START -->
16+
17+
UPDATE_README_TABLE
18+
19+
<!-- Created by update-readme.js. -->
20+
<!-- END -->
21+
22+
## 🌟 预览图
23+
24+
![](https://github.com/zoo-js/zoo/blob/main/assets/pets.png?raw=true)
25+
26+
## 💖 目的
27+
28+
- 🎁 为了好玩、好看!
29+
- 🙂 动物是我们的朋友,请爱惜!
30+
- 🌏 我们只有一个世界!
31+
32+
## 💄 如何领养?
33+
34+
新开一个 [issue][issue-new],填写自己想要领养(加入)小萌宠。同时原则上仅支持单人领养 **5只** 小宠物,请大家谨慎挑选。一经挑选,请勿随意抛弃。谢谢大家!
35+
36+
[issue-new]:https://github.com/zoo-js/zoo/issues/new/choose

base/README.en-US.base.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 🌈 Cute pet zoo
2+
3+
The cute pet zoo has opened, do you want to have the cute pets below? Come and adopt it.
4+
5+
[简体中文](./README.md) | English
6+
7+
Preview online collection: https://zoo-js.github.io/zoo-issue-helper/
8+
9+
People distribution charts: https://zoo-js.github.io/zoo-charts/
10+
11+
If your favorite pet is not in the following list, please raise it in the [issue][issue-new].
12+
13+
## ✨ Cute pet list ( UPDATE_README_NUMBER )
14+
15+
<!-- START -->
16+
17+
UPDATE_README_TABLE
18+
19+
<!-- Created by update-readme.js. -->
20+
<!-- END -->
21+
22+
## 🌟 Preview
23+
24+
![](https://github.com/zoo-js/zoo/blob/main/assets/pets.png?raw=true)
25+
26+
## 💖 Purpose
27+
28+
- 🎁 For fun and good-looking!
29+
- 🙂 Animals are our friends, please cherish!
30+
- 🌏 We only have one world!
31+
32+
## 💄 How to adopt?
33+
34+
Open a new [issue][issue-new] and fill in the pet that you want to adopt (join). At the same time, only one person adopts **5** small pets, please choose carefully. Once selected, please do not throw it away. thank you all!
35+
36+
[issue-new]:https://github.com/zoo-js/zoo/issues/new/choose

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{
2+
"name": "zoo",
3+
"scripts": {
4+
"update-readme": "yarn && node ./active-script/update-readme.js"
5+
},
6+
"license": "MIT",
27
"dependencies": {
38
"@actions/core": "^1.2.6",
49
"@octokit/rest": "^18.0.6",
510
"axios": "^0.21.0",
11+
"common-tags": "^1.8.0",
612
"dayjs": "^1.9.4",
7-
"dotenv": "^8.2.0"
13+
"dotenv": "^8.2.0",
14+
"prettier": "^2.1.2"
815
}
916
}

script/auto-invite.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,12 @@ async function invitePeople(email, pet) {
129129
};
130130

131131
async function getOrganizations() {
132-
await axios.get(url).then(res =>{
133-
organizations = res.data.data
134-
},rej => {
135-
core.info(`Get Org ${rej}`);
136-
}).catch(err =>{
137-
core.info(`Get Org ${err}`);
138-
})
132+
try {
133+
const res = await axios.get(url);
134+
organizations = res.data.data;
135+
} catch(err) {
136+
console.log(err);
137+
}
139138
};
140139

141140
function getPetFullName(name) {

0 commit comments

Comments
 (0)