Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryc127 committed Jan 10, 2025
2 parents a1caed1 + 172a8ee commit 0dc6aed
Show file tree
Hide file tree
Showing 70 changed files with 636 additions and 540 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ npm i hexo-theme-butterfly
- [x] Chart.js
- [x] Justified Gallery
- [x] Lazyload images
- [x] Instantpage/Pangu/Snackbar notification toast/PWA......
- [x] Instantpage/Snackbar notification toast/PWA......

## ✨ Contributors

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ theme: butterfly
- [x] Chart.js 圖表顯示
- [x] 照片牆
- [x] 圖片懶加載
- [x] Instantpage/Pangu/Snackbar彈窗/PWA......
- [x] Instantpage/Snackbar彈窗/PWA......

## ✨ 貢獻者

Expand Down
12 changes: 4 additions & 8 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -983,13 +983,6 @@ snackbar:
# https://instant.page/
instantpage: false

# Pangu - Insert a space between Chinese character and English character
# https://github.com/vinta/pangu.js
pangu:
enable: false
# Specify the field to use pangu (site or post)
field: site

# Lazyload
# https://github.com/verlok/vanilla-lazyload
lazyload:
Expand Down Expand Up @@ -1023,6 +1016,10 @@ Open_Graph_meta:
# fb_admins:
# fb_app_id:

# Structured Data
# https://developers.google.com/search/docs/guides/intro-structured-data
structured_data: true

# Add the vendor prefixes to ensure compatibility
css_prefix: true

Expand Down Expand Up @@ -1092,7 +1089,6 @@ CDN:
# medium_zoom:
# mermaid:
# meting_js:
# pangu:
# prismjs_autoloader:
# prismjs_js:
# prismjs_lineNumber_js:
Expand Down
7 changes: 2 additions & 5 deletions layout/includes/additional-js.pug
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ div
if theme.instantpage
script(src=url_for(theme.asset.instantpage), type='module')

if theme.lazyload.enable
if theme.lazyload.enable && !theme.lazyload.native
script(src=url_for(theme.asset.lazyload))

if theme.snackbar.enable
script(src=url_for(theme.asset.snackbar))

if theme.pangu.enable
!= partial("includes/third-party/pangu.pug", {}, { cache: true })

.js-pjax
if needLoadCountJs
!= partial("includes/third-party/card-post-count/index", {}, { cache: true })
Expand All @@ -36,7 +33,7 @@ div
!= partial("includes/third-party/prismjs", {}, { cache: true })

if theme.aside.enable && theme.aside.card_newest_comments.enable
if theme.pjax.enable || (!is_post() && page.aside !== false)
if theme.pjax.enable || (globalPageType !== 'post' && page.aside !== false)
!= partial("includes/third-party/newest-comments/index", {}, { cache: true })

!= fragment_cache('injectBottom', function(){return injectHtml(theme.inject.bottom)})
Expand Down
21 changes: 15 additions & 6 deletions layout/includes/head.pug
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
- var pageTitle
- is_archive() ? page.title = findArchivesTitle(page, theme.menu, date) : ''
- if (is_tag()) pageTitle = _p('page.tag') + ': ' + page.tag
- else if (is_category()) pageTitle = _p('page.category') + ': ' + page.category
- else if (is_current('/404.html', [strict])) pageTitle = _p('error404')
- else pageTitle = page.title || config.title || ''
- globalPageType === 'archive' ? page.title = findArchivesTitle(page, theme.menu, date) : ''
case globalPageType
when 'tag'
- pageTitle = _p('page.tag') + ': ' + page.tag
when 'category'
- pageTitle = _p('page.category') + ': ' + page.category
when '404'
- pageTitle = _p('error404')
default
- pageTitle = page.title || config.title || ''


- var isSubtitle = config.subtitle ? ' - ' + config.subtitle : ''
- var tabTitle = is_home() || !pageTitle ? config.title + isSubtitle : pageTitle + ' | ' + config.title
- var tabTitle = globalPageType === 'home' || !pageTitle ? config.title + isSubtitle : pageTitle + ' | ' + config.title
- var pageAuthor = config.email ? config.author + ',' + config.email : config.author
- var pageCopyright = config.copyright || config.author
- var themeColorLight = theme.theme_color && theme.theme_color.enable && theme.theme_color.meta_theme_color_light || '#ffffff'
Expand All @@ -25,6 +31,9 @@ meta(name="theme-color" content=themeColor)
//- Open_Graph
include ./head/Open_Graph.pug

//- Structured Data
include ./head/structured_data.pug

!=favicon_tag(theme.favicon || config.favicon)
link(rel="canonical" href=urlNoIndex(null,config.pretty_urls.trailing_index,config.pretty_urls.trailing_html))

