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

88 lines
2.5 KiB
Plaintext
Raw Normal View History

2024-01-17 00:27:48 +08:00
<%
2024-01-17 14:07:30 +08:00
var logo = theme.logo
if (page.logo) {
logo = Object.assign({}, logo, page.logo)
2024-01-19 01:05:44 +08:00
} else if (theme.wiki.tree[page.wiki]) {
2024-01-17 14:07:30 +08:00
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
}
}
2024-01-19 01:05:44 +08:00
} else if (theme.topic.tree[page.topic]) {
2024-01-17 14:07:30 +08:00
const topic = theme.topic.tree[page.topic]
var l = topic.logo
if (l) {
logo = l
} else if (topic.name || topic.icon) {
logo = {
icon: topic.icon || theme.default.topic,
title: `[${topic.name || topic.title}](${url_for(topic.homepage?.path || '')})`,
subtitle: topic.subtitle
}
}
}
2024-01-17 00:27:48 +08:00
// 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() {
2024-01-17 14:07:30 +08:00
if (where == 'main') {
2024-01-19 01:05:44 +08:00
if (page.header == false) {
2024-01-17 14:07:30 +08:00
return ''
}
2024-01-19 01:05:44 +08:00
// 内容页如果未设置 header 则不显示
if (page.header == null) {
if (!page.nav_tabs) { // 如果有 nav_tabs 就代表是列表页
if (page.layout === 'post' || page.layout === 'page' || page.wiki) {
return ''
}
}
2024-01-17 14:07:30 +08:00
}
}
2024-01-17 00:27:48 +08:00
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() %>