[feat] create widget in front-matter
This commit is contained in:
parent
7d10a24a4d
commit
6f48c3f477
|
@ -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})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue