[feat] create widget in front-matter

This commit is contained in:
xaoxuu 2022-11-22 22:38:01 +08:00
parent 7d10a24a4d
commit 6f48c3f477
2 changed files with 22 additions and 12 deletions

View File

@ -73,11 +73,21 @@ function layoutWidgets() {
} }
if (page.sidebar) { if (page.sidebar) {
page.sidebar.forEach((w, i) => { page.sidebar.forEach((w, i) => {
if (w in theme.data.widgets) { let name = ''
let widget = theme.data.widgets[w]; if (typeof w == 'string') {
if (widget && widget.layout) { name = w
el += partial('widgets/' + widget.layout, {item: widget}); } else if (typeof w == 'object' && w.layout && w.override) {
} name = w.override
}
let widget = {}
if (name in theme.data.widgets) {
Object.assign(widget, theme.data.widgets[name])
}
if (typeof w == 'object' && w.layout) {
Object.assign(widget, w)
}
if (widget && widget.layout) {
el += partial('widgets/' + widget.layout, {item: widget})
} }
}); });
} }

View File

@ -1,16 +1,16 @@
<% <%
function layoutDiv() { function layoutDiv() {
if (!item.content?.length) return ''
var el = ''; var el = '';
if (item.content == undefined || item.content.length == 0) {
return el;
}
el += '<div class="widget-wrap" id="markdown">'; el += '<div class="widget-wrap" id="markdown">';
if (item.title?.length > 0) {
el += '<div class="widget-header cap theme dis-select">'; el += '<div class="widget-header cap theme dis-select">';
el += '<span class="name">' + item.title + '</span>'; el += '<span class="name">' + item.title + '</span>';
el += '</div>';
el += '<div class="widget-body fs14">';
el += markdown(item.content);
el += '</div>'; el += '</div>';
}
el += '<div class="widget-body fs14">';
el += markdown(item.content);
el += '</div>';
el += '</div>'; el += '</div>';
return el; return el;
} }