repo info widget
This commit is contained in:
parent
024e18ad32
commit
3b489d6146
|
@ -26,7 +26,7 @@ sidebar:
|
|||
# Sidebar widgets
|
||||
widgets:
|
||||
# default layout in home/wiki/categories/tags/archives pages
|
||||
default: # [welcome, recent]
|
||||
default_layout: [welcome, recent]
|
||||
# Recent update
|
||||
recent:
|
||||
layout: recent
|
||||
|
|
|
@ -2,13 +2,27 @@
|
|||
// 默认组件
|
||||
if (page.sidebar == undefined) {
|
||||
if (page.layout == 'post' && page.content) {
|
||||
page.sidebar = ['toc'];
|
||||
page.sidebar = ['toc', 'repo_info'];
|
||||
} else if (page.layout == 'wiki' && page.content) {
|
||||
page.sidebar = ['toc', 'wiki_more'];
|
||||
page.sidebar = ['toc', 'repo_info', 'wiki_more'];
|
||||
} else {
|
||||
page.sidebar = theme.sidebar.widgets.default;
|
||||
page.sidebar = theme.sidebar.widgets.default_layout;
|
||||
}
|
||||
}
|
||||
function layoutWidgets() {
|
||||
var el = '';
|
||||
el += '<div class="widgets">';
|
||||
if (page.sidebar) {
|
||||
page.sidebar.forEach((w, i) => {
|
||||
if (w in theme.sidebar.widgets) {
|
||||
let widget = theme.sidebar.widgets[w];
|
||||
el += partial('widgets/' + widget.layout, {item: widget});
|
||||
}
|
||||
});
|
||||
}
|
||||
el += '</div>';
|
||||
return el;
|
||||
}
|
||||
function layoutFooterDiv() {
|
||||
if (theme.footer.social && theme.footer.social.length > 0) {
|
||||
var el = '<footer class="footer dis-select">';
|
||||
|
@ -16,14 +30,14 @@ function layoutFooterDiv() {
|
|||
const proj = theme.wiki.projects[page.wiki];
|
||||
if (proj.repo) {
|
||||
el += '<div class="proj-wrap">';
|
||||
el += '<a class="item"';
|
||||
el += ' title="GitHub"';
|
||||
el += ' href="' + url_for("https://github.com/" + proj.repo) + '"';
|
||||
el += ' target="_blank" rel="external nofollow noopener noreferrer"';
|
||||
el += '>';
|
||||
el += '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>';
|
||||
el += 'GitHub';
|
||||
el += '</a>';
|
||||
el += '<a class="item"';
|
||||
el += ' title="GitHub"';
|
||||
el += ' href="' + url_for("https://github.com/" + proj.repo) + '"';
|
||||
el += ' target="_blank" rel="external nofollow noopener noreferrer"';
|
||||
el += '>';
|
||||
el += '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>';
|
||||
el += 'GitHub';
|
||||
el += '</a>';
|
||||
el += '</div>';
|
||||
}
|
||||
} else {
|
||||
|
@ -60,12 +74,5 @@ function layoutFooterDiv() {
|
|||
}
|
||||
%>
|
||||
<%- partial('header', {where: 'sidebar'}) %>
|
||||
<div class='widgets'>
|
||||
<% page.sidebar.forEach(function(widget){ %>
|
||||
<% if (widget in theme.sidebar.widgets) { %>
|
||||
<% let w = theme.sidebar.widgets[widget]; %>
|
||||
<%- partial('widgets/' + w.layout, {item: w}) %>
|
||||
<% } %>
|
||||
<% }) %>
|
||||
</div>
|
||||
<%- layoutWidgets() %>
|
||||
<%- layoutFooterDiv() %>
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<%
|
||||
function layoutDiv() {
|
||||
var el = '';
|
||||
var repo;
|
||||
var branch = 'main';
|
||||
if (page.layout === 'wiki' && page.wiki) {
|
||||
let proj = theme.wiki.projects[page.wiki];
|
||||
if (proj && proj.repo) {
|
||||
repo = proj.repo;
|
||||
if (proj.branch !== undefined) {
|
||||
branch = proj.branch;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 其它的如果有设置 repo 也可以
|
||||
repo = page.repo;
|
||||
}
|
||||
if (repo === undefined) {
|
||||
return el;
|
||||
}
|
||||
// 布局
|
||||
el += '<div class="widget-wrap" id="repo-info">';
|
||||
el += '<div class="widget-body fs14">';
|
||||
var items = [];
|
||||
// Readme
|
||||
items.push({
|
||||
icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M0 1.75A.75.75 0 01.75 1h4.253c1.227 0 2.317.59 3 1.501A3.744 3.744 0 0111.006 1h4.245a.75.75 0 01.75.75v10.5a.75.75 0 01-.75.75h-4.507a2.25 2.25 0 00-1.591.659l-.622.621a.75.75 0 01-1.06 0l-.622-.621A2.25 2.25 0 005.258 13H.75a.75.75 0 01-.75-.75V1.75zm8.755 3a2.25 2.25 0 012.25-2.25H14.5v9h-3.757c-.71 0-1.4.201-1.992.572l.004-7.322zm-1.504 7.324l.004-5.073-.002-2.253A2.25 2.25 0 005.003 2.5H1.5v9h3.757a3.75 3.75 0 011.994.574z"></path></svg>',
|
||||
text: 'Readme',
|
||||
href: 'https://github.com/' + repo + '#readme'
|
||||
});
|
||||
// Releases
|
||||
items.push({
|
||||
icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M2.5 7.775V2.75a.25.25 0 01.25-.25h5.025a.25.25 0 01.177.073l6.25 6.25a.25.25 0 010 .354l-5.025 5.025a.25.25 0 01-.354 0l-6.25-6.25a.25.25 0 01-.073-.177zm-1.5 0V2.75C1 1.784 1.784 1 2.75 1h5.025c.464 0 .91.184 1.238.513l6.25 6.25a1.75 1.75 0 010 2.474l-5.026 5.026a1.75 1.75 0 01-2.474 0l-6.25-6.25A1.75 1.75 0 011 7.775zM6 5a1 1 0 100 2 1 1 0 000-2z"></path></svg>',
|
||||
text: 'Releases',
|
||||
href: 'https://github.com/' + repo + '/releases'
|
||||
});
|
||||
// Download
|
||||
items.push({
|
||||
icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M7.47 10.78a.75.75 0 001.06 0l3.75-3.75a.75.75 0 00-1.06-1.06L8.75 8.44V1.75a.75.75 0 00-1.5 0v6.69L4.78 5.97a.75.75 0 00-1.06 1.06l3.75 3.75zM3.75 13a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5z"></path></svg>',
|
||||
text: 'Download',
|
||||
href: 'https://github.com/' + repo + '/archive/refs/heads/' + branch + '.zip'
|
||||
});
|
||||
// Issues
|
||||
items.push({
|
||||
icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path d="M8 9.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3z"></path><path fill-rule="evenodd" d="M8 0a8 8 0 100 16A8 8 0 008 0zM1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0z"></path></svg>',
|
||||
text: 'Issues',
|
||||
href: 'https://github.com/' + repo + '/issues'
|
||||
});
|
||||
items.forEach((item, i) => {
|
||||
el += '<div class="item"><a class="item-link"';
|
||||
el += ' title="' + item.href + '"';
|
||||
el += ' href="' + url_for(item.href) + '"';
|
||||
el += ' target="_blank" rel="external nofollow noopener noreferrer"';
|
||||
el += '>';
|
||||
el += item.icon;
|
||||
el += item.text;
|
||||
el += '</a></div>';
|
||||
});
|
||||
el += '</div>';
|
||||
el += '</div>';
|
||||
return el;
|
||||
}
|
||||
%>
|
||||
<%- layoutDiv() %>
|
|
@ -32,14 +32,14 @@ module.exports = hexo => {
|
|||
}
|
||||
|
||||
// default menu
|
||||
if (hexo.theme.config.sidebar.menu == undefined) {
|
||||
if (hexo.theme.config.sidebar.menu === undefined) {
|
||||
hexo.theme.config.sidebar.menu = [];
|
||||
}
|
||||
// default widgets
|
||||
if (hexo.theme.config.sidebar.widgets.default == undefined) {
|
||||
hexo.theme.config.sidebar.widgets.default = ['welcome', 'recent'];
|
||||
if (hexo.theme.config.sidebar.widgets.repo_info === undefined) {
|
||||
hexo.theme.config.sidebar.widgets.repo_info = {layout: 'repo_info'};
|
||||
}
|
||||
if (hexo.theme.config.sidebar.widgets.wiki_more == undefined) {
|
||||
if (hexo.theme.config.sidebar.widgets.wiki_more === undefined) {
|
||||
hexo.theme.config.sidebar.widgets.wiki_more = {layout: 'wiki_more'};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
.widget-wrap#repo-info
|
||||
.widget-body
|
||||
.item
|
||||
margin: .25rem 0
|
||||
a
|
||||
color: var(--text-p2)
|
||||
font-weight: 500
|
||||
display: inline-flex
|
||||
align-items: center
|
||||
line-height: 1.8
|
||||
padding: 0 .5rem
|
||||
border-radius: 4px
|
||||
svg
|
||||
margin-right: .5rem
|
||||
width: 1rem
|
||||
a:hover
|
||||
color: var(--text-p1)
|
||||
background: var(--block-hover)
|
Loading…
Reference in New Issue