add theme

This commit is contained in:
2025-08-12 12:19:25 +08:00
parent 8c06923a46
commit ac0d1944ab
227 changed files with 18962 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
if theme.Open_Graph_meta.enable
-
const coverVal = page.cover_type === 'img' ? page.cover : theme.avatar.img
let ogOption = Object.assign({
type: globalPageType === 'post' ? 'article' : 'website',
image: coverVal ? full_url_for(coverVal) : '',
fb_admins: theme.facebook_comments.user_id || '',
fb_app_id: theme.facebook_comments.app_id || '',
}, theme.Open_Graph_meta.option)
-
!= open_graph(ogOption)
else
- const description = page.description || page.content || page.title || config.description
if description
meta(name="description" content=truncate(description, 150))

View File

@@ -0,0 +1,45 @@
if theme.baidu_analytics
script.
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?!{theme.baidu_analytics}";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
btf.addGlobalFn('pjaxComplete', () => {
_hmt.push(['_trackPageview',window.location.pathname])
}, 'baidu_analytics')
if theme.google_analytics
script(async src=`https://www.googletagmanager.com/gtag/js?id=${theme.google_analytics}`)
script.
window.dataLayer = window.dataLayer || []
function gtag(){dataLayer.push(arguments)}
gtag('js', new Date())
gtag('config', '!{theme.google_analytics}')
btf.addGlobalFn('pjaxComplete', () => {
gtag('config', '!{theme.google_analytics}', {'page_path': window.location.pathname})
}, 'google_analytics')
if theme.cloudflare_analytics
script(defer data-pjax src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon=`{"token": "${theme.cloudflare_analytics}"}`)
if theme.microsoft_clarity
script.
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "!{theme.microsoft_clarity}");
if (theme.google_tag_manager && theme.google_tag_manager.tag_id)
script.
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
"!{theme.google_tag_manager.domain ? theme.google_tag_manager.domain : 'https://www.googletagmanager.com'}/gtm.js?id="+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','!{theme.google_tag_manager.tag_id}');
btf.addGlobalFn('pjaxComplete', () => {
dataLayer.push({'event': 'pjaxComplete', 'page_title': document.title, 'page_location': location.href, 'page_path': window.location.pathname})
}, 'google_tag_manager')

View File

