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

63 lines
1.8 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-02-19 23:33:19 +08:00
} else if (page.layout == 'wiki' && page.content) {
2021-07-04 22:53:55 +08:00
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];
el += partial('widgets/' + widget.layout, {item: widget});
}
});
}
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() %>