Expand Down
2 changes: 1 addition & 1 deletion layout/includes/head/Open_Graph.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if theme.Open_Graph_meta.enable
-
const coverVal = page.cover_type === 'img' ? page.cover : theme.avatar.img
let ogOption = Object.assign({
type: is_post() ? 'article' : 'website',
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 || '',
Expand Down
2 changes: 1 addition & 1 deletion layout/includes/head/analytics.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if theme.baidu_analytics
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?!{theme.baidu_analytics}";
var s = document.getElementsByTagName("script")[0];
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
btf.addGlobalFn('pjaxComplete', () => {
Expand Down
2 changes: 1 addition & 1 deletion layout/includes/head/config.pug
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ script.
buttonText: '!{_p("load_more")}'
},
isPhotoFigcaption: !{theme.photofigcaption},
islazyload: !{theme.lazyload.enable},
islazyloadPlugin: !{theme.lazyload.enable && !theme.lazyload.native},
isAnchor: !{theme.anchor.auto_update || false},
percent: {
toc: !{theme.toc.scroll_percent},
Expand Down
8 changes: 3 additions & 5 deletions layout/includes/head/config_site.pug
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
var showToc = false
if (theme.aside.enable && page.aside !== false) {
let tocEnable = false
if (is_post() && theme.toc.post) tocEnable = true
else if (is_page() && theme.toc.page) tocEnable = true
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)
}
Expand All @@ -19,9 +19,7 @@
script#config-diff.
var GLOBAL_CONFIG_SITE = {
title: '!{titleVal}',
isPost: !{is_post()},
isHome: !{is_home()},
isHighlightShrink: !{isHighlightShrink},
isToc: !{showToc},
isShuoshuo: !{page.type == 'shuoshuo'}
pageType: '!{page.type == 'shuoshuo' ? 'shuoshuo' : globalPageType}'
}
2 changes: 1 addition & 1 deletion layout/includes/head/preconnect.pug
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if internal_provider === third_party_provider && internal_provider !== 'local'
link(rel="preconnect" href=providers[internal_provider])
else
else
if internal_provider !== 'local'
link(rel="preconnect" href=providers[internal_provider])
if third_party_provider !== 'local'
Expand Down
34 changes: 34 additions & 0 deletions layout/includes/head/structured_data.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
if theme.structured_data && page.layout === 'post'
-
// use json-ld to add structured data
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 || site.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);
-
script(type="application/ld+json").
!{jsonLdScript}
41 changes: 20 additions & 21 deletions layout/includes/header/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,32 @@
var bg_img = ''
if !theme.disable_top_img && page.top_img !== false
if is_post()
- top_img = page.top_img || page.cover || theme.default_top_img
else if is_page()
- top_img = page.top_img || theme.default_top_img
else if is_tag()
- top_img = theme.tag_per_img && theme.tag_per_img[page.tag]
- top_img = top_img || returnTopImg(theme.tag_img)
else if is_category()
- top_img = theme.category_per_img && theme.category_per_img[page.category]
- top_img = top_img || returnTopImg(theme.category_img)
else if is_home()
- top_img = returnTopImg(theme.index_img)
else if is_archive()
- top_img = returnTopImg(theme.archive_img)
else
- top_img = page.top_img || theme.default_top_img
case globalPageType
when 'post'
- top_img = page.top_img || page.cover || theme.default_top_img
when 'page'
- top_img = page.top_img || theme.default_top_img
when 'tag'
- top_img = theme.tag_per_img && theme.tag_per_img[page.tag] || returnTopImg(theme.tag_img)
when 'category'
- top_img = theme.category_per_img && theme.category_per_img[page.category] || returnTopImg(theme.category_img)
when 'home'
- top_img = returnTopImg(theme.index_img)
when 'archive'
- top_img = returnTopImg(theme.archive_img)
default
- top_img = page.top_img || theme.default_top_img

if top_img !== false
- bg_img = getBgPath(top_img)
- headerClassName = is_home() ? 'full_page' : is_post() ? 'post-bg' : 'not-home-page'
- headerClassName = globalPageType === 'home' ? 'full_page' : globalPageType === 'post' ? 'post-bg' : 'not-home-page'

header#page-header(class=`${headerClassName + isFixedClass}` style=bg_img)
include ./nav.pug
if top_img !== false
if is_post()
if globalPageType === 'post'
include ./post-info.pug
else if is_home()
else if globalPageType === 'home'
#site-info
h1#site-title=config.title
if theme.subtitle.enable
Expand All @@ -48,6 +47,6 @@ header#page-header(class=`${headerClassName + isFixedClass}` style=bg_img)
#page-site-info
h1#site-title=page.title || page.tag || page.category
else
//- improvement seo
if !is_post()
//- improve seo
if globalPageType !== 'post'
h1.title-seo=page.title || page.tag || page.category || config.title
2 changes: 1 addition & 1 deletion layout/includes/header/nav.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ nav#nav
img.site-icon(src=url_for(theme.nav.logo) alt='Logo')
if theme.nav.display_title
span.site-name=config.title
if is_post()
if globalPageType === 'post'
a.nav-page-title(href=url_for('/'))
span.site-name=(page.title || config.title)
#menus
Expand Down
7 changes: 4 additions & 3 deletions layout/includes/layout.pug
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
- var globalPageType = getPageType(page, is_home)
- var htmlClassHideAside = theme.aside.enable && theme.aside.hide ? 'hide-aside' : ''
- page.aside = is_archive() ? theme.aside.display.archive: is_category() ? theme.aside.display.category : is_tag() ? theme.aside.display.tag : page.aside
- page.aside = globalPageType === 'archive' ? theme.aside.display.archive: globalPageType === 'category' ? theme.aside.display.category : globalPageType === 'tag' ? theme.aside.display.tag : page.aside
- var hideAside = !theme.aside.enable || page.aside === false ? 'hide-aside' : ''
- var pageType = is_post() ? 'post' : 'page'
- var pageType = globalPageType === 'post' ? 'post' : 'page'
- pageType = page.type ? pageType + ' type-' + page.type : pageType

doctype html
Expand All @@ -13,7 +14,7 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside

if theme.background
#web_bg(style=getBgPath(theme.background))

!=partial('includes/sidebar', {}, {cache: true})

#body-wrap(class=pageType)
Expand Down
8 changes: 4 additions & 4 deletions layout/includes/mixins/indexPostUI.pug
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mixin indexPostUI()
- const leftOrRight = indexLayout === 3 ? (index % 2 === 0 ? 'left' : 'right') : (indexLayout === 2 ? 'right' : '')
- const post_cover = article.cover
- const no_cover = article.cover === false || !theme.cover.index_enable ? 'no-cover' : ''

if post_cover && theme.cover.index_enable
.post_cover(class=leftOrRight)
a(href=url_for(link) title=title)
Expand All @@ -20,7 +20,7 @@ mixin indexPostUI()
div.post-bg(style=`background: ${post_cover}`)
.recent-post-info(class=no_cover)
a.article-title(href=url_for(link) title=title)
if is_home() && (article.top || article.sticky > 0)
if globalPageType === 'home' && (article.top || article.sticky > 0)
i.fas.fa-thumbtack.sticky
= title
.article-meta-wrap
Expand Down Expand Up @@ -58,7 +58,7 @@ mixin indexPostUI()
a(href=url_for(item.path)).article-meta__tags #[=item.name]
if index < article.tags.data.length - 1
span.article-meta-link #[='']

mixin countBlockInIndex
- needLoadCountJs = true
span.article-meta
Expand All @@ -67,7 +67,7 @@ mixin indexPostUI()
if block
block
span.article-meta-label= ' ' + _p('card_post_count')

if theme.comments.card_post_count && theme.comments.use
case theme.comments.use[0]
when 'Disqus'
Expand Down
6 changes: 3 additions & 3 deletions layout/includes/page/flink.pug
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="flink-item-icon">
<img class="no-lightbox" src="${lists[j].avatar}" onerror='this.onerror=null;this.src="!{url_for(theme.error_img.flink)}"' alt="${lists[j].name}" />
</div>
<div class="flink-item-name">${lists[j].name}</div>
<div class="flink-item-name">${lists[j].name}</div>
<div class="flink-item-desc" title="${lists[j].descr}">${lists[j].descr}</div>
</a>
</div>`
Expand Down Expand Up @@ -63,14 +63,14 @@
- let listResult = ""

each j in i.link_list
-
-
listResult += `
<div class="flink-list-item">
<a href="${j.link}" title="${j.name}" target="_blank">
<div class="flink-item-icon">
<img class="no-lightbox" src="${j.avatar}" onerror='this.onerror=null;this.src="${url_for(theme.error_img.flink)}"' alt="${j.name}" />
</div>
<div class="flink-item-name">${j.name}</div>
<div class="flink-item-name">${j.name}</div>
<div class="flink-item-desc" title="${j.descr}">${j.descr}</div>
</a>
</div>`
Expand Down
8 changes: 4 additions & 4 deletions layout/includes/pagination.pug
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
escape: false
}
if is_post()
if globalPageType === 'post'
- let paginationOrder = theme.post_pagination === 1 ? { prev: page.prev, next: page.next } : { prev: page.next, next: page.prev }

nav#pagination.pagination-post
Expand All @@ -15,13 +15,13 @@ if is_post()
- const getPostDesc = direction.postDesc || postDesc(direction)
- let className = key === 'prev' ? (paginationOrder.next ? '' : 'full-width') : (paginationOrder.prev ? '' : 'full-width')
- className = getPostDesc ? className : className + ' no-desc'

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`)
else
.cover(style=`background: ${direction.cover || 'var(--default-bg-color)'}`)

.info(class=key === 'prev' ? '' : 'text-right')
.info-1
.info-item-1=_p(`pagination.${key}`)
Expand All @@ -32,6 +32,6 @@ if is_post()
else
nav#pagination
.pagination
if is_home()
if globalPageType === 'home'
- options.format = 'page/%d/#content-inner'
!=paginator(options)
Loading

0 comments on commit 0dc6aed

Please sign in to comment.