From 4239b3fe0ec73190dcca8dca84ca09bc7b919bf8 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Wed, 5 Oct 2022 17:34:16 +0800 Subject: [PATCH] ghinfo --- _config.yml | 1 + layout/_partial/scripts/index.ejs | 1 + layout/_partial/sidebar/widgets/repo_info.ejs | 37 +++++++--- source/css/_common/base.styl | 2 +- source/css/_layout/sidebar/repo_info.styl | 2 +- source/js/main.js | 8 +++ source/js/plugins/friends.js | 1 - source/js/plugins/ghinfo.js | 72 +++++++++++++++++++ 8 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 source/js/plugins/ghinfo.js diff --git a/_config.yml b/_config.yml index 01eab67..a850039 100755 --- a/_config.yml +++ b/_config.yml @@ -272,6 +272,7 @@ plugins: # issues api sitesjs: /js/plugins/sites.js friendsjs: /js/plugins/friends.js + ghinfo: /js/plugins/ghinfo.js ## optional plugins ## # preload diff --git a/layout/_partial/scripts/index.ejs b/layout/_partial/scripts/index.ejs index 7f26f83..0586568 100644 --- a/layout/_partial/scripts/index.ejs +++ b/layout/_partial/scripts/index.ejs @@ -106,6 +106,7 @@ jQuery: '<%- url_for(theme.plugins.jquery || "https://fastly.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js") %>', sitesjs: '<%- url_for(theme.plugins.sitesjs) %>', friendsjs: '<%- url_for(theme.plugins.friendsjs) %>', + ghinfo: '<%- url_for(theme.plugins.ghinfo) %>', }; // optional plugins diff --git a/layout/_partial/sidebar/widgets/repo_info.ejs b/layout/_partial/sidebar/widgets/repo_info.ejs index fe08826..c6e509c 100644 --- a/layout/_partial/sidebar/widgets/repo_info.ejs +++ b/layout/_partial/sidebar/widgets/repo_info.ejs @@ -26,7 +26,7 @@ function layoutDiv() { el += ''; // body el += '
'; - el += '
'; + el += '
'; var items = []; // GitHub items.push({ @@ -34,6 +34,20 @@ function layoutDiv() { text: 'GitHub', href: 'https://github.com/' + repo }); + // Stars + items.push({ + icon: '', + text: 'Stars', + apiKey: 'stargazers_count', + href: 'https://github.com/' + repo + '/stargazers' + }); + // Forks + items.push({ + icon: '', + text: 'Forks', + apiKey: 'forks_count', + href: 'https://github.com/' + repo + '/network/members' + }); // Releases items.push({ icon: '', @@ -43,15 +57,9 @@ function layoutDiv() { // Download items.push({ icon: '', - text: 'Download', + text: 'Download Zip', href: 'https://github.com/' + repo + '/archive/refs/heads/' + branch + '.zip' }); - // Issues - items.push({ - icon: '', - text: 'Issues', - href: 'https://github.com/' + repo + '/issues' - }); items.forEach((item, i) => { el += '
'; el += ''; + el += '
'; + // right + el += '
'; + if (item.apiKey) { + el += ''; + } + if (item.icon) { + el += item.icon; + } + el += '
'; el += '
'; }); el += '
'; diff --git a/source/css/_common/base.styl b/source/css/_common/base.styl index 750dad1..0789201 100644 --- a/source/css/_common/base.styl +++ b/source/css/_common/base.styl @@ -14,7 +14,7 @@ a // md > a p:not([class]), li:not([class]) - >a:not([class]) + a:not([class]) position: relative margin: 0 1px padding: 2px diff --git a/source/css/_layout/sidebar/repo_info.styl b/source/css/_layout/sidebar/repo_info.styl index 42dede2..c48b268 100644 --- a/source/css/_layout/sidebar/repo_info.styl +++ b/source/css/_layout/sidebar/repo_info.styl @@ -20,9 +20,9 @@ padding: 0.5rem .5rem font-size: $fs-13 justify-content: space-between - flex-direction: row-reverse svg width: 1em height: 1em + margin-left: 4px a:hover background: var(--block-hover) diff --git a/source/js/main.js b/source/js/main.js index 3158927..222564e 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -230,6 +230,14 @@ if (stellar.plugins.friendsjs) { }) } } +if (stellar.plugins.ghinfo) { + const issues_api = document.getElementById('ghinfo-api'); + if (issues_api != undefined) { + stellar.jQuery(() => { + stellar.loadScript(stellar.plugins.ghinfo, { defer: true }) + }) + } +} // swiper if (stellar.plugins.swiper) { diff --git a/source/js/plugins/friends.js b/source/js/plugins/friends.js index 0187d3b..2649b07 100644 --- a/source/js/plugins/friends.js +++ b/source/js/plugins/friends.js @@ -48,7 +48,6 @@ const friendsjs = { friendsjs.requestAPI(cfg.api, function(data) { $(el).find('.loading-wrap').remove(); const arr = data.content || data; - console.log(data); arr.forEach((item, i) => { var user = '