Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryc127 committed Jun 6, 2023
2 parents 6e0b290 + 507780e commit c90b00f
Show file tree
Hide file tree
Showing 44 changed files with 467 additions and 411 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<div align="right">
Language:
🇺🇸
<a title="Chinese" href="/README_CN.md">🇨🇳</a>
<a title="Chinese" href="/README_CN.md">中文</a>
</div>

# hexo-theme-butterfly
Expand All @@ -14,7 +12,7 @@

![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/theme-butterfly-readme.png)

Demo: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [CrazyWong](https://crazywong.com/)
Demo: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [CrazyWong](https://blog.crazywong.com/)

Docs: 📖 [Butterfly Docs](https://butterfly.js.org/posts/21cfbf15/)

Expand Down Expand Up @@ -62,17 +60,17 @@ npm i hexo-theme-butterfly

- [x] Card UI Design
- [X] Support sub-menu
- [x] Two Column designs
- [x] Two-column layout
- [x] Responsive Web Design
- [x] Dark Mode
- [x] Pjax
- [x] Read Mode
- [x] Conversion between Traditional and Simplified Chinese
- [X] TOC catalog is available for both computers and mobile phones
- [X] Color themes (darker/pale night/light/ocean/mac/mac light), support custom colors
- [X] Built-in Syntax Highlighting Themes (darker/pale night/light/ocean/mac/mac light), also support customization
- [X] Code Blocks (Display code language/close or expand Code Blocks/Copy Button/word wrap)
- [X] Disable copy/Add a Copyright Notice to the Copied Text
- [X] Search (Algolia SearchZ/Local Search)
- [X] Search (Algolia Search/Local Search)
- [x] Mathjax and Katex
- [x] Built-in 404 page
- [x] WordCount
Expand Down
8 changes: 3 additions & 5 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<div align="right">
語言:
中文
<a title="English" href="/README.md">英文</a>
<a title="English" href="/README.md">English</a>
</div>

# hexo-theme-butterfly
Expand All @@ -14,7 +12,7 @@

![](https://cdn.jsdelivr.net/gh/jerryc127/CDN@m2/img/theme-butterfly-readme.png)

預覽: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [CrazyWong](https://crazywong.com/)
預覽: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [CrazyWong](https://blog.crazywong.com/)

文檔: 📖 [Butterfly Docs](https://butterfly.js.org/posts/21cfbf15/)

Expand Down Expand Up @@ -72,7 +70,7 @@ theme: butterfly
- [X] 內置多種代碼配色(darker/pale night/light/ocean/mac/mac light),可自定義代碼配色
- [X] 代碼塊顯示代碼語言/關閉或展開代碼塊/代碼複製/代碼自動換行
- [X] 可關閉文字複製/可開啟內容複製增加版權信息)
- [X] 兩種搜索(Algolia搜索和本地搜索
- [X] 兩種搜索( Algolia 搜索和本地搜索
- [x] Mathjax 和 Katex
- [x] 內置404頁面
- [x] 顯示字數統計
Expand Down
5 changes: 5 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,11 @@ background:
# Footer Background
footer_bg: false

# Add mask to header or footer (为 header 或 footer 添加黑色半透遮罩)
mask:
header: true
footer: true

# the position of bottom right button/default unit: px (右下角按鈕距離底部的距離/默認單位為px)
rightside-bottom:

Expand Down
2 changes: 1 addition & 1 deletion layout/includes/header/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ header#page-header(class=`${isHomeClass+isFixedClass}` style=bg_img)
span#subtitle
if(theme.social)
#site_social_icons
!=fragment_cache('social', function(){return partial('includes/header/social')})
!=partial('includes/header/social', {}, {cache: true})
#scroll-down
i.fas.fa-angle-down.scroll-down-effects
else
Expand Down
34 changes: 19 additions & 15 deletions layout/includes/loading/fullpage-loading.pug
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
.loading-word= _p('loading')

script.
const preloader = {
endLoading: () => {
document.body.style.overflow = '';
document.getElementById('loading-box').classList.add("loaded")
},
initLoading: () => {
document.body.style.overflow = 'hidden';
document.getElementById('loading-box').classList.remove("loaded")
(()=>{
const $loadingBox = document.getElementById('loading-box')
const $body = document.body
const preloader = {
endLoading: () => {
$body.style.overflow = ''
$loadingBox.classList.add('loaded')
},
initLoading: () => {
$body.style.overflow = 'hidden'
$loadingBox.classList.remove('loaded')
}
}
}

preloader.initLoading()
window.addEventListener('load',()=> { preloader.endLoading() })
preloader.initLoading()
window.addEventListener('load',() => { preloader.endLoading() })

if (!{theme.pjax && theme.pjax.enable}) {
document.addEventListener('pjax:send', () => { preloader.initLoading() })
document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}
if (!{theme.pjax && theme.pjax.enable}) {
document.addEventListener('pjax:send', () => { preloader.initLoading() })
document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}
})()
4 changes: 2 additions & 2 deletions layout/includes/mixins/post-ui.pug
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mixin postUI(posts)
block
span.article-meta-label= ' ' + _p('card_post_count')

if theme.comments.card_post_count
if theme.comments.card_post_count && theme.comments.use
case theme.comments.use[0]
when 'Disqus'
+countBlockInIndex
Expand All @@ -89,7 +89,7 @@ mixin postUI(posts)
when 'Waline'
+countBlockInIndex
a(href=url_for(link) + '#post-comment')
span.waline-comment-count(id=url_for(link))
span.waline-comment-count(data-path=url_for(link))
i.fa-solid.fa-spinner.fa-spin
when 'Twikoo'
+countBlockInIndex
Expand Down
70 changes: 41 additions & 29 deletions layout/includes/page/flink.pug
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
#article-container
.flink
- let pageContent = page.content
if page.flink_url
- let { content, random, flink_url } = page
- let pageContent = content

if flink_url || random
- const linkData = flink_url ? false : site.data.link || false
script.
(()=>{
const replaceSymbol = (str) => {
return str.replace(/[\p{P}\p{S}]/gu, "-")
}

let result = ""
fetch("!{url_for(page.flink_url)}")
.then(response => response.json())
.then(str => {
for(let i = 0; i < str.length; i++){
const replaceClassName = replaceSymbol(str[i].class_name)
const className = str[i].class_name ? `<h2 id="${replaceClassName}"><a href="#${replaceClassName}" class="headerlink" title="${str[i].class_name}"></a>${str[i].class_name}</h2>` : ""
const classDesc = str[i].class_desc ? `<div class="flink-desc">${str[i].class_desc}</div>` : ""

let listResult = ""
const lists = str[i].link_list
for(let j = 0; j < lists.length; j++){
listResult += `
<div class="flink-list-item">
<a href="${lists[j].link}" title="${lists[j].name}" target="_blank">
<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-desc" title="${lists[j].descr}">${lists[j].descr}</div>
</a>
</div>`
}
const add = (str) => {
for(let i = 0; i < str.length; i++){
const replaceClassName = replaceSymbol(str[i].class_name)
const className = str[i].class_name ? `<h2 id="${replaceClassName}"><a href="#${replaceClassName}" class="headerlink" title="${str[i].class_name}"></a>${str[i].class_name}</h2>` : ""
const classDesc = str[i].class_desc ? `<div class="flink-desc">${str[i].class_desc}</div>` : ""

result += `${className}${classDesc} <div class="flink-list">${listResult}</div>`
let listResult = ""
const lists = str[i].link_list
if (!{random === true}) {
lists.sort(() => Math.random() - 0.5)
}
for(let j = 0; j < lists.length; j++){
listResult += `
<div class="flink-list-item">
<a href="${lists[j].link}" title="${lists[j].name}" target="_blank">
<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-desc" title="${lists[j].descr}">${lists[j].descr}</div>
</a>
</div>`
}

document.querySelector(".flink").insertAdjacentHTML("afterbegin", result)
window.lazyLoadInstance && window.lazyLoadInstance.update()
})
result += `${className}${classDesc} <div class="flink-list">${listResult}</div>`
}

document.querySelector(".flink").insertAdjacentHTML("afterbegin", result)
window.lazyLoadInstance && window.lazyLoadInstance.update()
}

const linkData = !{JSON.stringify(linkData)}
if (!{Boolean(flink_url)}) {
fetch("!{url_for(flink_url)}")
.then(response => response.json())
.then(add)
} else if (linkData) {
add(linkData)
}
})()

else
Expand Down Expand Up @@ -67,4 +80,3 @@

- pageContent = result + pageContent
!= pageContent

2 changes: 1 addition & 1 deletion layout/includes/rightside.pug
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mixin rightsideItem(array)
i.fas.fa-list-ul
when 'chat'
if chat_btn
button#chat_btn(type="button" title=_p("rightside.chat"))
button#chat-btn(type="button" title=_p("rightside.chat"))
i.fas.fa-sms
when 'comment'
if commentsJsLoad
Expand Down
2 changes: 1 addition & 1 deletion layout/includes/sidebar.pug
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
.headline= _p('aside.categories')
.length-num= site.categories.length

hr
hr.custom-hr
!=partial('includes/header/menu_item', {}, {cache: true})
35 changes: 25 additions & 10 deletions layout/includes/third-party/card-post-count/artalk.pug
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,34 @@

script.
(() => {
const getArtalkCount = () => {
const runWidget = () => {
Artalk.loadCountWidget({
server: '!{server}',
site: '!{site}',
countEl: '.artalk-count'
const getArtalkCount = async() => {
try {
const eleGroup = document.querySelectorAll('#recent-posts .artalk-count')
const keyArray = Array.from(eleGroup).map(i => i.getAttribute('data-page-key'))

const headerList = {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': window.location.origin
},
body: new URLSearchParams({
'site_name': '!{site}',
'type':'page_comment',
'page_keys': keyArray
})
}

const res = await fetch('!{server}/api/stat', headerList)
const result = await res.json()

keyArray.forEach((key, index) => {
eleGroup[index].textContent = result.data[key] || 0
})
} catch (err) {
console.error(err)
}

if (typeof Artalk === 'function') runWidget()
else getScript('!{theme.asset.artalk_js}').then(runWidget)
}


window.pjax ? getArtalkCount() : window.addEventListener('load', getArtalkCount)
})()
24 changes: 13 additions & 11 deletions layout/includes/third-party/card-post-count/waline.pug
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
script.
(() => {
function loadWaline () {
function initWaline () {
let initData = {
el: null,
serverURL: '!{theme.waline.serverURL}',
comment: true
}
const waline = Waline.init(initData)
}
async function loadWaline () {
try {
const eleGroup = document.querySelectorAll('#recent-posts .waline-comment-count')
const keyArray = Array.from(eleGroup).map(i => i.getAttribute('data-path'))

if (typeof Waline === 'object') initWaline()
else getScript('!{url_for(theme.asset.waline_js)}').then(initWaline)
const res = await fetch(`!{theme.waline.serverURL}/api/comment?type=count&url=${keyArray}`, { method: 'GET' })
const result = await res.json()

result.data.forEach((count, index) => {
eleGroup[index].textContent = count
})
} catch (err) {
console.error(err)
}
}

window.pjax ? loadWaline() : window.addEventListener('load', loadWaline)
Expand Down
Loading

0 comments on commit c90b00f

Please sign in to comment.