update theme to butterfly

This commit is contained in:
2026-01-05 19:48:25 +08:00
parent a2934b5576
commit 9619cab07b
33 changed files with 440 additions and 999 deletions

View File

@@ -52,7 +52,7 @@ div
!= partial("includes/third-party/umami_analytics", {}, { cache: true })
if theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv
script(async data-pjax src= theme.asset.busuanzi || '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js')
script(async data-pjax src=theme.asset.busuanzi ? url_for(theme.asset.busuanzi) : '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js')
!= partial('includes/third-party/search/index', {}, { cache: true })

View File

@@ -13,9 +13,32 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
!=partial('includes/loading/index', {}, {cache: true})
if theme.background
#web_bg(style=getBgPath(theme.background))
if !Array.isArray(theme.background)
#web_bg.bg-animation(style=getBgPath(theme.background))
else
#web_bg.bg-animation
- const bgStyleArr = theme.background.map(getBgPath)
script.
(() => {
const arr = !{JSON.stringify(bgStyleArr)}
const webBgDiv = document.getElementById('web_bg')
const setRandomBg = () => {
webBgDiv.style = arr[Math.floor(Math.random() * arr.length)]
requestAnimationFrame(() => webBgDiv.classList.add('bg-animation'))
}
document.addEventListener('pjax:send', () => {
webBgDiv.style = ''
webBgDiv.classList.remove('bg-animation')
})
document.addEventListener('pjax:complete', setRandomBg)
document.addEventListener('DOMContentLoaded', setRandomBg)
})()
!=partial('includes/sidebar', {}, {cache: true})
#body-wrap(class=pageType)
include ./header/index.pug
@@ -33,5 +56,4 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
!=partial('includes/footer', {}, {cache: true})
include ./rightside.pug
include ./additional-js.pug
!=partial('includes/rightmenu',{}, {cache:true})
include ./additional-js.pug

View File

