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

77 lines
2.3 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-11-19 22:04:14 +08:00
page.sidebar = theme.sidebar.widget_layout.post;
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 {
2021-11-19 22:04:14 +08:00
page.sidebar = theme.sidebar.widget_layout.wiki;
2021-07-25 22:47:18 +08:00
}
2021-11-20 01:51:22 +08:00
} else if (is_home() || ['categories', 'tags', 'archives', 'index', '404', undefined].includes(page.layout)) {
2021-11-19 22:04:14 +08:00
page.sidebar = theme.sidebar.widget_layout.index;
} else if (page.layout == 'page') {
page.sidebar = theme.sidebar.widget_layout.page;
2021-02-19 23:33:19 +08:00
} else {
2021-11-19 22:04:14 +08:00
page.sidebar = [];
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-11-19 20:37:42 +08:00
if (page.layout !== 'wiki' && theme.footer.social) {
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">';
2021-11-19 20:37:42 +08:00
for (let id of Object.keys(theme.footer.social)) {
let item = theme.footer.social[id];
2021-07-14 14:54:06 +08:00
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-11-19 20:37:42 +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 '';
}
}
%>
2022-10-05 23:00:52 +08:00
<% if (page.header == undefined || page.header == 'left' || page.header == 'auto') { %>
<%- partial('header', {where: 'sidebar'}) %>
<% } %>
2021-07-04 22:53:55 +08:00
<%- layoutWidgets() %>
2021-03-05 21:37:28 +08:00
<%- layoutFooterDiv() %>