[opt] wiki sidebar

This commit is contained in:
xaoxuu 2022-11-19 16:48:44 +08:00
parent ff168d322f
commit 2c20cb9040
6 changed files with 98 additions and 86 deletions

View File

@ -13,17 +13,15 @@ function generate_title() {
}
} else {
if (page.title) {
return page.title;
return page.title + ' - ' + config.title;
} else if (page.category) {
return __('btn.category') + __('symbol.colon') + page.category + ' - ' + config.title;
} else if (page.tag) {
return __('btn.tag') + __('symbol.colon') + page.tag + ' - ' + config.title;
} else {
}
}
return config.title;
}
}
return '';
}
function generate_description() {
if (theme.open_graph && theme.open_graph.enable) {
return '';

View File

@ -1,21 +1,56 @@
<%
var proj;
if (page.layout === 'wiki' && page.wiki) {
proj = theme.wiki.projects[page.wiki];
}
function layoutTitle(main, url, sub) {
var el = '';
el += '<a class="title" href="' + url_for(url || "/") + '">';
el += '<div class="main" ff="title">' + main + '</div>';
if (sub) {
let arr = sub.split('|');
if (arr.length > 1) {
el += '<div class="sub normal cap">' + arr[0].trim() + '</div>';
el += '<div class="sub hover cap" style="opacity:0">' + arr[1].trim() + '</div>';
} else if (arr.length > 0) {
el += '<div class="sub cap">' + arr[0] + '</div>';
}
}
el += '</a>';
return el;
}
function layoutDiv() {
var el = '';
if (page.layout == 'wiki' && page.menu_id == 'wiki') {
return el;
}
el += '<header class="header';
if (where == 'main') {
el += ' mobile-only';
}
el += '">';
el += partial('logo');
el += '<div class="logo-wrap">';
if (md_text(theme.sidebar.logo.avatar)) {
el += '<a class="avatar" href="' + url_for(md_link(theme.sidebar.logo.avatar) || "/") + '">';
if (theme.style.animated_avatar.animate) {
el += '<div class="bg" style="opacity:0;background-image:url(' + theme.style.animated_avatar.background + ');"></div>';
}
el += '<img no-lazy class="avatar" src="' + md_text(theme.sidebar.logo.avatar) + '">';
el += '</a>';
}
let main = md_text(theme.sidebar.logo.title);
if (main) {
let url = md_link(theme.sidebar.logo.title);
let sub = config.subtitle;
el += layoutTitle(main, url, sub);
}
el += '</div>';
if (where != 'main') {
if (page.layout === 'wiki' && page.wiki) {
if (page.menu_id !== 'wiki') {
el += partial('menu', {where: where});
}
} else {
el += partial('menu', {where: where});
}
}
el += '</header>';
return el;
}

View File

@ -1,4 +1,8 @@
<%
var proj;
if (page.layout === 'wiki' && page.wiki) {
proj = theme.wiki.projects[page.wiki];
}
// 默认组件
if (page.sidebar == undefined) {
if (page.layout == 'post' && page.content) {
@ -23,10 +27,50 @@ if (page.sidebar == undefined) {
if (typeof page.sidebar == 'string') {
page.sidebar = page.sidebar.replace(/ /g, '').split(',');
}
function layoutTitle(main, url, sub) {
var el = '';
el += '<a class="title" href="' + url_for(url || "/") + '">';
el += '<div class="main" ff="title">' + main + '</div>';
if (sub) {
let arr = sub.split('|');
if (arr.length > 1) {
el += '<div class="sub normal cap">' + arr[0].trim() + '</div>';
el += '<div class="sub hover cap" style="opacity:0">' + arr[1].trim() + '</div>';
} else if (arr.length > 0) {
el += '<div class="sub cap">' + arr[0] + '</div>';
}
}
el += '</a>';
return el;
}
function layoutWidgets() {
var el = '';
el += '<div class="widgets">';
if (page.layout == 'wiki' && proj && page.menu_id == 'wiki') {
el += '<div class="widget-wrap logo-wrap wiki">';
// all products
el += '<a style="filter: grayscale(100%)" class="wiki-home cap" href="' + url_for(config.wiki_dir) + '">';
el += '<svg aria-hidden="true" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor"><path fill-rule="evenodd" d="M7.78 12.53a.75.75 0 01-1.06 0L2.47 8.28a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.81 7h7.44a.75.75 0 010 1.5H4.81l2.97 2.97a.75.75 0 010 1.06z"></path></svg>';
el += __('btn.all_wiki');
el += '</a>';
// this product
if (proj == undefined) {
// 如果没有项目名则使用menu中显示的名字
if (page.menu_id && theme.sidebar.menu[page.menu_id] && md_link(theme.sidebar.menu[page.menu_id])) {
proj = {
path: md_link(theme.sidebar.menu[page.menu_id]),
wiki: __(md_text(theme.sidebar.menu[page.menu_id]))
};
}
}
if (proj != undefined) {
let main = proj.name || proj.title || page.wiki || page.title;
let url = proj.homepage.path;
let sub = proj.subtitle;
el += layoutTitle(main, url, sub);
}
el += '</div>';
}
if (page.sidebar) {
page.sidebar.forEach((w, i) => {
if (w in theme.data.widgets) {

View File

@ -1,69 +0,0 @@
<%
var proj;
if (page.layout === 'wiki' && page.wiki) {
proj = theme.wiki.projects[page.wiki];
}
function layoutTitle(main, url, sub) {
var el = '';
el += '<a class="title" href="' + url_for(url || "/") + '">';
el += '<div class="main" ff="title">' + main + '</div>';
if (sub) {
let arr = sub.split('|');
if (arr.length > 1) {
el += '<div class="sub normal cap">' + arr[0].trim() + '</div>';
el += '<div class="sub hover cap" style="opacity:0">' + arr[1].trim() + '</div>';
} else if (arr.length > 0) {
el += '<div class="sub cap">' + arr[0] + '</div>';
}
}
el += '</a>';
return el;
}
function layoutDiv() {
var el = '';
if (page.layout == 'wiki' && proj && proj.index != false) {
el += '<div class="logo-wrap wiki">';
// all products
el += '<a style="filter: grayscale(100%)" class="wiki-home cap" href="' + url_for(config.wiki_dir) + '">';
el += '<svg aria-hidden="true" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor"><path fill-rule="evenodd" d="M7.78 12.53a.75.75 0 01-1.06 0L2.47 8.28a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.81 7h7.44a.75.75 0 010 1.5H4.81l2.97 2.97a.75.75 0 010 1.06z"></path></svg>';
el += __('btn.all_wiki');
el += '</a>';
// this product
if (proj == undefined) {
// 如果没有项目名则使用menu中显示的名字
if (page.menu_id && theme.sidebar.menu[page.menu_id] && md_link(theme.sidebar.menu[page.menu_id])) {
proj = {
path: md_link(theme.sidebar.menu[page.menu_id]),
wiki: __(md_text(theme.sidebar.menu[page.menu_id]))
};
}
}
if (proj != undefined) {
let main = proj.name || proj.title || page.wiki || page.title;
let url = proj.homepage.path;
let sub = proj.subtitle;
el += layoutTitle(main, url, sub);
}
} else {
el += '<div class="logo-wrap">';
if (md_text(theme.sidebar.logo.avatar)) {
el += '<a class="avatar" href="' + url_for(md_link(theme.sidebar.logo.avatar) || "/") + '">';
if (theme.style.animated_avatar.animate) {
el += '<div class="bg" style="opacity:0;background-image:url(' + theme.style.animated_avatar.background + ');"></div>';
}
el += '<img no-lazy class="avatar" src="' + md_text(theme.sidebar.logo.avatar) + '">';
el += '</a>';
}
let main = md_text(theme.sidebar.logo.title);
if (main) {
let url = md_link(theme.sidebar.logo.title);
let sub = config.subtitle;
el += layoutTitle(main, url, sub);
}
}
el += '</div>';
return el;
}
%>
<%- layoutDiv() %>

View File

@ -29,7 +29,11 @@ function layoutDocTree(pages) {
}
el += '<div class="doc-tree' + isActive + '">';
if (proj.pages.length > 1) {
el += '<a class="doc-tree-link' + isActive + '" href="' + url_for(p.path) + '">';
let href = url_for(p.path);
if (i == 0) {
href += '#start'
}
el += '<a class="doc-tree-link' + isActive + '" href="' + href + '">';
el += '<span class="toc-text">' + (p.title || p.seo_title) + '</span>';
el += '</a>';
}

View File

@ -100,12 +100,12 @@
opacity: 1 !important
.logo-wrap.wiki
margin: 1rem 0 1.5rem 0
.l_left .widgets .widget-wrap.logo-wrap.wiki
margin-bottom: 1.5rem
flex-direction: column
align-items: flex-start
a.wiki-home
margin-bottom: 1rem
margin-bottom: 0.5rem
color: var(--text-p1)
svg
margin-right: 2px