@@ -49,6 +49,7 @@
if !page.shuoshuo_url
script(type='application/json' id='shuoshuo-data')!= safeJSON(localDate)
- const { enable, native, placeholder, field } = theme.lazyload
script.
(() => {
const limitConfig = !{ JSON.stringify(page.limit || {}) }
@@ -84,6 +85,36 @@
return `${year}-${month}-${day} ${hour}:${minute}:${second}`
}
const addLazyload = str => {
const config = {
enable: !{Boolean(enable)},
native: !{Boolean(native)},
field: '!{field}',
placeholder: '!{url_for(placeholder)}',
}
if (!config.enable || config.field !== 'site') return str
const parser = new DOMParser()
const doc = parser.parseFromString(str, 'text/html')
const images = doc.querySelectorAll('img')
images.forEach(img => {
if (config.native) {
img.setAttribute('loading', 'lazy')
} else {
const src = img.getAttribute('src')
img.setAttribute('data-lazy-src', src)
if (config.placeholder) {
img.setAttribute('src', config.placeholder)
} else {
img.removeAttribute('src')
}
}
})
return doc.body.innerHTML
}
let currentPage = 1
const itemsPerPage = 8
let totalPages = 0
@@ -117,7 +148,7 @@
</time>
</div>
</div>
<div class="shuoshuo-content">${item.content}</div>
<div class="shuoshuo-content">${addLazyload(item.content)}</div>
<div class="shuoshuo-footer ${tags ? 'flex-between' : 'flex-end'}">
${tags ? `<div class="shuoshuo-tags">${tags}</div>` : ''}
${commentButton}

View File

@@ -19,7 +19,7 @@ if page.total !== 1
a.pagination-related(class=className href=url_for(direction.path) title=direction.title)
if direction.cover_type === 'img'
img.cover(src=url_for(direction.cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt=`cover of ${key === 'prev' ? 'previous' : 'next'} post`)
img.cover(src=url_for(direction.pagination_cover || direction.cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt=`cover of ${key === 'prev' ? 'previous' : 'next'} post`)
else
.cover(style=`background: ${direction.cover || 'var(--default-bg-color)'}`)

View File

@@ -51,8 +51,8 @@ script.
const loadArtalk = async (el, pageKey) => {
if (typeof Artalk === 'object') initArtalk(el, pageKey)
else {
await btf.getCSS('!{theme.asset.artalk_css}')
await btf.getScript('!{theme.asset.artalk_js}')
await btf.getCSS('!{url_for(theme.asset.artalk_css)}')
await btf.getScript('!{url_for(theme.asset.artalk_js)}')
initArtalk(el, pageKey)
}
}

View File

@@ -6,7 +6,11 @@ script.
ele.forEach((item, index) => {
const mermaidSrc = item.firstElementChild
const mermaidThemeConfig = `%%{init:{ 'theme':'${theme}'}}%%\n`
const config = mermaidSrc.dataset.config ? JSON.parse(mermaidSrc.dataset.config) : {}
if (!config.theme) {
config.theme = theme
}
const mermaidThemeConfig = `%%{init: ${JSON.stringify(config)}}%%\n`
const mermaidID = `mermaid-${index}`
const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent

View File

@@ -14,9 +14,9 @@ if choose
else
- pjaxSelectors.unshift('meta[name="description"]')
script(src=url_for(theme.asset.pjax))
script(src=url_for(theme.asset.pjax) defer)
script.
(() => {
document.addEventListener('DOMContentLoaded', () => {
const pjaxSelectors = !{JSON.stringify(pjaxSelectors)}
window.pjax = new Pjax({
@@ -65,10 +65,9 @@ script.
document.addEventListener('pjax:error', e => {
if (e.request.status === 404) {
const usePjax = !{theme.pjax && theme.pjax.enable}
!{theme.error_404 && theme.error_404.enable}
? (usePjax ? pjax.loadUrl('!{url_for("/404.html")}') : window.location.href = '!{url_for("/404.html")}')
? pjax.loadUrl('!{url_for("/404.html")}')
: window.location.href = e.request.responseURL
}
})
})()
})

View File

@@ -17,7 +17,7 @@ if (syntax_highlighter === 'prismjs' || enable) && !preprocess
btf.addGlobalFn('encrypt', highlightAll, 'prismjs')
})()
script(src=url_for(prismjs_js))
script(src=url_for(prismjs_autoloader))
script(src=url_for(prismjs_js) defer)
script(src=url_for(prismjs_autoloader) defer)
if (line_number)
script(src=url_for(prismjs_lineNumber_js))
script(src=url_for(prismjs_lineNumber_js) defer)

View File

@@ -31,7 +31,7 @@ script.
const getData = async (isPost) => {
try {
const now = Date.now()
const keyUrl = isPost ? `&url=${window.location.pathname}` : ''
const keyUrl = isPost ? `&url=${window.location.pathname}&path=${window.location.pathname}` : ''
const headerList = { 'Accept': 'application/json' }
if (!{isServerURL}) {
@@ -62,8 +62,8 @@ script.
const pagePV = document.getElementById('umamiPV')
if (pagePV) {
const data = await getData(true)
if (data && data.pageviews && typeof data.pageviews.value !== 'undefined') {
pagePV.textContent = data.pageviews.value
if (data && data.pageviews) {
pagePV.textContent = typeof data.pageviews.value !== 'undefined' ? data.pageviews.value : data.pageviews
} else {
console.warn('Umami Analytics: Invalid page view data received')
}
@@ -75,8 +75,8 @@ script.
if (config.site_uv) {
const siteUV = document.getElementById('umami-site-uv')
if (siteUV && data && data.visitors && typeof data.visitors.value !== 'undefined') {
siteUV.textContent = data.visitors.value
if (siteUV && data && data.visitors) {
siteUV.textContent = typeof data.visitors.value !== 'undefined' ? data.visitors.value : data.visitors
} else if (siteUV) {
console.warn('Umami Analytics: Invalid site UV data received')
}
@@ -84,8 +84,8 @@ script.
if (config.site_pv) {
const sitePV = document.getElementById('umami-site-pv')
if (sitePV && data && data.pageviews && typeof data.pageviews.value !== 'undefined') {
sitePV.textContent = data.pageviews.value
if (sitePV && data && data.pageviews) {
sitePV.textContent = typeof data.pageviews.value !== 'undefined' ? data.pageviews.value : data.pageviews
} else if (sitePV) {
console.warn('Umami Analytics: Invalid site PV data received')
}