hexo-theme-stellar/layout/_partial/main/navbar/article_banner.ejs

127 lines
2.8 KiB
Plaintext
Raw Normal View History

2024-01-30 23:48:00 +08:00
<%
2024-02-06 14:07:46 +08:00
var banner = {}
2024-02-03 14:38:34 +08:00
if (page.banner) {
2024-02-06 14:07:46 +08:00
banner.url = page.banner
2024-02-03 14:38:34 +08:00
} else if (theme.topic.tree[page.topic]?.banner != null) {
2024-02-06 14:07:46 +08:00
banner.url = theme.topic.tree[page.topic]?.banner
2024-02-03 14:38:34 +08:00
} else if (theme.wiki.tree[page.wiki]?.banner != null) {
2024-02-06 14:07:46 +08:00
banner.url = theme.wiki.tree[page.wiki]?.banner
}
banner = Object.assign(banner, page.banner_info)
// 标题
if (banner.title == null) {
banner.title = page.h1 != null ? page.h1 : page.title
}
2024-02-18 12:46:14 +08:00
// 副标题
if (banner.subtitle == null) {
banner.subtitle = page.subtitle
}
2024-02-06 14:07:46 +08:00
function layoutBreadcrumb() {
if (page.breadcrumb === false) {
return `<div class="top"></div>`
}
var el = ''
// 1.main
el += `<div class="top bread-nav footnote">`
// 2.left
el += `<div class="left">`
// 3.left.top: 面包屑导航
el += `<div class="flex-row" id="breadcrumb">`
// 首页
el += `<a class="cap breadcrumb" href="${url_for(config.root)}">${__("btn.home")}</a>`
if (theme.wiki.tree[page.wiki]) {
el += partial('breadcrumb/wiki')
2024-05-13 09:45:38 +08:00
} else if (page.notebook) {
el += partial('breadcrumb/note')
2024-02-06 14:07:46 +08:00
} else if (page.layout == 'post') {
el += partial('breadcrumb/blog')
} else {
el += partial('breadcrumb/page')
}
// end 3.left.top
el += `</div>`
// 3.left.bottom
el += partial('dateinfo')
// end 2.left
el += `</div>`
// end 1.main
el += `</div>`
return el
2024-02-03 14:38:34 +08:00
}
2024-01-30 23:48:00 +08:00
function layoutTitle() {
2024-02-06 14:07:46 +08:00
if (banner.title?.length > 0) {
return `<h1 class="text title"><span>${banner.title}</span></h1>`
} else {
return ''
}
}
function layoutSubtitle() {
if (banner.subtitle?.length > 0) {
return `<div class="text subtitle">${banner.subtitle}</div>`
} else {
return ''
}
}
function layoutIcon() {
if (banner.avatar?.length > 0 || banner.icon?.length > 0) {
return `<img class="avatar" src="${banner.avatar || banner.icon}">`
2024-01-30 23:48:00 +08:00
} else {
return ''
}
}
function layoutBottom() {
2024-02-06 14:07:46 +08:00
const el_icon = layoutIcon()
const el_title = layoutTitle()
const el_subtitle = layoutSubtitle()
var cls = ''
if (el_title.length > 0 && el_subtitle.length == 0) {
cls += ' only-title'
}
if (el_title.length > 0) {
2024-01-30 23:48:00 +08:00
return `
2024-02-06 14:07:46 +08:00
<div class="bottom${cls}">
${el_icon}
2024-01-30 23:48:00 +08:00
<div class="text-area">
2024-02-06 14:07:46 +08:00
${el_title}
${el_subtitle}
2024-01-30 23:48:00 +08:00
</div>
</div>
`
} else {
return ``
}
}
function layoutDiv() {
const bottom = layoutBottom()
2024-02-06 14:07:46 +08:00
if (page.breadcrumb === false && bottom.length == 0) {
2024-01-30 23:48:00 +08:00
return ``
}
2024-02-06 14:07:46 +08:00
const top = layoutBreadcrumb()
2024-01-31 13:58:56 +08:00
var style = ``
2024-01-30 23:48:00 +08:00
var el = ``
el += `<div class="article banner top">`
2024-02-06 14:07:46 +08:00
if (banner.url?.length > 0) {
el += `<img class="bg" src="${banner.url}">`
if (banner.color) {
style += ' style="--text-banner:' + banner.color + '"'
2024-01-31 13:58:56 +08:00
}
2024-01-30 23:48:00 +08:00
}
el += `
<div class="content"${style}>
${top}
${bottom}
</div>
`
el += `</div>`
return el
}
%>
<%- layoutDiv() %>