@@ -0,0 +1,126 @@
-
let algolia = 'undefined'
if (theme.search.use === 'algolia_search') {
const { ALGOLIA_APP_ID, ALGOLIA_API_KEY, ALGOLIA_INDEX_NAME } = process.env
const { appId, applicationID, apiKey, indexName } = config.algolia
algolia = JSON.stringify({
appId: ALGOLIA_APP_ID || appId || applicationID,
apiKey: ALGOLIA_API_KEY || apiKey,
indexName: ALGOLIA_INDEX_NAME || indexName,
hitsPerPage: theme.search.algolia_search.hitsPerPage,
// search languages
languages: {
input_placeholder: theme.search.placeholder || _p("search.input_placeholder"),
hits_empty: _p("search.algolia_search.hits_empty"),
hits_stats: _p("search.algolia_search.hits_stats"),
}
})
}
let localSearch = 'undefined'
if (theme.search.use === 'local_search') {
const { CDN, preload, top_n_per_article, unescape } = theme.search.local_search
localSearch = JSON.stringify({
path: CDN || config.root + config.search.path,
preload,
top_n_per_article,
unescape,
languages: {
// search languages
hits_empty: _p("search.local_search.hits_empty"),
hits_stats: _p("search.local_search.hits_stats"),
}
})
}
let translate = 'undefined'
if (theme.translate && theme.translate.enable){
translate = JSON.stringify({
defaultEncoding: theme.translate.defaultEncoding,
translateDelay: theme.translate.translateDelay,
msgToTraditionalChinese: theme.translate.msgToTraditionalChinese,
msgToSimplifiedChinese: theme.translate.msgToSimplifiedChinese
})
}
let copyright = 'undefined'
if (theme.copy.enable && theme.copy.copyright.enable){
copyright = JSON.stringify({
limitCount: theme.copy.copyright.limit_count,
languages: {
author: _p("copy_copyright.author") + ': ' + config.author,
link: _p("copy_copyright.link") + ': ',
source: _p("copy_copyright.source") + ': ' + config.title,
info: _p("copy_copyright.info")
}
})
}
let Snackbar = 'undefined'
if (theme.snackbar && theme.snackbar.enable) {
Snackbar = JSON.stringify({
chs_to_cht: _p("Snackbar.chs_to_cht"),
cht_to_chs: _p("Snackbar.cht_to_chs"),
day_to_night: _p("Snackbar.day_to_night"),
night_to_day: _p("Snackbar.night_to_day"),
bgLight: theme.snackbar.bg_light,
bgDark: theme.snackbar.bg_dark,
position: theme.snackbar.position,
})
}
let highlight = 'undefined'
let syntaxHighlighter = config.syntax_highlighter
let highlightEnable = syntaxHighlighter ? ['highlight.js', 'prismjs'].includes(syntaxHighlighter) : (config.highlight.enable || config.prismjs.enable)
if (highlightEnable) {
const { copy, language, height_limit, fullpage, macStyle } = theme.code_blocks
highlight = JSON.stringify({
plugin: syntaxHighlighter ? syntaxHighlighter : config.highlight.enable ? 'highlight.js' : 'prismjs',
highlightCopy: copy,
highlightLang: language,
highlightHeightLimit: height_limit,
highlightFullpage: fullpage,
highlightMacStyle: macStyle
})
}
script.
const GLOBAL_CONFIG = {
root: '!{config.root}',
algolia: !{algolia},
localSearch: !{localSearch},
translate: !{translate},
highlight: !{highlight},
copy: {
success: '!{_p("copy.success")}',
error: '!{_p("copy.error")}',
noSupport: '!{_p("copy.noSupport")}'
},
relativeDate: {
homepage: !{theme.post_meta.page.date_format === 'relative'},
post: !{theme.post_meta.post.date_format === 'relative'}
},
runtime: '!{theme.aside.card_webinfo.runtime_date ? _p("aside.card_webinfo.runtime.unit") : ""}',
dateSuffix: {
just: '!{_p("date_suffix.just")}',
min: '!{_p("date_suffix.min")}',
hour: '!{_p("date_suffix.hour")}',
day: '!{_p("date_suffix.day")}',
month: '!{_p("date_suffix.month")}'
},
copyright: !{copyright},
lightbox: '!{ theme.lightbox || 'null' }',
Snackbar: !{Snackbar},
infinitegrid: {
js: '!{url_for(theme.asset.egjs_infinitegrid)}',
buttonText: '!{_p("load_more")}'
},
isPhotoFigcaption: !{theme.photofigcaption},
islazyloadPlugin: !{theme.lazyload.enable && !theme.lazyload.native},
isAnchor: !{theme.anchor.auto_update || false},
percent: {
toc: !{theme.toc.scroll_percent},
rightside: !{theme.rightside_scroll_percent},
},
autoDarkmode: !{theme.darkmode.enable && theme.darkmode.autoChangeMode === 1}
}

View File

@@ -0,0 +1,25 @@
-
const titleVal = pageTitle.replace(/'/ig,"\\'")
let isHighlightShrink
if (theme.code_blocks.shrink == 'none') isHighlightShrink = 'undefined'
else if (typeof page.highlight_shrink == 'boolean') isHighlightShrink = page.highlight_shrink
else isHighlightShrink = theme.code_blocks.shrink
var showToc = false
if (theme.aside.enable && page.aside !== false) {
let tocEnable = false
if (globalPageType === 'post' && theme.toc.post) tocEnable = true
else if (globalPageType === 'page' && theme.toc.page) tocEnable = true
const pageToc = typeof page.toc === 'boolean' ? page.toc : tocEnable
showToc = pageToc && (toc(page.content) !== '' || page.encrypt === true)
}
-
script#config-diff.
var GLOBAL_CONFIG_SITE = {
title: '!{titleVal}',
isHighlightShrink: !{isHighlightShrink},
isToc: !{showToc},
pageType: '!{page.type == 'shuoshuo' ? 'shuoshuo' : globalPageType}'
}

View File

@@ -0,0 +1,9 @@
if (theme.google_adsense && theme.google_adsense.enable)
script(async src=theme.google_adsense.js)
if theme.google_adsense.auto_ads
script.
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: '!{theme.google_adsense.client}',
enable_page_level_ads: '!{theme.google_adsense.enable_page_level_ads}'
});

