hexo-theme-stellar/layout/_partial/sidebar/index.ejs

70 lines
1.9 KiB
Plaintext
Raw Normal View History

2021-02-19 23:33:19 +08:00
<%
// 默认组件
if (page.sidebar == undefined) {
if (page.layout == 'post' && page.content) {
2021-07-04 22:53:55 +08:00
page.sidebar = ['toc', 'repo_info'];
2021-07-25 22:47:18 +08:00
} else if (page.layout == 'wiki' && page.content && page.wiki) {
let proj = theme.wiki.projects[page.wiki];
if (proj.sidebar) {
page.sidebar = proj.sidebar;
} else {
page.sidebar = ['toc', 'repo_info', 'wiki_more'];
}
2021-02-19 23:33:19 +08:00
} else {
2021-07-04 22:53:55 +08:00
page.sidebar = theme.sidebar.widgets.default_layout;
2021-02-19 23:33:19 +08:00
}
}
2021-07-04 22:53:55 +08:00
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];
2021-08-02 19:23:50 +08:00
if (widget && widget.layout) {
el += partial('widgets/' + widget.layout, {item: widget});
}
2021-07-04 22:53:55 +08:00
}
});
}
el += '</div>';
return el;
}
2021-02-19 23:33:19 +08:00
function layoutFooterDiv() {
2021-07-14 14:54:06 +08:00
if (page.layout !== 'wiki' && theme.footer.social && theme.footer.social.length > 0) {
2021-07-04 21:29:06 +08:00
var el = '<footer class="footer dis-select">';
2021-07-14 14:54:06 +08:00
el += '<div class="social-wrap">';
theme.footer.social.forEach(item => {
if (item.icon && (item.url || item.onclick)) {
el += '<a class="social"';
if (item.title) {
el += ' title="' + item.title + '"';
}
if (item.url) {
el += ' href="' + url_for(item.url) + '"';
if (item.url.includes('://')) {
el += ' target="_blank" rel="external nofollow noopener noreferrer"';
} else {
el += ' rel="noopener noreferrer"';
}
} else if (item.onclick) {
item.onclick = item.onclick.replace(/"|\'/g, '&quot;');
el += ' onclick="' + item.onclick + '"';
}
2021-07-04 22:53:55 +08:00
el += '>';
2021-07-14 14:54:06 +08:00
el += item.icon;
2021-07-04 22:53:55 +08:00
el += '</a>';
2021-07-04 21:29:06 +08:00
}
2021-07-14 14:54:06 +08:00
});
el += '</div>';
2021-07-04 21:29:06 +08:00
el += '</footer>';
2021-02-19 23:33:19 +08:00
return el;
} else {
return '';
}
}
%>
2021-03-05 21:37:28 +08:00
<%- partial('header', {where: 'sidebar'}) %>
2021-07-04 22:53:55 +08:00
<%- layoutWidgets() %>
2021-03-05 21:37:28 +08:00
<%- layoutFooterDiv() %>