[opt] code optimization

This commit is contained in:
xaoxuu 2024-01-19 01:05:44 +08:00
parent 8e8b63169b
commit 5bc949fc22
43 changed files with 203 additions and 239 deletions

View File

@ -11,6 +11,7 @@ stellar:
preconnect:
# - https://gcore.jsdelivr.net
# - https://unpkg.com
# - https://cdn.bootcdn.net
open_graph:
enable: true
@ -369,9 +370,9 @@ plugins:
# https://scrollrevealjs.org/api/reveal.html
scrollreveal:
enable: #true
js: https://gcore.jsdelivr.net/npm/scrollreveal@4.0.9/dist/scrollreveal.min.js
distance: 8px
duration: 500 # ms
js: https://cdn.bootcdn.net/ajax/libs/scrollReveal.js/4.0.9/scrollreveal.min.js
distance: 16px
duration: 800 # ms
interval: 100 # ms
scale: 1 # 0.1~1

View File

@ -1,12 +1,12 @@
<%
function layoutCover() {
if (page.layout == 'wiki') {
return partial('wiki_cover');
if (page.wiki) {
return partial('wiki_cover')
}
if (page.layout == 'post') {
return partial('post_cover');
if (page.layout === 'post') {
return partial('post_cover')
}
return '';
return ''
}
%>
<%- layoutCover() %>

View File

@ -26,7 +26,7 @@ function div() {
url = 'https://source.unsplash.com/random/2000x400';
}
}
el += '<div class="l_cover post' + scrollreveal() + '">';
el += '<div class="l_cover post' + scrollreveal(' ') + '">';
el += '<div class="cover">';
if (theme.plugins.lazyload && theme.plugins.lazyload.enable) {
el += '<div class="lazy img bg" data-bg="' + url + '"></div>';

View File

@ -1,7 +1,7 @@
<%
function layoutWikiCover() {
var el = '';
let proj = theme.wiki.tree[page.wiki];
const proj = theme.wiki.tree[page.wiki]
if (proj == undefined) {
return el;
}
@ -18,7 +18,7 @@ function layoutWikiCover() {
if (coverpage === true) {
coverpage = ['cover', 'title', 'description'];
}
el += '<div class="l_cover wiki' + scrollreveal() + '">';
el += '<div class="l_cover wiki' + scrollreveal(' ') + '">';
el += '<article class="cover-wrap md-text">';
if (cover?.length > 0 && coverpage.includes('cover')) {

View File

@ -1,8 +1,8 @@
<%
function generate_title() {
if (page.wiki) {
let proj = theme.wiki.tree[page.wiki];
let wiki = (proj && proj.name) || page.wiki;
const proj = theme.wiki.tree[page.wiki]
const wiki = proj?.name || page.wiki
if (page.title) {
return wiki + __('symbol.colon') + page.title + ' - ' + config.title;
} else {
@ -24,9 +24,9 @@ function generate_description() {
return '';
}
if (page.wiki) {
let proj = theme.wiki.tree[page.wiki];
if (proj && proj.description) {
return '<meta name="description" content="' + proj.description + '">';
const proj = theme.wiki.tree[page.wiki]
if (proj?.description) {
return '<meta name="description" content="' + proj.description + '">'
}
}
if (page.description || page.excerpt || page.content) {

View File

@ -14,7 +14,7 @@ function layoutDiv() {
if (item.length === 0) {
return el;
}
el += '<div class="article-footer reveal fs14">';
el += `<div class="article-footer${scrollreveal(' ')} fs14">`
if (page.references?.length > 0) {
function refList() {
var el = '';
@ -39,7 +39,7 @@ function layoutDiv() {
var license = ''
if (page.wiki) {
let proj = theme.wiki.tree[page.wiki]
const proj = theme.wiki.tree[page.wiki]
if (page.license != null) {
license = page.license || theme.article.license
} else if (proj?.license != null) {
@ -76,7 +76,7 @@ function layoutDiv() {
var showSharePlugin = false
if (page.wiki) {
let proj = theme.wiki.tree[page.wiki]
const proj = theme.wiki.tree[page.wiki]
if (page.share != null) {
showSharePlugin = page.share == true
} else if (proj != null) {
@ -101,7 +101,7 @@ function layoutDiv() {
el += '&title=' + page.title + ' - ' + config.title;
if (page.layout == 'post' && page.cover) {
el += '&pics=' + page.cover;
} else if (page.layout == 'wiki' && page.icon) {
} else if (page.wiki && page.icon) {
el += '&pics=' + page.icon;
}
el += '&summary=' + truncate(page.description || strip_html(page.excerpt || page.content), {length: 120});

View File

@ -7,10 +7,10 @@ function layoutDiv() {
if (page.layout === 'post') {
prev = page.prev
next = page.next
} else if (page.layout === 'wiki' && page.wiki?.length > 0) {
} else if (page.wiki?.length > 0) {
var title_prev = __('meta.prev');
var title_next = __('meta.next');
let proj = theme.wiki.tree[page.wiki];
const proj = theme.wiki.tree[page.wiki];
if (proj) {
let ps = proj.pages?.filter(p => p.path == page.path)
if (ps?.length > 0) {
@ -33,7 +33,7 @@ function layoutDiv() {
}
let el = '';
if (prev || next) {
el += '<div class="related-wrap reveal" id="read-next">';
el += `<div class="related-wrap${scrollreveal(' ')}" id="read-next">`
el += '<section class="body">';
// prev
el += '<div class="item" id="prev">';

View File

@ -2,7 +2,7 @@
function layoutDiv() {
if (theme.article.related_posts.enable) {
var el = '';
el += '<div class="related-wrap reveal" id="related-posts">';
el += `<div class="related-wrap${scrollreveal(' ')}" id="related-posts">`
el += popular_posts_wrapper({
title: __('meta.related_posts'),
json: popular_posts_json({ maxCount: theme.article.related_posts.max_count , ulClass: 'related-posts' , PPMixingRate: 0.2 , isImage: true , isExcerpt: true} , page )

View File

@ -2,7 +2,7 @@
const content = theme.footer.content?.replace('${author.name}', (config.author || 'Anonymity'))?.replace('${theme.name}', stellar_info('name'))?.replace('${theme.version}', stellar_info('version'))?.replace('${theme.tree}', stellar_info('tree'))
function layoutDiv() {
var el = ''
el += '<footer class="page-footer reveal fs12">'
el += `<footer class="page-footer${scrollreveal(' ')} fs12">`
el += '<hr>'
// sitemap
if (theme.footer.sitemap && Object.keys(theme.footer.sitemap).length > 0) {

View File

@ -99,7 +99,7 @@ function layoutDiv() {
nodes.push(url);
el += '<a class="cap breadcrumb" id="menu" href="' + url + '">' + __("btn.wiki") + '</a>';
// 项目名
let proj = theme.wiki.tree[page.wiki];
const proj = theme.wiki.tree[page.wiki]
if (proj != null) {
let url_proj = url_for(proj.homepage?.path);
if (nodes.includes(url_proj) === false) {

View File

@ -1,5 +1,5 @@
<% if ((is_home() || is_category() || is_tag()) && page.total > 1) { %>
<div class='paginator-wrap dis-select'>
<div class='paginator-wrap dis-select<%- scrollreveal(' ') %>'>
<%- paginator({
prev_text: '',
next_text: '',

View File

@ -1,4 +1,4 @@
<% if (page.layout === 'post' || (page.layout === 'wiki' && page.wiki && page.wiki.length > 0)) { %>
<% if (page.layout === 'post' || (page.wiki?.length > 0)) { %>
<script>
let tianliGPT_postSelector = '.md-text.content.<%= page.layout === "post" ? "post" : "wiki" %>';
let tianliGPT_key = '<%= theme.plugins.tianli_gpt.api %>';

View File

@ -12,8 +12,8 @@ if (theme.comments.service && theme.comments.service.length > 0) {
}
}
// 合并项目评论
let proj = theme.wiki.tree[page.wiki];
if (loadComment && page.layout == 'wiki' && page.wiki && (proj != null)) {
const proj = theme.wiki.tree[page.wiki]
if (loadComment && (proj != null)) {
if (proj.comment_title != undefined && page.comment_title == undefined) {
if (['utterances', 'beaudar', 'giscus'].includes(theme.comments.service)) {
page.comment_title = proj.comment_title;
@ -31,7 +31,7 @@ if (cmt.service && page[cmt.service]) {
page.cmt = cmt;
%>
<% if (loadComment) { %>
<div class='related-wrap md-text reveal' id="comments">
<div class="related-wrap md-text<%- scrollreveal(' ') %>" id="comments">
<section class='header cmt-title cap theme'>
<%- page.comment_title != undefined ? markdown(page.comment_title) : __('meta.comment_title') %>
</section>

View File

@ -1,4 +1,8 @@
<%
const wiki = theme.wiki.tree[page.wiki]
const topic = theme.topic.tree[page.topic]
if (page.sidebar == null) {
const { site_tree } = theme
var sidebar
@ -11,7 +15,7 @@ if (page.sidebar == null) {
sidebar = site_tree.blog.sidebar
} else if (page.topic?.length > 0) {
sidebar = site_tree.topic.sidebar
} else if (page.layout === 'index_wiki' || page.layout === 'wiki') {
} else if (page.layout === 'index_wiki' || page.wiki) {
sidebar = site_tree.wiki.sidebar
} else if (page.layout === '404') {
sidebar = site_tree.error_page.sidebar
@ -25,16 +29,17 @@ if (page.sidebar == null) {
sidebar = []
}
if (page.topic && theme.topic?.tree[page.topic]?.sidebar) {
sidebar = theme.topic.tree[page.topic].sidebar
if (topic?.sidebar) {
sidebar = topic.sidebar
}
if (page.layout == 'wiki' && page.wiki && theme.wiki?.tree[page.wiki]?.sidebar) {
sidebar = theme.wiki.tree[page.wiki].sidebar
if (wiki?.sidebar) {
sidebar = wiki.sidebar
}
page.sidebar = sidebar
}
// parse array string
if (typeof page.sidebar == 'string') {
page.sidebar = page.sidebar.replace(/ /g, '').split(',');
@ -57,10 +62,6 @@ function layoutTitle(main, url, sub) {
}
function layoutWidgets() {
var el = '';
var proj;
if (page.layout === 'wiki' && page.wiki) {
proj = theme.wiki.tree[page.wiki];
}
el += '<div class="widgets">';
if (page.sidebar) {
page.sidebar.forEach((w, i) => {
@ -71,8 +72,8 @@ function layoutWidgets() {
} else if (typeof w == 'object' && w.override) {
name = w.override
}
if (name in theme.data.widgets) {
Object.assign(widget, theme.data.widgets[name])
if (name in theme.widgets) {
Object.assign(widget, theme.widgets[name])
}
if (typeof w == 'object' && (w.override || w.layout)) {
Object.assign(widget, w)
@ -128,16 +129,10 @@ function layoutNavArea() {
var search = {}
if (page.search) {
search = page.search
} else if (page.wiki && page.layout == 'wiki' && theme.wiki.tree[page.wiki]) {
const proj = theme.wiki.tree[page.wiki]
if (proj.search) {
search = proj.search
}
} else if (page.topic && theme.topic.tree[page.topic]) {
const topic = theme.topic.tree[page.topic]
if (topic.search) {
search = topic.search
}
} else if (wiki?.search) {
search = wiki.search
} else if (topic?.search) {
search = topic.search
}
var el = ''
el += `<div class="nav-area">`

View File

@ -2,7 +2,7 @@
var logo = theme.logo
if (page.logo) {
logo = Object.assign({}, logo, page.logo)
} else if (page.wiki && page.layout == 'wiki' && theme.wiki.tree[page.wiki]) {
} else if (theme.wiki.tree[page.wiki]) {
const proj = theme.wiki.tree[page.wiki]
var l = proj.logo
if (l) {
@ -14,7 +14,7 @@ if (page.logo) {
subtitle: proj.subtitle
}
}
} else if (page.topic && theme.topic.tree[page.topic]) {
} else if (theme.topic.tree[page.topic]) {
const topic = theme.topic.tree[page.topic]
var l = topic.logo
if (l) {
@ -48,11 +48,16 @@ function layoutTitle(main, url, sub) {
function layoutDiv() {
if (where == 'main') {
if (page.layout == 'wiki' && page.menu_id == 'wiki') {
if (page.header == false) {
return ''
}
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 = ''

View File

@ -8,7 +8,7 @@ function layoutDiv() {
el += `<form class="search-form">`
var filter = ''
if (item.filter == 'auto') {
if (page.layout == 'wiki') {
if (page.wiki) {
let matches = page.path.match(/(.*?)\/(.*?)\//i)
if (matches?.length > 0) {
filter = matches[0]

View File

@ -5,13 +5,11 @@ function layoutDiv() {
var branch = 'main';
if (page.repo) {
repo = page.repo
} else if (page.layout === 'wiki' && page.wiki) {
let proj = theme.wiki.tree[page.wiki];
if (proj && proj.repo) {
repo = proj.repo;
if (proj.branch != undefined) {
branch = proj.branch;
}
} else if (theme.wiki.tree[page.wiki]?.repo) {
const proj = theme.wiki.tree[page.wiki]
repo = proj.repo
if (proj.branch != undefined) {
branch = proj.branch
}
}
if (repo == undefined) {
@ -21,7 +19,7 @@ function layoutDiv() {
if (item.labels) {
item.api += '&labels=' + item.labels;
}
el += '<widget class="widget-wrapper timeline">';
el += `<widget class="widget-wrapper${scrollreveal(' ')} timeline">`
if (item.title) {
el += '<div class="widget-header dis-select">';
el += '<span class="name">' + item.title + '</span>';

View File

@ -5,20 +5,18 @@ function layoutDiv() {
var branch = 'main';
if (page.repo) {
repo = page.repo
} else if (page.layout === 'wiki' && page.wiki) {
let proj = theme.wiki.tree[page.wiki];
if (proj && proj.repo) {
repo = proj.repo;
if (proj.branch != undefined) {
branch = proj.branch;
}
} else if (theme.wiki.tree[page.wiki]?.repo) {
const proj = theme.wiki.tree[page.wiki]
repo = proj.repo
if (proj.branch != undefined) {
branch = proj.branch
}
}
if (repo == undefined) {
return el;
}
// 布局
el += '<widget class="widget-wrapper ghrepo">';
el += `<widget class="widget-wrapper${scrollreveal(' ')} ghrepo">`
// body
el += '<div class="widget-body">';
el += '<div class="items stellar-ghinfo-api" api="' + theme.api_host.ghapi + '/repos/' + repo + '">';

View File

@ -22,7 +22,7 @@ function layoutDiv() {
return el;
}
el += '<widget class="widget-wrapper ghuser">';
el += `<widget class="widget-wrapper${scrollreveal(' ')} ghuser">`
// body
el += '<div class="widget-body stellar-ghinfo-api" api="' + theme.api_host.ghapi + '/users/' + item.username + '">';
if (item.avatar) {

View File

@ -2,7 +2,7 @@
function layoutDiv() {
if (!item.content?.length && !item.src?.length) return ''
var el = '';
el += '<widget class="widget-wrapper markdown">';
el += `<widget class="widget-wrapper${scrollreveal(' ')} markdown">`
if (item.title?.length > 0) {
el += '<div class="widget-header dis-select">';
el += '<span class="name">' + item.title + '</span>';

View File

@ -1,6 +1,6 @@
<%
function layoutDiv() {
var el = '<widget class="widget-wrapper post-list">';
var el = `<widget class="widget-wrapper${scrollreveal(' ')} post-list">`
// header
el += '<div class="widget-header dis-select">';
el += '<span class="name">' + __("meta.recent_update") + '</span>';
@ -32,8 +32,8 @@ function layoutDiv() {
const isActive = post.path == page.path
el += `<a class="item title${post.path == page.path ? ' active' : ''}" href="${url_for(post.link || post.path)}">`
el += '<span class="title">'
if (post.layout == 'wiki') {
let proj = theme.wiki.tree[post.wiki];
if (post.wiki) {
const proj = theme.wiki.tree[post.wiki];
let name = proj?.name || post?.wiki;
if (name) {
el += '<strong>' + name + '</strong>' + '<span class="dot"></span>';

View File

@ -8,7 +8,7 @@ function relatedPostsInTopic() {
return ''
}
var el = ''
el += `<widget class="widget-wrapper post-list">`
el += `<widget class="widget-wrapper${scrollreveal(' ')} post-list">`
el += `<div class="widget-header dis-select">`
el += `<span class="name">${__('btn.topic') + __('symbol.colon') + topic.name}</span>`
el += `</div>`
@ -34,7 +34,7 @@ function relatedWiki() {
const relatedItems = thisItemObject.relatedItems
var el = ''
for (let relatedItem of relatedItems) {
el += `<widget class="widget-wrapper post-card">`
el += `<widget class="widget-wrapper${scrollreveal(' ')} post-card">`
el += `<div class="widget-header dis-select">`
el += `<span class="name">${__('meta.more') + __('symbol.colon') + relatedItem.name}</span>`
el += `</div>`

View File

@ -8,7 +8,7 @@ function layoutDiv() {
delete opts['title'];
delete opts['layout'];
opts.class = 'tag ';
el += '<widget class="widget-wrapper tagcloud">';
el += `<widget class="widget-wrapper${scrollreveal(' ')} tagcloud">`
if (item.title) {
el += '<div class="widget-header dis-select">';
el += '<span class="name">' + item.title + '</span>';

View File

@ -4,7 +4,7 @@ function layoutDiv() {
if (item.api == undefined) {
return el;
}
el += '<widget class="widget-wrapper timeline">';
el += `<widget class="widget-wrapper${scrollreveal(' ')} timeline">`
if (item.title) {
el += '<div class="widget-header dis-select">';
el += '<span class="name">' + item.title + '</span>';

View File

@ -1,5 +1,5 @@
<%
let proj = theme.wiki.tree[page.wiki];
const proj = theme.wiki.tree[page.wiki]
var hasTOC = true
function layoutTocBody() {
if (toc(page.content).length > 0) {
@ -56,12 +56,8 @@ function layoutDocTree(pages) {
function layoutDiv(fallback) {
var type = ''
if (proj && proj.pages) {
if (proj.pages.length > 1) {
type = 'multi'
} else {
type = 'single'
}
if (proj?.pages) {
type = proj.pages.length > 1 ? 'multi' : 'single'
} else {
let toc_content = toc(page.content)
if (toc_content && toc_content.length > 0) {
@ -71,19 +67,8 @@ function layoutDiv(fallback) {
var el = ''
if (type.length > 0) {
el += `<widget class="widget-wrapper toc ${type}" id="data-toc" collapse="${item.collapse}">`
if (page.layout !== 'wiki') {
// post 布局
el += layoutTocHeader()
el += `<div class="widget-body fs14">`
el += `<div class="doc-tree active">`
el += layoutTocBody()
el += `</div>`
el += `</div>`
if (hasTOC == false) {
return ''
}
} else if (proj) {
el += `<widget class="widget-wrapper${scrollreveal(' ')} toc ${type}" id="data-toc" collapse="${item.collapse}">`
if (proj) {
// wiki 布局
if (proj.sections && proj.sections.length > 0 && proj.pages.length > 1) { // 多 pages
for (let sec of proj.sections) {
@ -108,10 +93,21 @@ function layoutDiv(fallback) {
return ''
}
}
}
} else {
// post 布局
el += layoutTocHeader()
el += `<div class="widget-body fs14">`
el += `<div class="doc-tree active">`
el += layoutTocBody()
el += `</div>`
el += `</div>`
if (hasTOC == false) {
return ''
}
}
el += `</widget>`
} else if (item.fallback) {
const fallback = theme.data.widgets[item.fallback]
const fallback = theme.widgets[item.fallback]
el += partial(fallback.layout, {item: fallback})
}
return el

View File

@ -24,7 +24,7 @@ function layoutArchiveList() {
}
})
for (let year of years) {
el += `<article class="${scrollreveal()}" id="archive">`
el += `<article class="${scrollreveal('')}" id="archive">`
el += `<div class='archive-header h4'>${year}</div>`
site.posts.sort('date', -1).filter(function (post) {
post.year = date(post.date, 'YYYY')

View File

@ -9,7 +9,7 @@ if (page.menu_id == undefined) {
<% page.layout = 'categories'; %>
<%- partial('_partial/main/navbar/nav_tabs_blog') %>
<div class='post-list'>
<article class='<%- scrollreveal() %>' id='cats'>
<article class='<%- scrollreveal("") %>' id='cats'>
<% site.categories.sort('path').each(function(category){ %>
<div>
<a class="<%= category.parent ? 'cat child' : 'cat'%>" href="<%= url_for(category.path) %>">

View File

@ -12,7 +12,7 @@ function layout_post_card(layout, post, content) {
if (layout == 'post' && post.cover != undefined && post.poster != undefined) {
layout += ' photo';
}
el += '<a class="post-card ' + layout + ' ' + scrollreveal() + '" href="' + url_for(post.link || post.path) + '">';
el += `<a class="post-card${scrollreveal(' ')} ${layout}" href="${url_for(post.link || post.path)}">`
el += content;
el += '</a>';
return el;

View File

@ -8,7 +8,7 @@ function layout_topic_list(partial) {
continue
}
el += `<div class="post-list wiki topic">`
el += `<a class="post-card wiki topic ${scrollreveal()}" href="${url_for(topic.homepage?.path || '/')}">`
el += `<a class="post-card wiki topic${scrollreveal(' ')}" href="${url_for(topic.homepage?.path || '/')}">`
el += partial(topic)
el += `</a>`
el += `</div>`

View File

@ -13,14 +13,14 @@ function layout_wiki_list(partial) {
if (page.filter === false) {
// wikiList
el += `<div class="post-list wiki">`
el += `<a class="post-card wiki ${scrollreveal()}" href="${url_for(proj.homepage?.path || '/')}">`
el += `<a class="post-card wiki${scrollreveal(' ')}" href="${url_for(proj.homepage?.path || '/')}">`
el += partial(proj)
el += `</a>`
el += `</div>`
} else if (proj.tags && proj.tags.includes(page.tagName) === true) {
// filtered wikiList
el += `<div class="post-list wiki filter">`
el += `<a class="post-card wiki ${scrollreveal()}" href="${url_for(proj.homepage?.path || '/')}">`
el += `<a class="post-card wiki${scrollreveal(' ')}" href="${url_for(proj.homepage?.path || '/')}">`
el += partial(proj)
el += `</a>`
el += `</div>`

View File

@ -15,11 +15,11 @@ if (page.type?.length > 0) {
var indent = false
if (page.indent != null) {
indent = page.indent
} else if (page.topic && theme.topic.tree[page.topic] && (theme.topic.tree[page.topic].indent != null)) {
indent = theme.topic.tree[page.topic].indent
} else if (page.wiki && theme.wiki.tree[page.wiki] && (theme.wiki.tree[page.wiki].indent != null)) {
indent = theme.wiki.tree[page.wiki].indent
} else if (theme.article.indent) {
} else if (theme.topic.tree[page.topic]?.indent != null) {
indent = theme.topic.tree[page.topic]?.indent
} else if (theme.wiki.tree[page.wiki]?.indent != null) {
indent = theme.wiki.tree[page.wiki]?.indent
} else if (theme.article.indent != null) {
indent = theme.article.indent
} else {
indent = article_type === 'story'
@ -32,7 +32,6 @@ html += `<html lang="${page.lang}">`
html += partial('_partial/cover/index')
html += `<div class="l_body ${page_type} ${article_type}" id="start" layout="${page.layout}" ${indent ? 'text-indent' : ''}>`
html += `<aside class="l_left">`
// html += `<img no-lazy class="sidebar-bg" src="${theme.style.sidebar.background}">`
html += `<div class="sidebar-container${theme.style.sidebar?.blur ? ' sidebar-blur' : ''}">`
html += partial('_partial/sidebar/index')
html += `</div>`

View File

@ -1,28 +1,70 @@
<%
function layoutTitle() {
const title = page.h1 != null ? page.h1 : page.title;
if (title && title.length > 0) {
return '<h1 class="article-title"><span>' + title + '</span></h1>';
const { layout } = page
// 是否使用 Heti 布局插件
const isUsingHeti = theme.plugins.heti && theme.plugins.heti.enable
// 是否使用 TianliGPT 插件
const isUsingTianliGPT = theme.plugins.tianli_gpt.enable && ['all', page.layout].includes(theme.plugins.tianli_gpt.field)
// 默认的 menu_id
if (page.menu_id == null) {
if (page.wiki) {
page.menu_id = 'wiki'
} else {
return '';
page.menu_id = 'post'
}
}
// 默认的 title
if (page.title == null) {
if (page.wiki) {
page.title = __('btn.wiki')
}
}
function layoutTitle() {
const title = page.h1 != null ? page.h1 : page.title
if (title && title.length > 0) {
return `<h1 class="article-title"><span>${title}</span></h1>`
} else {
return ''
}
}
function articleClass() {
var str = `md-text content${scrollreveal(' ')}`
if (isUsingHeti) {
str += ' heti'
}
if (isUsingTianliGPT) {
str += ' '
}
return str
}
function layoutDiv() {
var el = '';
var el = ''
if (page.nav_tabs) {
el += partial('_partial/main/navbar/nav_tabs_blog');
el += partial('_partial/main/navbar/nav_tabs_blog')
}
if (page.h1 || page.title || (page.content && page.content.length > 0)) {
el += partial('_partial/main/navbar/breadcrumb');
el += partial('_partial/main/navbar/breadcrumb')
}
el += '<article class="md-text content ' + page.layout + scrollreveal() + '">';
el += layoutTitle();
el += `<article class="${articleClass()}">`
el += layoutTitle()
if (page.content && page.content.length > 0) {
el += page.content;
el += page.content
}
el += '</article>';
el += partial('_partial/plugins/comments/layout');
return el;
if (layout === 'post') {
el += partial('_partial/main/article/article_footer')
}
el += `</article>`
if (layout === 'post' || page.wiki) {
el += partial('_partial/main/article/read_next')
}
if (layout === 'post') {
el += partial('_partial/main/article/related_posts')
}
el += partial('_partial/plugins/comments/layout')
return el
}
%>

View File

@ -1,33 +0,0 @@
<%
if (page.menu_id == undefined) {
page.menu_id = 'post';
}
if (page.header == undefined) {
page.header = false;
}
function layoutTitle() {
const title = page.h1 != null ? page.h1 : page.title;
if (title && title.length > 0) {
return '<h1 class="article-title"><span>' + title + '</span></h1>';
} else {
return '';
}
}
let post = page;
let heti = '';
if (theme.plugins.heti && theme.plugins.heti.enable) {
heti = ' heti';
}
%>
<%- partial('_partial/main/navbar/breadcrumb') %>
<article class='md-text content<%- heti %> <%- post.layout %><%- scrollreveal() %>'>
<%- layoutTitle() %>
<%- post.content %>
<% if (theme.plugins.tianli_gpt.enable && ['all', 'post'].includes(theme.plugins.tianli_gpt.field)) { %>
<%- partial('_partial/plugins/ai/tianli_gpt') %>
<% } %>
<%- partial('_partial/main/article/article_footer') %>
</article>
<%- partial('_partial/main/article/read_next') %>
<%- partial('_partial/main/article/related_posts') %>
<%- partial('_partial/plugins/comments/layout') %>

View File

@ -9,7 +9,7 @@ if (page.menu_id == undefined) {
<% page.layout = 'tags'; %>
<%- partial('_partial/main/navbar/nav_tabs_blog') %>
<div class='post-list'>
<article class='<%- scrollreveal() %>' id='tags'>
<article class='<%- scrollreveal("") %>' id='tags'>
<% site.tags.sort('length', -1).each(function(tag){ %>
<a class='tag' href="<%= url_for(tag.path) %>">
<span class='name'><%= tag.name %></span>

View File

@ -1,32 +0,0 @@
<%
if (page.menu_id == undefined) {
page.menu_id = 'wiki';
}
if (page.title == undefined) {
if (page.tagName) {
page.title = page.tagName;
} else {
page.title = __('btn.wiki');
}
}
function layoutTitle() {
const title = page.h1 != null ? page.h1 : page.title;
if (title && title.length > 0) {
return '<h1 class="article-title"><span>' + title + '</span></h1>';
} else {
return '';
}
}
%>
<%- partial('_partial/main/navbar/breadcrumb') %>
<article class='md-text content <%- page.layout %><%- scrollreveal() %>'>
<%- layoutTitle() %>
<%- page.content %>
<% if (theme.plugins.tianli_gpt.enable && ['all', 'wiki'].includes(theme.plugins.tianli_gpt.field)) { %>
<%- partial('_partial/plugins/ai/tianli_gpt') %>
<% } %>
<%- partial('_partial/main/article/article_footer') %>
</article>
<%- partial('_partial/main/article/read_next') %>
<%- partial('_partial/plugins/comments/layout') %>

View File

@ -7,57 +7,55 @@
'use strict';
const path = require('path');
const path = require('path')
module.exports = hexo => {
module.exports = ctx => {
const { cache, language_switcher } = hexo.theme.config;
const { cache, language_switcher } = ctx.theme.config
const warning = function(...args) {
hexo.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`);
};
ctx.log.warn(`Since ${args[0]} is turned on, the ${args[1]} is disabled to avoid potential hazards.`)
}
if (cache && cache.enable && language_switcher) {
warning('language_switcher', 'caching');
cache.enable = false;
warning('language_switcher', 'caching')
cache.enable = false
}
if (cache && cache.enable && hexo.config.relative_link) {
warning('caching', '`relative_link` option in Hexo `_config.yml`');
hexo.config.relative_link = false;
if (cache && cache.enable && ctx.config.relative_link) {
warning('caching', '`relative_link` option in Hexo `_config.yml`')
ctx.config.relative_link = false
}
// hexo.config.meta_generator = false;
// ctx.config.meta_generator = false;
// merge data
const data = hexo.locals.get('data');
const data = ctx.locals.get('data')
// merge widgets
var widgets = hexo.render.renderSync({ path: path.join(hexo.theme_dir, '_data/widgets.yml'), engine: 'yaml' });
var widgets = ctx.render.renderSync({ path: path.join(ctx.theme_dir, '_data/widgets.yml'), engine: 'yaml' })
if (data.widgets) {
for (let i of Object.keys(data.widgets)) {
let widget = data.widgets[i];
let widget = data.widgets[i]
if (widget == null || widget.length == 0) {
// delete
delete widgets[i];
delete widgets[i]
} else {
// create
if (widgets[i] == null) {
widgets[i] = widget;
widgets[i] = widget
} else {
// merge
for (let j of Object.keys(widget)) {
widgets[i][j] = widget[j];
widgets[i][j] = widget[j]
}
}
}
}
}
if (hexo.theme.config.data == undefined) {
hexo.theme.config.data = {};
}
hexo.theme.config.data['widgets'] = widgets;
ctx.theme.config.widgets = widgets
// default menu
if (hexo.theme.config.menu == undefined) {
hexo.theme.config.menu = {};
if (ctx.theme.config.menubar == undefined) {
ctx.theme.config.menubar = {}
}
};
}

View File

@ -55,7 +55,7 @@ module.exports = ctx => {
var wiki = getWikiObject(ctx)
const pages = ctx.locals.get('pages')
// wiki 所有页面
const wiki_pages = pages.filter(p => (p.layout === 'wiki')).map(p => new WikiPage(p))
const wiki_pages = pages.filter(p => (p.wiki != null)).map(p => new WikiPage(p))
const wiki_list = Object.keys(wiki.tree)
// 上架的项目列表
wiki.shelf = ctx.locals.get('data').wiki || []

View File

@ -28,7 +28,8 @@ hexo.extend.generator.register('wiki', function (locals) {
layout: 'index_wiki',
menu_id: site_tree.wiki.menu_id,
filter: true,
tagName: tag.name
tagName: tag.name,
title: tag.name
}
})
}

View File

@ -1,9 +1,9 @@
'use strict';
hexo.extend.helper.register('scrollreveal', function(args){
const cfg = hexo.theme.config;
if (cfg.plugins.scrollreveal && cfg.plugins.scrollreveal.enable) {
return ' reveal';
hexo.extend.helper.register('scrollreveal', function(args) {
if (hexo.theme.config.plugins.scrollreveal?.enable) {
return `${args ? args : ''}slide-up`
} else {
return ''
}
return '';
});
})

View File

@ -41,7 +41,6 @@
transform: translateX(-320px)
margin: 0
left: 8px
background: var(--site-bg)
box-shadow: $boxshadow-card-float
z-index: 10
.l_main

View File

@ -14,12 +14,6 @@
background-size: cover
if hexo-config('style.sidebar.background')
background-image: convert(hexo-config('style.sidebar.background'))
.sidebar-bg
position absolute
width: 100%
height: 100%
object-fit: cover
background: var(--text-meta)
.sidebar-container
height: 100%
display: flex

View File

@ -1,2 +1,2 @@
.reveal
.slide-up
visibility: hidden

View File

@ -197,13 +197,16 @@ init.registerTabsTag()
// scrollreveal
if (stellar.plugins.scrollreveal) {
stellar.loadScript(stellar.plugins.scrollreveal.js).then(function () {
ScrollReveal().reveal("body .reveal", {
const slideUp = {
distance: stellar.plugins.scrollreveal.distance,
duration: stellar.plugins.scrollreveal.duration,
interval: stellar.plugins.scrollreveal.interval,
scale: stellar.plugins.scrollreveal.scale,
opacity: 0,
easing: "ease-out"
});
}
ScrollReveal().reveal('.l_left .slide-up', slideUp)
ScrollReveal().reveal('.l_main .slide-up', slideUp)
})
}