View File

@@ -0,0 +1,35 @@
-
const { internal_provider, third_party_provider, custom_format } = theme.CDN
const providers = {
'jsdelivr': '//cdn.jsdelivr.net',
'cdnjs': '//cdnjs.cloudflare.com',
'unpkg': '//unpkg.com',
'custom': custom_format && custom_format.match(/^((https?:)?(\/\/[^/]+)|([^/]+))(\/|$)/)[1]
}
-
if internal_provider === third_party_provider && internal_provider !== 'local'
link(rel="preconnect" href=providers[internal_provider])
else
if internal_provider !== 'local'
link(rel="preconnect" href=providers[internal_provider])
if third_party_provider !== 'local'
link(rel="preconnect" href=providers[third_party_provider])
if theme.google_analytics
link(rel="preconnect" href="//www.google-analytics.com" crossorigin='')
if theme.baidu_analytics
link(rel="preconnect" href="//hm.baidu.com")
if theme.cloudflare_analytics
link(rel="preconnect" href="//static.cloudflareinsights.com")
if theme.microsoft_clarity
link(rel="preconnect" href="//www.clarity.ms")
if theme.blog_title_font && theme.blog_title_font.font_link && theme.blog_title_font.font_link.indexOf('//fonts.googleapis.com') != -1
link(rel="preconnect" href="//fonts.googleapis.com" crossorigin='')
if !theme.asset.busuanzi && (theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv)
link(rel="preconnect" href="//busuanzi.ibruce.info")

View File

@@ -0,0 +1,13 @@
- const { manifest, theme_color, apple_touch_icon, favicon_32_32, favicon_16_16, mask_icon } = theme.pwa
link(rel="manifest" href=url_for(manifest))
if theme_color
meta(name="msapplication-TileColor" content=theme_color)
if apple_touch_icon
link(rel="apple-touch-icon" sizes="180x180" href=url_for(apple_touch_icon))
if favicon_32_32
link(rel="icon" type="image/png" sizes="32x32" href=url_for(favicon_32_32))
if favicon_16_16
link(rel="icon" type="image/png" sizes="16x16" href=url_for(favicon_16_16))
if mask_icon
link(rel="mask-icon" href=url_for(mask_icon) color="#5bbad5")

View File

@@ -0,0 +1,3 @@
if theme.site_verification
each item in theme.site_verification
meta(name=item.name content=item.content)

View File

@@ -0,0 +1,55 @@
if theme.structured_data
if page.layout === 'post'
-
// https://developers.google.com/search/docs/appearance/structured-data/article
const title = page.title
const url = page.permalink
const imageVal = page.cover_type === 'img' ? page.cover : theme.avatar.img
const image = imageVal ? full_url_for(imageVal) : ''
const datePublished = page.date.toISOString()
const dateModified = (page.updated || page.date).toISOString()
const author = page.copyright_author || config.author
const authorHrefVal = page.copyright_author_href || theme.post_copyright.author_href || config.url
const authorHref = full_url_for(authorHrefVal)
const jsonLd = {
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": title,
"url": url,
"image": image,
"datePublished": datePublished,
"dateModified": dateModified,
"author": [{
"@type": "Person",
"name": author,
"url": authorHref
}]
}
jsonLdScript = JSON.stringify(jsonLd, null, 2)
-
else if is_home() && (!page.current || page.current === 1)
-
// https://developers.google.com/search/docs/appearance/site-names#website
const baseUrl = config.url;
const currentPath = url_for('/');
const isRootOrSubdomain = currentPath.split('/').filter(Boolean).length === 0;
if (isRootOrSubdomain) {
const jsonLd = {
"@context": "https://schema.org",
"@type": "WebSite",
"name": config.title,
"url": full_url_for('/'),
}
jsonLdScript = JSON.stringify(jsonLd, null, 2)
}
-
script(type="application/ld+json").
!{jsonLdScript}