Fix: show partial information about anonymous contributors and fix http cache (#307)
diff --git a/layouts/shortcodes/contributors.html b/layouts/shortcodes/contributors.html
index 949b2d3..14e54e9 100644
--- a/layouts/shortcodes/contributors.html
+++ b/layouts/shortcodes/contributors.html
@@ -42,8 +42,14 @@
<div class="card-body limit">
<ul class="list-style-none d-flex flex-wrap mb-n2">
{{range $index, $element := .contributors}}
- {{if .login}}
- <li class="mb-2 mr-2" data-src="{{.avatar_url}}?s=64&v=4">
+
+ <li class="mb-2 mr-2">
+ {{if eq .type "Anonymous"}}
+ <a>
+ <i class="fas fa-envelope"></i>
+ {{.login }}
+ </a>
+ {{else}}
<a href="{{.html_url}}" target="_blank">
<i class="fab fa-github"></i>
{{.login }}
diff --git a/scripts/team.js b/scripts/team.js
index 0b008b8..22ee241 100644
--- a/scripts/team.js
+++ b/scripts/team.js
@@ -11,13 +11,13 @@
constructor(docsFile, teamFile) {
this.docsFile = docsFile;
this.teamFile = teamFile;
+ this.nativeObject = [];
+ this.logins = {};
}
- nativeObject = []
- ids = {}
-
async init() {
try{
+ console.log('start...');
this.nativeObject = await this.loadYaml(docsFile);
await this.getAllRepoContributors()
await this.writeFile()
@@ -44,7 +44,7 @@
async writeFile() {
const data = {
- totalCount: Object.keys(this.ids).length,
+ totalCount: Object.keys(this.logins).length,
projects: this.nativeObject
}
const yamlString = YAML.stringify(data);
@@ -52,16 +52,6 @@
console.log('team.yml success!');
}
- getUniqueId(list) {
- list.forEach(item => {
- const {id, email,} = item;
- const key = id || email
- if (!this.ids[key]) {
- this.ids[key] = key
- }
- })
- }
-
async loadYaml() {
const data = await new Promise((resolve) => {
YAML.load(this.docsFile, (result) => {
@@ -71,11 +61,23 @@
return data
}
+ handleData(data) {
+ return data
+ .filter((item) => item.type !== 'Bot')
+ .map((item) => {
+ const { type, email } = item;
+ if (type === 'Anonymous') {
+ item.login = email.replace(/(.+)@.+/, '$1**');
+ }
+ this.logins[item.login] = item.login;
+ return item;
+ });
+ }
+
async getRepoContributors({user, repo, page = 1, per_page = 100, list = [], item}) {
- let {data} = await axios.get(`https://api.github.com/repos/${user}/${repo}/contributors?page=${page}&per_page=${per_page}&anon=true`)
- data = data.filter(item => item.type !== 'Bot')
+ let {data} = await axios.get(`https://api.github.com/repos/${user}/${repo}/contributors?page=${page}&per_page=${per_page}&anon=true&t=${new Date().getTime()}`)
+ data = this.handleData(data);
list.push(...data)
- this.getUniqueId(data)
if (data.length === per_page) {
page++;
await this.getRepoContributors({user, repo, page, per_page, list, item})