From c571409ecfdc50d50356706ffd68669353a6425f Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Fri, 5 Nov 2021 16:37:00 +0800 Subject: [PATCH] fix issue --- options/locale/locale_en-US.ini | 1 + options/locale/locale_zh-CN.ini | 2 + templates/repo/contributors.tmpl | 97 ++++++++++++++++++++++++++++- templates/repo/home.tmpl | 12 ++-- web_src/js/features/letteravatar.js | 74 ++++++++++++++++++++++ web_src/js/index.js | 2 +- 6 files changed, 180 insertions(+), 8 deletions(-) create mode 100644 web_src/js/features/letteravatar.js diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 7fa8c7a4f..759583242 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -218,6 +218,7 @@ show_only_private = Showing only private show_only_public = Showing only public issues.in_your_repos = In your repositories +contributors = Contributors [explore] repos = Repositories diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 81b4a8459..b01626b2b 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -220,6 +220,8 @@ show_only_public=只显示公开的 issues.in_your_repos=属于该用户项目的 +contributors=贡献者 + [explore] repos=项目 users=用户 diff --git a/templates/repo/contributors.tmpl b/templates/repo/contributors.tmpl index 235ebf23b..4412c1942 100755 --- a/templates/repo/contributors.tmpl +++ b/templates/repo/contributors.tmpl @@ -1,6 +1,101 @@ {{template "base/head" .}} +
{{template "repo/header" .}} - {{template "repo/user_cards" .}} +
+ +
+

+ {{.i18n.Tr "home.contributors"}} ({{len .ContributorInfo}}) +

+
+ {{range .ContributorInfo}} +
+ {{if .UserInfo}} + + {{else if .Email}} + + {{end}} + +
+
+ {{if .UserInfo}} + {{.UserInfo.Name}} + {{else if .Email}} + {{.Email}} + {{end}} +
+ Commits: {{.CommitCnt}} +
+ +
+ + {{end}} + +
+ + {{template "base/paginate" .}} + +
+ + + +
{{template "base/footer" .}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 8648b8b59..cbba6f3ee 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -331,7 +331,7 @@

贡献者 ({{len .ContributorInfo}})

@@ -353,10 +353,10 @@
{{template "base/footer" .}} diff --git a/web_src/js/features/letteravatar.js b/web_src/js/features/letteravatar.js new file mode 100644 index 000000000..9ec12b60f --- /dev/null +++ b/web_src/js/features/letteravatar.js @@ -0,0 +1,74 @@ +/** + * LetterAvatar + * + * Artur Heinze + * Create Letter avatar based on Initials + * based on https://gist.github.com/leecrossley/6027780 + */ +(function(w, d){ + function LetterAvatar (name, size, color) { + name = name || ''; + size = size || 60; + var colours = [ + "#1abc9c", "#2ecc71", "#3498db", "#9b59b6", "#34495e", "#16a085", "#27ae60", "#2980b9", "#8e44ad", "#2c3e50", + "#f1c40f", "#e67e22", "#e74c3c", "#00bcd4", "#95a5a6", "#f39c12", "#d35400", "#c0392b", "#bdc3c7", "#7f8c8d" + ], + nameSplit = String(name).split(' '), + initials, charIndex, colourIndex, canvas, context, dataURI; + if (nameSplit.length == 1) { + initials = nameSplit[0] ? nameSplit[0].charAt(0):'?'; + } else { + initials = nameSplit[0].charAt(0) + nameSplit[1].charAt(0); + } + if (w.devicePixelRatio) { + size = (size * w.devicePixelRatio); + } + + charIndex = (initials == '?' ? 72 : initials.charCodeAt(0)) - 64; + colourIndex = charIndex % 20; + canvas = d.createElement('canvas'); + canvas.width = size; + canvas.height = size; + context = canvas.getContext("2d"); + + context.fillStyle = color ? color : colours[colourIndex - 1]; + context.fillRect (0, 0, canvas.width, canvas.height); + context.font = Math.round(canvas.width/2)+"px 'Microsoft Yahei'"; + context.textAlign = "center"; + context.fillStyle = "#FFF"; + context.fillText(initials, size / 2, size / 1.5); + dataURI = canvas.toDataURL(); + canvas = null; + return dataURI; + } + LetterAvatar.transform = function() { + Array.prototype.forEach.call(d.querySelectorAll('img[avatar]'), function(img, name, color) { + name = img.getAttribute('avatar'); + color = img.getAttribute('color'); + img.src = LetterAvatar(name, img.getAttribute('width'), color); + img.removeAttribute('avatar'); + img.setAttribute('alt', name); + }); + }; + // AMD support + if (typeof define === 'function' && define.amd) { + + define(function () { return LetterAvatar; }); + + // CommonJS and Node.js module support. + } else if (typeof exports !== 'undefined') { + + // Support Node.js specific `module.exports` (which can be a function) + if (typeof module != 'undefined' && module.exports) { + exports = module.exports = LetterAvatar; + } + // But always support CommonJS module 1.1.1 spec (`exports` cannot be a function) + exports.LetterAvatar = LetterAvatar; + } else { + + window.LetterAvatar = LetterAvatar; + d.addEventListener('DOMContentLoaded', function(event) { + LetterAvatar.transform(); + }); + } +})(window, document); \ No newline at end of file diff --git a/web_src/js/index.js b/web_src/js/index.js index 5c6ff188a..a117ee73d 100755 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -4,7 +4,7 @@ import './publicpath.js'; import './polyfills.js'; - +import './features/letteravatar.js' import Vue from 'vue'; import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css';