custom breadcrumb

This commit is contained in:
xaoxuu 2021-08-28 13:08:53 +08:00
parent 7df5ca50c8
commit eb4835db17
2 changed files with 19 additions and 5 deletions

View File

@ -56,6 +56,10 @@ sidebar:
######## Main ########
breadcrumb:
home: config.title # config.title / config.author / home or custom content
######## Article ######## ######## Article ########
article: article:
# 如果没有指定封面,是否根据 tags 作为关键词搜索封面? # 如果没有指定封面,是否根据 tags 作为关键词搜索封面?
@ -230,7 +234,7 @@ style:
darkmode: auto # set 'auto' to enable, set 'false' to disable darkmode: auto # set 'auto' to enable, set 'false' to disable
theme: theme:
light: '#f8f8f8' light: '#f8f8f8'
dark: '#20252B' dark: '#202429'
animated_avatar: animated_avatar:
animate: auto # auto, always animate: auto # auto, always
background: https://cdn.jsdelivr.net/gh/cdn-x/placeholder@1.0.2/avatar/round/rainbow64@3x.webp background: https://cdn.jsdelivr.net/gh/cdn-x/placeholder@1.0.2/avatar/round/rainbow64@3x.webp

View File

@ -4,6 +4,16 @@ function layoutDiv() {
if (page.breadcrumb === false) { if (page.breadcrumb === false) {
return el; return el;
} }
var home_title = __("btn.home");
if (theme.breadcrumb && theme.breadcrumb.home) {
if (theme.breadcrumb.home === 'config.title') {
home_title = config.title;
} else if (theme.breadcrumb.home === 'config.author') {
home_title = config.author;
} else if (theme.breadcrumb.home !== 'home') {
home_title = theme.breadcrumb.home;
}
}
if (page.layout === "post") { if (page.layout === "post") {
var firstCat = ""; var firstCat = "";
if (page.categories && page.categories.length > 0) { if (page.categories && page.categories.length > 0) {
@ -11,9 +21,9 @@ function layoutDiv() {
} }
el += '<div class="bread-nav fs12">'; el += '<div class="bread-nav fs12">';
el += '<div id="breadcrumb">'; el += '<div id="breadcrumb">';
el += '<a class="cap breadcrumb" href="/">' + __("btn.home") + '</a>'; el += '<a class="cap breadcrumb" href="' + config.root + '">' + home_title + '</a>';
el += '<span class="sep"></span>'; el += '<span class="sep"></span>';
el += '<a class="cap breadcrumb" href="/">' + __("btn.blog") + '</a>'; el += '<a class="cap breadcrumb" href="' + config.root + '">' + __("btn.blog") + '</a>';
if (page.layout == "post" && page.categories && page.categories.length > 0) { if (page.layout == "post" && page.categories && page.categories.length > 0) {
el += '<span class="sep"></span>'; el += '<span class="sep"></span>';
el += list_categories(page.categories, { el += list_categories(page.categories, {
@ -34,7 +44,7 @@ function layoutDiv() {
el += '<div id="breadcrumb">'; el += '<div id="breadcrumb">';
var nodes = []; var nodes = [];
// home // home
el += '<a class="cap breadcrumb" id="home" href="/">' + __("btn.home") + '</a>'; el += '<a class="cap breadcrumb" id="home" href="' + config.root + '">' + home_title + '</a>';
nodes.push('/'); nodes.push('/');
// menu_id // menu_id
el += '<span class="sep"></span>'; el += '<span class="sep"></span>';
@ -63,7 +73,7 @@ function layoutDiv() {
} else if (page.title || page.seo_title) { } else if (page.title || page.seo_title) {
el += '<div class="bread-nav fs12">'; el += '<div class="bread-nav fs12">';
el += '<div id="breadcrumb">'; el += '<div id="breadcrumb">';
el += '<a class="cap breadcrumb" href="/">' + __("btn.home") + '</a>'; el += '<a class="cap breadcrumb" href="' + config.root + '">' + home_title + '</a>';
el += '<span class="sep"></span>'; el += '<span class="sep"></span>';
el += '<a class="cap breadcrumb" href="' + url_for(page.path) + '">' + (page.title || page.seo_title) + '</a>'; el += '<a class="cap breadcrumb" href="' + url_for(page.path) + '">' + (page.title || page.seo_title) + '</a>';
el += '</div>'; el += '</div>';