hexo-theme-stellar/layout/_partial/sidebar/logo.ejs

76 lines
2.1 KiB
Plaintext

<%
var logo = theme.logo
if (page.logo) {
logo = Object.assign({}, logo, page.logo)
} else if (theme.wiki.tree[page.wiki]) {
const proj = theme.wiki.tree[page.wiki]
var l = proj.logo
if (l) {
logo = l
} else if (proj.name || proj.icon) {
logo = {
icon: proj.icon || theme.default.project,
title: `[${proj.name || proj.title}](${url_for(proj.homepage?.path || '')})`,
subtitle: proj.subtitle
}
}
}
// logo.icon, logo.title, logo.subtitle, logo.url
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) {
const arr = sub.split('|')
if (arr.length > 1) {
el += `<div class="sub normal cap">${arr.shift().trim()}</div>`
el += `<div class="sub hover cap" style="opacity:0">${arr.join('|')}</div>`
} else {
el += `<div class="sub cap">${sub}</div>`
}
}
el += `</a>`
return el
}
function layoutDiv() {
if (where == 'main') {
if (page.header == false) {
return ''
}
// 内容页如果未设置 header 则不显示
if (page.header == null) {
if (!page.nav_tabs) { // 如果有 nav_tabs 就代表是列表页
if (page.layout === 'post' || page.layout === 'page' || page.wiki) {
return ''
}
}
}
}
var el = ''
el += `<header class="header${where == 'main' ? ' mobile-only' : ''}">`
el += `<div class="logo-wrap">`
if (logo.icon) {
el += `<div class="icon"><img no-lazy class="icon" src="${md_text(logo.icon)}"></div>`
} else if (md_text(logo.avatar)) {
el += `<a class="avatar" href="${url_for(md_link(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(logo.avatar)}">`
el += `</a>`
}
const main = md_text(logo.title)
if (main) {
let url = md_link(logo.title)
el += layoutTitle(main, url, logo.subtitle)
}
el += `</div>`
el += '</header>'
return el
}
%>
<%- layoutDiv() %>