Compare commits

...

37 Commits
4.6.0 ... 4.8.1

Author SHA1 Message Date
Jerry
496234c8ad fix: 修復 CDN 的 internal_provider 設為 jsdelivr 時,主題的 js 無法加載的 bug 2023-04-10 20:30:16 +08:00
Jerry
8d5ca45948 fix merge 2023-04-10 16:49:53 +08:00
Jerry
04e36c8d8a feat: 發佈 4.8.0
feat: 支持自定義 giscus 評論系統的 JS 地址
2023-04-10 16:45:45 +08:00
Jerry Wong
5c2894d3d5 Merge pull request #1252 from Lea321/dev
新增自定义深浅模式切换时间
2023-04-10 00:38:49 +08:00
Leonus
63353566d2 新增自定义深浅模式切换时间 2023-04-09 00:03:08 +08:00
Jerry
f0588a3967 代码优化 2023-04-08 21:09:43 +08:00
Jerry
0834720d32 代码优化 2023-04-08 21:02:27 +08:00
Jerry Wong
183d01b9eb Merge pull request #1248 from youngjuning/patch-3
chore: 优化 viewport seo
2023-04-08 15:30:03 +08:00
Jerry Wong
7e8d666bf7 Merge pull request #1241 from JamesY-Jey/add-social-style
新增给social配置添加样式参数
2023-04-08 15:11:17 +08:00
Jerry Wong
49b6c7436c Update _config.yml 2023-04-08 15:10:56 +08:00
洛竹
1e24c62f70 chore: 优化 viewport seo
https://www.omiod.com/meta-seo-inspector/meta-info.php?meta=viewport&utm_source=MSI_app&utm_medium=info_link&utm_term=viewport
2023-04-04 18:38:55 +08:00
JamesYao
5e30032a5f Merge branch 'add-social-style' of https://github.com/JamesY-Jey/hexo-theme-butterfly into add-social-style 2023-04-04 15:38:04 +08:00
JamesYao
47214b5a7c feat: add social icon color config 2023-04-04 15:37:55 +08:00
JamesYao
d62f047073 Merge branch 'jerryc127:dev' into add-social-style 2023-04-04 10:13:48 +08:00
Jerry Wong
5a13f01649 Merge pull request #1239 from LittleNyima/patch-abcjs
feat: 支持abcjs乐谱渲染
2023-04-03 18:53:53 +08:00
Jerry Wong
09b7342882 Merge branch 'dev' into patch-abcjs 2023-04-03 18:53:40 +08:00
Jerry
4c9395666d update 2023-04-03 18:51:42 +08:00
LittleNyima
f4d0687750 minor adjustments 2023-04-03 16:23:02 +08:00
Jerry Wong
e80ecb43ef Merge pull request #1245 from youngjuning/patch-2
chore: 宽屏 1500px 有些浪费空间,增加到 1700px
2023-04-03 15:04:17 +08:00
洛竹
93f7461d28 chore: 宽屏 1500px 有些浪费空间,增加到 1700px 2023-04-03 10:43:55 +08:00
JamesYao
841fbb0c5e Add social config style 2023-03-30 17:11:59 +08:00
LittleNyima
247e62a418 resolve conflicts with dev branch 2023-03-30 10:16:23 +08:00
Jerry
8199e25215 feat: 重構本地搜索
feat: Algolia 搜索,點擊文章內容也會跳轉到相應頁面
fix: 修復 fullpage loading 顯示滾動條的 bug close #1235
fix: 修復 safari 下,搜索內容被系統搜索框遮擋的 bug
improvement: 手機 safari 橫屏時,網頁全屏幕顯示
improvement: 當沒有開啟 beautify 時, hr 顯示默認的樣式
2023-03-28 20:40:43 +08:00
LittleNyima
b34eeb0425 feat: 支持abcjs乐谱渲染
- 添加相关可配置选项
 - 添加渲染与组件注册相关脚本
 - 添加默认cdn配置
2023-03-28 14:14:15 +08:00
Jerry
63dc605794 Merge branch 'dev' of https://github.com/jerryc127/hexo-theme-butterfly into dev 2023-03-09 22:43:36 +08:00
Jerry
a7d6d0fb80 breaking changes: CDN 配置了 version 為 true, 本地鏈接也會加上版本號 closed #1218
breaking changes: CDN option 部分參數名字修改
feat: 升級 fancybox 到 v5
feat: 更新 facebook js 版本
feat: 移除 gitter 聊天插件 closed #1212
improvement: 社交圖標 hover 旋轉180度 closed #1195
improvement: 代碼優化
fix: 開啟 archor 後, pace.js 會隨着 archor 添加而觸發的問題
fix: 修復設置圖片時,圖片後綴大寫而導致識別錯誤的 bug closed #1205
2023-03-09 22:35:41 +08:00
Jerry Wong
768d9e370b Merge pull request #1219 from Weidows/patch-1
card_tags.color: true 时遇到limit失效问题
2023-03-04 13:16:46 +08:00
齐下无贰
a3e46f757b Update card_tags.pug 2023-03-04 10:53:34 +08:00
Jerry
431b5fa7ce update 2023-02-20 17:23:00 +08:00
Jerry
8a50b80527 update 2023-02-20 17:21:01 +08:00
Jerry
3694ee01df Merge branch 'dev' of https://github.com/jerryc127/hexo-theme-butterfly into dev 2023-02-12 17:01:43 +08:00
Jerry
c579dad041 feat: gallery 標籤外掛增加 json 獲取
feat: 本地搜索,點擊文章內容也會跳轉到相應頁面
feat: 添加 docsearch
feat: 標籤頁支持配置 orderby 和 order 參數
feat: card_tags 可配置 orderby 和 order 參數
fix: 修復本地搜索,輸入 ?d 報錯的 bug closed #1192
fix: 修復 waline 在 pjax 模式下 css 沒有加載的 bug
fix: 修復 artalk 最新評論無法加載 closed #1191
fix: 修復 card_author 和 card_announcement 設為 false 後,aside 卡片沒有間距的 bug closed #1174
improvement: getCSS 重構
2023-02-12 16:56:18 +08:00
Jerry Wong
5baf759749 Merge pull request #1190 from SakuraWald/pr
FIX mathjax在ajax啓用時,可能的重置錯誤
2023-02-12 16:26:07 +08:00
SakuraWald
532b74edde FIX mathjax在ajax啓用時,可能的重置錯誤 2023-02-08 07:25:06 +08:00
Jerry
08fabdc2d1 update package.json 2023-01-18 20:27:31 +08:00
Jerry
6a50b62869 remove: 移除多余的代码 2023-01-17 15:02:42 +08:00
Jerry
396fb102da feat: 可配置 typed.js 的參數 closed #1154
fix: 修復 typeJSFn 重複賦值的 bug
fix: 修復固定狀態欄後,標題有陰影的 bug
fix: 修復 gallery 標籤將圖片鏈接截斷導致404無法加載圖片的 bug closed #1160
fix: 修復開啟導航欄固定後,點擊部分滾動向上的按鈕,滾動的目標部分被導航欄遮擋的 bug closed #1158
fix: 修復固定導航欄後,toc 被遮擋的 closed #1159
fix: 切換簡繁時,會改變 html 的 lang 屬性
2023-01-17 14:46:55 +08:00
59 changed files with 1052 additions and 715 deletions

View File

@@ -81,7 +81,7 @@ npm i hexo-theme-butterfly
- [x] Share (AddThis/Sharejs/Addtoany)
- [X] Comment (Disqus/Disqusjs/Livere/Gitalk/Valine/Waline/Utterances/Facebook Comments/Twikoo/Giscus/Remark42/artalk)
- [x] Multiple Comment System Support
- [x] Online Chats (Chatra/Tidio/Daovoice/Gitter/Crisp/messenger)
- [x] Online Chats (Chatra/Tidio/Daovoice/Crisp/messenger)
- [x] Web analytics
- [x] Google AdSense
- [x] Webmaster Verification

View File

@@ -81,7 +81,7 @@ theme: butterfly
- [x] 多種分享系統AddThis/Sharejs/Addtoany
- [X] 多種評論系統Disqus/Disqusjs/Livere/Gitalk/Valine/Waline/Utterances/Facebook Comments/Twikoo/Giscus/Remark42/artalk
- [x] 支持雙評論部署
- [x] 多種在線聊天Chatra/Tidio/Daovoice/Gitter/Crisp/messenger
- [x] 多種在線聊天Chatra/Tidio/Daovoice/Crisp/messenger
- [x] 多種分析系統
- [x] 谷歌廣告/手動廣告位置
- [x] 各種站長驗證Google/Bing/Baidu/360/Yandex

View File

@@ -1,7 +1,13 @@
# Main menu navigation (導航目錄)
# see https://butterfly.js.org/posts/4aa8abbe/#導航菜單
# Navigation bar settings (導航欄設置)
# see https://butterfly.js.org/posts/4aa8abbe/##導航欄設置-Navigation-bar-settings
# --------------------------------------
nav:
logo: # image
display_title: true
fixed: false # fixed navigation bar
# Menu 目錄
menu:
# Home: / || fas fa-home
# Archives: /archives/ || fas fa-archive
@@ -13,11 +19,6 @@ menu:
# Link: /link/ || fas fa-link
# About: /about/ || fas fa-heart
nav:
logo: # image
display_title: true
fixed: false # fixed navigation bar
# Code Blocks (代碼相關)
# --------------------------------------
@@ -28,54 +29,12 @@ highlight_shrink: false # true: shrink the code blocks / false: expand the code
highlight_height_limit: false # unit: px
code_word_wrap: false
# copy settings
# copyright: Add the copyright information after copied content (複製的內容後面加上版權信息)
copy:
enable: true
copyright:
enable: false
limit_count: 50
# social settings (社交圖標設置)
# Social Settings (社交圖標設置)
# formal:
# icon: link || the description
# icon: link || the description || color
social:
# fab fa-github: https://github.com/xxxxx || Github
# fas fa-envelope: mailto:xxxxxx@gmail.com || Email
# search (搜索)
# see https://butterfly.js.org/posts/ceeb73f/#搜索系統
# --------------------------------------
# Algolia search
algolia_search:
enable: false
hits:
per_page: 6
# Local search
local_search:
enable: false
preload: false
CDN:
# Math (數學)
# --------------------------------------
# About the per_page
# if you set it to true, it will load mathjax/katex script in each page (true 表示每一頁都加載js)
# if you set it to false, it will load mathjax/katex script according to your setting (add the 'mathjax: true' in page's front-matter)
# (false 需要時加載,須在使用的 Markdown Front-matter 加上 mathjax: true)
# MathJax
mathjax:
enable: false
per_page: false
# KaTeX
katex:
enable: false
per_page: false
hide_scrollbar: true
# fab fa-github: https://github.com/xxxxx || Github || '#24292e'
# fas fa-envelope: mailto:xxxxxx@gmail.com || Email || '#4a7dbe'
# Image (圖片設置)
# --------------------------------------
@@ -155,14 +114,6 @@ post_meta:
tags: true # true or false 文章頁是否顯示標籤
label: true # true or false 顯示描述性文字
# wordcount (字數統計)
# see https://butterfly.js.org/posts/ceeb73f/#字數統計
wordcount:
enable: false
post_wordcount: true
min2read: true
total_wordcount: true
# Display the article introduction on homepage
# 1: description
# 2: both (if the description exists, it will show description, or show the auto_excerpt)
@@ -180,6 +131,17 @@ anchor:
icon: # the unicode value of Font Awesome icon, such as '\3423'
auto_update: false # when you scroll in post, the URL will update according to header id.
# figcaption (圖片描述文字)
photofigcaption: false
# copy settings
# copyright: Add the copyright information after copied content (複製的內容後面加上版權信息)
copy:
enable: true
copyright:
enable: false
limit_count: 50
# Post
# --------------------------------------
@@ -224,9 +186,6 @@ related_post:
limit: 6 # Number of posts displayed
date_type: created # or created or updated 文章日期顯示創建日或者更新日
# figcaption (圖片描述文字)
photofigcaption: false
# post_pagination (分頁)
# value: 1 || 2 || false
# 1: The 'next post' will link to old post
@@ -243,7 +202,183 @@ noticeOutdate:
message_prev: It has been
message_next: days since the last update, the content of the article may be outdated.
# Share System (分享功能)
# Footer Settings
# --------------------------------------
footer:
owner:
enable: true
since: 2020
custom_text:
copyright: true # Copyright of theme and framework
# aside (側邊欄)
# --------------------------------------
aside:
enable: true
hide: false
button: true
mobile: true # display on mobile
position: right # left or right
display:
archive: true
tag: true
category: true
card_author:
enable: true
description:
button:
enable: true
icon: fab fa-github
text: Follow Me
link: https://github.com/xxxxxx
card_announcement:
enable: true
content: This is my Blog
card_recent_post:
enable: true
limit: 5 # if set 0 will show all
sort: date # date or updated
sort_order: # Don't modify the setting unless you know how it works
card_categories:
enable: true
limit: 8 # if set 0 will show all
expand: none # none/true/false
sort_order: # Don't modify the setting unless you know how it works
card_tags:
enable: true
limit: 40 # if set 0 will show all
color: false
orderby: random # Order of tags, random/name/length
order: 1 # Sort of order. 1, asc for ascending; -1, desc for descending
sort_order: # Don't modify the setting unless you know how it works
card_archives:
enable: true
type: monthly # yearly or monthly
format: MMMM YYYY # eg: YYYY年MM月
order: -1 # Sort of order. 1, asc for ascending; -1, desc for descending
limit: 8 # if set 0 will show all
sort_order: # Don't modify the setting unless you know how it works
card_webinfo:
enable: true
post_count: true
last_push_date: true
sort_order: # Don't modify the setting unless you know how it works
# busuanzi count for PV / UV in site
# 訪問人數
busuanzi:
site_uv: true
site_pv: true
page_pv: true
# Time difference between publish date and now (網頁運行時間)
# Formal: Month/Day/Year Time or Year/Month/Day Time
runtimeshow:
enable: false
publish_date:
# Aside widget - Newest Comments
newest_comments:
enable: false
sort_order: # Don't modify the setting unless you know how it works
limit: 6
storage: 10 # unit: mins, save data to localStorage
avatar: true
# Bottom right button (右下角按鈕)
# --------------------------------------
# Conversion between Traditional and Simplified Chinese (簡繁轉換)
translate:
enable: false
# The text of a button
default:
# the language of website (1 - Traditional Chinese/ 2 - Simplified Chinese
defaultEncoding: 2
# Time delay
translateDelay: 0
# The text of the button when the language is Simplified Chinese
msgToTraditionalChinese: '繁'
# The text of the button when the language is Traditional Chinese
msgToSimplifiedChinese: '簡'
# Read Mode (閲讀模式)
readmode: true
# dark mode
darkmode:
enable: true
# Toggle Button to switch dark/light mode
button: true
# Switch dark/light mode automatically (自動切換 dark mode和 light mode)
# autoChangeMode: 1 Following System Settings, if the system doesn't support dark mode, it will switch dark mode between 6 pm to 6 am
# autoChangeMode: 2 Switch dark mode between 6 pm to 6 am
# autoChangeMode: false
autoChangeMode: false
# Set the light mode time. The value is between 0 and 24. If not set, the default value is 6 and 18
start: # 8
end: # 22
# show scroll percent in scroll-to-top button
rightside_scroll_percent: false
# Don't modify the following settings unless you know how they work (非必要請不要修改 )
# Choose: readmode,translate,darkmode,hideAside,toc,chat,comment
# Don't repeat 不要重複
rightside_item_order:
enable: false
hide: # readmode,translate,darkmode,hideAside
show: # toc,chat,comment
# Math (數學)
# --------------------------------------
# About the per_page
# if you set it to true, it will load mathjax/katex script in each page (true 表示每一頁都加載js)
# if you set it to false, it will load mathjax/katex script according to your setting (add the 'mathjax: true' in page's front-matter)
# (false 需要時加載,須在使用的 Markdown Front-matter 加上 mathjax: true)
# MathJax
mathjax:
enable: false
per_page: false
# KaTeX
katex:
enable: false
per_page: false
hide_scrollbar: true
# search (搜索)
# see https://butterfly.js.org/posts/ceeb73f/#搜索系統
# --------------------------------------
# Algolia search
algolia_search:
enable: false
hits:
per_page: 6
# Local search
local_search:
enable: false
# Preload the search data when the page loads.
preload: false
# Show top n results per article, show all results by setting to -1
top_n_per_article: 1
# Unescape html strings to the readable one.
unescape: false
CDN:
# Docsearch
docsearch:
enable: false
appId:
apiKey:
indexName:
option:
# Share System (分享)
# --------------------------------------
# AddThis
@@ -407,12 +542,6 @@ daovoice:
enable: false
app_id:
# gitter
# https://gitter.im/
gitter:
enable: false
room:
# crisp
# https://crisp.chat/en/
crisp:
@@ -426,15 +555,6 @@ messenger:
pageID:
lang: zh_TW # Language en_US/zh_CN/zh_TW and so on
# Footer Settings
# --------------------------------------
footer:
owner:
enable: true
since: 2020
custom_text:
copyright: true # Copyright of theme and framework
# Analysis
# --------------------------------------
@@ -531,6 +651,14 @@ rightside-bottom:
# Enter transitions (開啓網頁進入效果)
enter_transitions: true
# Typewriter Effect (打字效果)
# https://github.com/disjukr/activate-power-mode
activate_power_mode:
enable: false
colorful: true # open particle animation (冒光特效)
shake: true # open shake (抖動特效)
mobile: false
# Background effects (背景特效)
# --------------------------------------
@@ -559,14 +687,6 @@ canvas_nest:
count: 99 # the number of lines, default: 99.
mobile: false
# Typewriter Effect (打字效果)
# https://github.com/disjukr/activate-power-mode
activate_power_mode:
enable: false
colorful: true # open particle animation (冒光特效)
shake: true # open shake (抖動特效)
mobile: false
# Mouse click effects: fireworks (鼠標點擊效果: 煙火特效)
fireworks:
enable: false
@@ -625,12 +745,9 @@ subtitle:
enable: false
# Typewriter Effect (打字效果)
effect: true
# Effect Speed Options (打字效果速度參數)
startDelay: 300 # time before typing starts in milliseconds
typeSpeed: 150 # type speed in milliseconds
backSpeed: 50 # backspacing speed in milliseconds
# loop (循環打字)
loop: true
# Customize typed.js (配置typed.js)
# https://github.com/mattboldt/typed.js/#customization
typed_option:
# source 調用第三方服務
# source: false 關閉調用
# source: 1 調用一言網的一句話(簡體) https://hitokoto.cn/
@@ -651,120 +768,13 @@ preloader:
# pace theme (see https://codebyzach.github.io/pace/)
pace_css_url:
# aside (側邊欄)
# --------------------------------------
aside:
enable: true
hide: false
button: true
mobile: true # display on mobile
position: right # left or right
display:
archive: true
tag: true
category: true
card_author:
enable: true
description:
button:
enable: true
icon: fab fa-github
text: Follow Me
link: https://github.com/xxxxxx
card_announcement:
enable: true
content: This is my Blog
card_recent_post:
enable: true
limit: 5 # if set 0 will show all
sort: date # date or updated
sort_order: # Don't modify the setting unless you know how it works
card_categories:
enable: true
limit: 8 # if set 0 will show all
expand: none # none/true/false
sort_order: # Don't modify the setting unless you know how it works
card_tags:
enable: true
limit: 40 # if set 0 will show all
color: false
sort_order: # Don't modify the setting unless you know how it works
card_archives:
enable: true
type: monthly # yearly or monthly
format: MMMM YYYY # eg: YYYY年MM月
order: -1 # Sort of order. 1, asc for ascending; -1, desc for descending
limit: 8 # if set 0 will show all
sort_order: # Don't modify the setting unless you know how it works
card_webinfo:
enable: true
post_count: true
last_push_date: true
sort_order: # Don't modify the setting unless you know how it works
# busuanzi count for PV / UV in site
# 訪問人數
busuanzi:
site_uv: true
site_pv: true
page_pv: true
# Time difference between publish date and now (網頁運行時間)
# Formal: Month/Day/Year Time or Year/Month/Day Time
runtimeshow:
# wordcount (字數統計)
# see https://butterfly.js.org/posts/ceeb73f/#字數統計
wordcount:
enable: false
publish_date:
# Aside widget - Newest Comments
newest_comments:
enable: false
sort_order: # Don't modify the setting unless you know how it works
limit: 6
storage: 10 # unit: mins, save data to localStorage
avatar: true
# Bottom right button (右下角按鈕)
# --------------------------------------
# Conversion between Traditional and Simplified Chinese (簡繁轉換)
translate:
enable: false
# The text of a button
default:
# the language of website (1 - Traditional Chinese/ 2 - Simplified Chinese
defaultEncoding: 2
# Time delay
translateDelay: 0
# The text of the button when the language is Simplified Chinese
msgToTraditionalChinese: '繁'
# The text of the button when the language is Traditional Chinese
msgToSimplifiedChinese: '簡'
# Read Mode (閲讀模式)
readmode: true
# dark mode
darkmode:
enable: true
# Toggle Button to switch dark/light mode
button: true
# Switch dark/light mode automatically (自動切換 dark mode和 light mode)
# autoChangeMode: 1 Following System Settings, if the system doesn't support dark mode, it will switch dark mode between 6 pm to 6 am
# autoChangeMode: 2 Switch dark mode between 6 pm to 6 am
# autoChangeMode: false
autoChangeMode: false
# show scroll percent in scroll-to-top button
rightside_scroll_percent: false
# Don't modify the following settings unless you know how they work (非必要請不要修改 )
# Choose: readmode,translate,darkmode,hideAside,toc,chat,comment
# Don't repeat 不要重複
rightside_item_order:
enable: false
hide: # readmode,translate,darkmode,hideAside
show: # toc,chat,comment
post_wordcount: true
min2read: true
total_wordcount: true
# Lightbox (圖片大圖查看模式)
# --------------------------------------
@@ -775,12 +785,18 @@ rightside_item_order:
medium_zoom: false
# fancybox
# http://fancyapps.com/fancybox/3/
# https://fancyapps.com/fancybox/
fancybox: true
# Tag Plugins settings (標籤外掛)
# --------------------------------------
# abcjs (樂譜渲染)
# See https://github.com/paulrosen/abcjs
abcjs:
enable: false
per_page: true
# mermaid
# see https://github.com/mermaid-js/mermaid
mermaid:
@@ -899,7 +915,7 @@ CDN:
# when set it to local, you need to install hexo-butterfly-extjs
third_party_provider: jsdelivr
# Add version number to CDN, true or false
# Add version number to url, true or false
version: false
# Custom format
@@ -913,8 +929,10 @@ CDN:
# translate:
# local_search:
# algolia_js:
# algolia_search_v4:
# instantsearch_v4:
# algolia_search:
# instantsearch:
# docsearch_js:
# docsearch_css:
# pjax:
# gitalk:
# gitalk_css:
@@ -925,6 +943,7 @@ CDN:
# twikoo:
# waline_js:
# waline_css:
# giscus:
# sharejs:
# sharejs_css:
# mathjax:
@@ -938,8 +957,8 @@ CDN:
# instantpage:
# typed:
# pangu:
# fancybox_css_v4:
# fancybox_v4:
# fancybox_css:
# fancybox:
# medium_zoom:
# snackbar_css:
# snackbar:
@@ -947,7 +966,7 @@ CDN:
# fireworks:
# click_heart:
# ClickShowText:
# fontawesomeV6:
# fontawesome:
# flickr_justified_gallery_js:
# flickr_justified_gallery_css:
# aplayer_css:
@@ -958,3 +977,5 @@ CDN:
# prismjs_autoloader:
# artalk_js:
# artalk_css:
# busuanzi:
# abcjs_basic_js:

View File

@@ -45,6 +45,7 @@ search:
local_search:
input_placeholder: Search for Posts
hits_empty: "We didn't find any results for the search: ${query}"
hits_stats: '${hits} results found'
pagination:
prev: Previous Post

View File

@@ -45,6 +45,7 @@ search:
local_search:
input_placeholder: Search for Posts
hits_empty: "We didn't find any results for the search: ${query}"
hits_stats: '${hits} results found'
pagination:
prev: Previous Post

View File

@@ -46,6 +46,7 @@ search:
local_search:
input_placeholder: 搜索文章
hits_empty: '找不到您查询的内容:${query}'
hits_stats: '共找到 ${hits} 篇文章'
pagination:
prev: 上一篇

View File

@@ -46,7 +46,8 @@ search:
local_search:
input_placeholder: 搜尋文章
hits_empty: '找不到您查詢的內容:${query}'
hits_stats: '共找到 ${hits} 篇文章'
pagination:
prev: 上一篇
next: 下一篇

View File

@@ -8,7 +8,7 @@ div
if theme.medium_zoom
script(src=url_for(theme.asset.medium_zoom))
else if theme.fancybox
script(src=url_for(theme.asset.fancybox_v4))
script(src=url_for(theme.asset.fancybox))
if theme.instantpage
script(src=url_for(theme.asset.instantpage), type='module')
@@ -22,14 +22,6 @@ div
if theme.pangu.enable
!= partial("includes/third-party/pangu.pug", {}, { cache: true })
//- search
if theme.algolia_search.enable
script(src=url_for(theme.asset.algolia_search_v4))
script(src=url_for(theme.asset.instantsearch_v4))
script(src=url_for(theme.asset.algolia_js))
else if theme.local_search.enable
script(src=url_for(theme.asset.local_search))
.js-pjax
if needLoadCountJs
!= partial("includes/third-party/card-post-count/index", {}, { cache: true })
@@ -39,6 +31,8 @@ div
include ./third-party/math/index.pug
include ./third-party/abcjs/index.pug
if commentsJsLoad
include ./third-party/comments/js.pug
@@ -67,3 +61,5 @@ div
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')
!=partial('includes/third-party/search/index', {}, {cache: true})

View File

@@ -15,7 +15,7 @@
meta(charset='UTF-8')
meta(http-equiv="X-UA-Compatible" content="IE=edge")
meta(name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0")
meta(name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover")
title= tabTitle
meta(name="author" content=pageAuthor)
meta(name="copyright" content=pageCopyright)
@@ -40,13 +40,13 @@ if (theme.pwa && theme.pwa.enable)
//- main css
link(rel='stylesheet', href=url_for(theme.asset.main_css))
link(rel='stylesheet', href=url_for(theme.asset.fontawesomeV6) media="print" onload="this.media='all'")
link(rel='stylesheet', href=url_for(theme.asset.fontawesome) media="print" onload="this.media='all'")
if (theme.snackbar && theme.snackbar.enable)
link(rel='stylesheet', href=url_for(theme.asset.snackbar_css) media="print" onload="this.media='all'")
if theme.fancybox
link(rel='stylesheet' href=url_for(theme.asset.fancybox_css_v4) media="print" onload="this.media='all'")
link(rel='stylesheet' href=url_for(theme.asset.fancybox_css) media="print" onload="this.media='all'")
//- google_adsense
!=partial('includes/head/google_adsense', {}, {cache: true})
@@ -66,4 +66,4 @@ include ./head/noscript.pug
!=fragment_cache('injectHeadJs', function(){return inject_head_js()})
!=fragment_cache('injectHead', function(){return injectHtml(theme.inject.head)})
!=fragment_cache('injectHead', function(){return injectHtml(theme.inject.head)})

View File

@@ -21,9 +21,12 @@
localSearch = JSON.stringify({
path: theme.local_search.CDN ? theme.local_search.CDN : config.root + config.search.path,
preload: theme.local_search.preload,
top_n_per_article: theme.local_search.top_n_per_article,
unescape: theme.local_search.unescape,
languages: {
// search languages
hits_empty: _p("search.local_search.hits_empty"),
hits_stats: _p("search.local_search.hits_stats"),
}
})
}
@@ -102,7 +105,7 @@ script.
post: !{theme.post_meta.post.date_format === 'relative'}
},
runtime: '!{theme.runtimeshow.enable ? _p("aside.card_webinfo.runtime.unit") : ""}',
date_suffix: {
dateSuffix: {
just: '!{_p("date_suffix.just")}',
min: '!{_p("date_suffix.min")}',
hour: '!{_p("date_suffix.hour")}',

View File

@@ -28,7 +28,9 @@ else
- var top_img = false
- var isHomeClass = 'not-top-img'
header#page-header(class=isHomeClass style=bg_img)
- const isFixedClass = theme.nav.fixed ? ' fixed' : ''
header#page-header(class=`${isHomeClass+isFixedClass}` style=bg_img)
!=partial('includes/header/nav', {}, {cache: true})
if top_img !== false
if is_post()

View File

@@ -1,5 +1,4 @@
- const isFixedClass = theme.nav.fixed ? 'fixed' : ''
nav#nav(class=isFixedClass)
nav#nav
span#blog-info
a(href=url_for('/') title=config.title)
if theme.nav.logo
@@ -8,7 +7,7 @@ nav#nav(class=isFixedClass)
span.site-name=config.title
#menus
if (theme.algolia_search.enable || theme.local_search.enable)
if (theme.algolia_search.enable || theme.local_search.enable || theme.docsearch.enable)
#search-button
a.site-page.social-icon.search(href="javascript:void(0);")
i.fas.fa-search.fa-fw

View File

@@ -1,4 +1,4 @@
each url, icon in theme.social
a.social-icon(href=url_for(trim(url.split('||')[0])) target="_blank"
title=url.split('||')[1] === undefined ? '' : trim(url.split('||')[1]))
i(class=icon)
i(class=icon style=url.split('||')[2] === undefined ? '' : `color: ${trim(url.split('||')[2]).replace(/[\'\"]/g, '')};`)

View File

@@ -44,5 +44,4 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
include ./404.pug
include ./rightside.pug
!=partial('includes/third-party/search/index', {}, {cache: true})
include ./additional-js.pug

View File

@@ -11,15 +11,16 @@
script.
const preloader = {
endLoading: () => {
document.body.style.overflow = 'auto';
document.body.style.overflow = '';
document.getElementById('loading-box').classList.add("loaded")
},
initLoading: () => {
document.body.style.overflow = '';
document.body.style.overflow = 'hidden';
document.getElementById('loading-box').classList.remove("loaded")
}
}
preloader.initLoading()
window.addEventListener('load',()=> { preloader.endLoading() })
if (!{theme.pjax && theme.pjax.enable}) {

View File

@@ -1,2 +1,11 @@
script.
window.paceOptions = {
restartOnPushState: false
}
document.addEventListener('pjax:send', () => {
Pace.restart()
})
link(rel="stylesheet", href=url_for(theme.preloader.pace_css_url || theme.asset.pace_default_css))
script(src=url_for(theme.asset.pace_js))

View File

@@ -1,2 +1,2 @@
.tag-cloud-list.is-center
!=cloudTags({source: site.tags, minfontsize: 1.2, maxfontsize: 2.1, limit: 0, unit: 'em'})
!=cloudTags({source: site.tags, orderby: page.orderby || 'random', order: page.order || 1, minfontsize: 1.2, maxfontsize: 2.1, limit: 0, unit: 'em'})

View File

@@ -0,0 +1,15 @@
script.
(() => {
function abcjsInit() {
function abcjsFn() {
for (let abcContainer of document.getElementsByClassName("abc-music-sheet")) {
ABCJS.renderAbc(abcContainer, abcContainer.innerHTML, {responsive: 'resize'})
}
}
typeof ABCJS === 'object' ? abcjsFn()
: getScript('!{url_for(theme.asset.abcjs_basic_js)}').then(abcjsFn)
}
window.pjax ? abcjsInit() : document.addEventListener('DOMContentLoaded', abcjsInit)
})()

View File

@@ -0,0 +1,6 @@
if theme.abcjs.enable
if theme.abcjs.per_page
if is_post() || is_page()
include ./abcjs.pug
else if page.abcjs
include ./abcjs.pug

View File

@@ -1,4 +1,4 @@
- const fbSDKVer = 'v15.0'
- const fbSDKVer = 'v16.0'
- const fbSDK = theme.messenger.enable ? `https://connect.facebook.net/${theme.facebook_comments.lang}/sdk/xfbml.customerchat.js#xfbml=1&version=${fbSDKVer}` : `https://connect.facebook.net/${theme.facebook_comments.lang}/sdk.js#xfbml=1&version=${fbSDKVer}`
script.

View File

@@ -1,43 +0,0 @@
if theme.chat_btn
script.
((window.gitter = {}).chat = {}).options = {
disableDefaultChat: true,
};
document.addEventListener('gitter-sidecar-ready', (e) => {
const GitterChat = e.detail.Chat
let chat
function initGitter () {
chat = new GitterChat({
room: '#{theme.gitter.room}',
activationElement: '#chat_btn'
});
}
initGitter()
if (!{theme.pjax.enable}) {
document.addEventListener('pjax:complete', () => {
chat.destroy()
initGitter()
})
}
})
else
script.
((window.gitter = {}).chat = {}).options = {
room: '#{theme.gitter.room}',
};
if (!{theme.chat_hide_show}) {
function chatBtnHide () {
document.getElementsByClassName('gitter-open-chat-button')[0].style.display= 'none'
}
function chatBtnShow () {
document.getElementsByClassName('gitter-open-chat-button')[0].style.display= 'block'
}
}
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)

View File

@@ -4,8 +4,6 @@ else if theme.tidio && theme.tidio.enable
include ./tidio.pug
else if theme.daovoice && theme.daovoice.enable
include ./daovoice.pug
else if theme.gitter && theme.gitter.enable
include ./gitter.pug
else if theme.crisp && theme.crisp.enable
include ./crisp.pug
else if theme.messenger && theme.messenger.enable

View File

@@ -9,7 +9,7 @@ script.
window.fbAsyncInit = function() {
FB.init({
xfbml: true,
version: 'v15.0'
version: 'v16.0'
});
};

View File

@@ -1,4 +1,4 @@
- const fbSDKVer = 'v15.0'
- const fbSDKVer = 'v16.0'
- const fbSDK = theme.messenger.enable ? `https://connect.facebook.net/${theme.facebook_comments.lang}/sdk/xfbml.customerchat.js#xfbml=1&version=${fbSDKVer}` : `https://connect.facebook.net/${theme.facebook_comments.lang}/sdk.js#xfbml=1&version=${fbSDKVer}`
script.

View File

@@ -1,16 +1,20 @@
- const { repo, repo_id, category_id, option } = theme.giscus
- const themes = theme.giscus.theme
script.
function loadGiscus () {
let nowTheme = document.documentElement.getAttribute('data-theme') === 'dark' ? '!{themes.dark}' : '!{themes.light}'
- const { repo, repo_id, category_id, theme:themes, option } = theme.giscus
- const giscusUrl = theme.asset.giscus || 'https://giscus.app/client.js'
- const giscusOriginUrl = new URL(giscusUrl).origin
script.
function getGiscusTheme () {
return document.documentElement.getAttribute('data-theme') === 'dark' ? '!{themes.dark}' : '!{themes.light}'
}
function loadGiscus () {
const config = Object.assign({
src: 'https://giscus.app/client.js',
src: '!{giscusUrl}',
'data-repo': '!{repo}',
'data-repo-id': '!{repo_id}',
'data-category-id': '!{category_id}',
'data-mapping': 'pathname',
'data-theme': nowTheme,
'data-theme': getGiscusTheme(),
'data-reactions-enabled': '1',
crossorigin: 'anonymous',
async: true
@@ -24,17 +28,15 @@ script.
}
function changeGiscusTheme () {
const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? '!{themes.dark}' : '!{themes.light}'
function sendMessage(message) {
const iframe = document.querySelector('iframe.giscus-frame');
if (!iframe) return;
iframe.contentWindow.postMessage({ giscus: message }, 'https://giscus.app');
const iframe = document.querySelector('iframe.giscus-frame')
if (!iframe) return
iframe.contentWindow.postMessage({ giscus: message }, '!{giscusOriginUrl}')
}
sendMessage({
setConfig: {
theme: theme
theme: getGiscusTheme()
}
});
}

View File

@@ -14,9 +14,13 @@ script.
}, !{JSON.stringify(option)}))
}
if (typeof Waline === 'object') initWaline()
const walineCSSLoad = document.getElementById('waline-css')
if (typeof Waline === 'object') {
walineCSSLoad ? initWaline() : getCSS('!{url_for(theme.asset.waline_css)}','waline-css').then(initWaline)
}
else {
getCSS('!{url_for(theme.asset.waline_css)}').then(() => {
getCSS('!{url_for(theme.asset.waline_css)}','waline-css').then(() => {
getScript('!{url_for(theme.asset.waline_js)}').then(initWaline)
})
}

View File

@@ -43,5 +43,5 @@ script.
} else {
MathJax.startup.document.state(0)
MathJax.texReset()
MathJax.typeset()
MathJax.typesetPromise()
}

View File

@@ -1,4 +1,4 @@
- const { server, option } = theme.artalk
- const { server, site, option } = theme.artalk
- const avatarCdn = option !== null && option.gravatar ? option.gravatar.mirror : 'https://sdn.geekzu.org/avatar/'
- const avatarDefault = option !== null && option.gravatar ? option.gravatar.default : 'mp'
@@ -45,8 +45,15 @@ script.
window.pjax && window.pjax.refresh($dom)
}
const headerList = {
method: 'POST',
headers: {
'Origin': window.location.origin
}
}
const getComment = () => {
fetch('!{server}/api/stat?type=latest_comments&limit=!{theme.newest_comments.limit}',{method: "POST"})
fetch('!{server}/api/stat?type=latest_comments&limit=!{theme.newest_comments.limit}&site_name=!{site}', headerList)
.then(response => response.json())
.then(d => {
const artalk = d.data.map(function (e) {

View File

@@ -16,3 +16,7 @@
.algolia-poweredBy
#search-mask
script(src=url_for(theme.asset.algolia_search))
script(src=url_for(theme.asset.instantsearch))
script(src=url_for(theme.asset.algolia_js))

View File

@@ -0,0 +1,27 @@
- const { appId, apiKey, indexName, option } = theme.docsearch
.docsearch-wrap
#docsearch(style="display:none")
link(rel="stylesheet" href=url_for(theme.asset.docsearch_css))
script(src=url_for(theme.asset.docsearch_js))
script.
(() => {
docsearch(Object.assign({
appId: '!{appId}',
apiKey: '!{apiKey}',
indexName: '!{indexName}',
container: '#docsearch',
}, !{JSON.stringify(option)}))
const searchClickFn = () => {
document.querySelector('#search-button > .search').addEventListener('click', () => {
document.querySelector('.DocSearch-Button').click()
})
}
searchClickFn()
window.addEventListener('pjax:complete', searchClickFn)
})()

View File

@@ -1,4 +1,6 @@
if theme.algolia_search.enable
include ./algolia.pug
else if theme.local_search.enable
include ./local-search.pug
include ./local-search.pug
else if theme.docsearch.enable
include ./docsearch.pug

View File

@@ -15,6 +15,8 @@
.local-search-box
input(placeholder=_p("search.local_search.input_placeholder") type="text").local-search-box--input
hr
#local-search-results
#local-search-results.no-result
#local-search-stats-wrap
#search-mask
#search-mask
script(src=url_for(theme.asset.local_search))

View File

@@ -1,6 +1,30 @@
- const { effect,loop,source,sub,startDelay,typeSpeed,backSpeed } = theme.subtitle
- const { effect,source,sub,typed_option } = theme.subtitle
- let subContent = sub || new Array()
script.
window.typedJSFn = {
init: (str) => {
window.typed = new Typed('#subtitle', Object.assign({
strings: str,
startDelay: 300,
typeSpeed: 150,
loop: true,
backSpeed: 50,
}, !{JSON.stringify(typed_option)}))
},
run: (subtitleType) => {
if (!{effect}) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
}
} else {
subtitleType()
}
}
}
case source
when 1
script.
@@ -12,28 +36,13 @@ case source
const from = '出自 ' + data.from
const sub = !{JSON.stringify(subContent)}
sub.unshift(data.hitokoto, from)
window.typed = new Typed('#subtitle', {
strings: sub,
startDelay: !{startDelay},
typeSpeed: !{typeSpeed},
loop: !{loop},
backSpeed: !{backSpeed},
})
typedJSFn.init(sub)
} else {
document.getElementById('subtitle').innerHTML = data.hitokoto
}
})
}
if (!{effect}) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
}
} else {
subtitleType()
}
typedJSFn.run(subtitleType)
when 2
script.
@@ -44,28 +53,13 @@ case source
const from = '出自 ' + str[1]
const sub = !{JSON.stringify(subContent)}
sub.unshift(con, from)
window.typed = new Typed('#subtitle', {
strings: sub,
startDelay: !{startDelay},
typeSpeed: !{typeSpeed},
loop: !{loop},
backSpeed: !{backSpeed},
})
typedJSFn.init(sub)
} else {
document.getElementById('subtitle').innerHTML = con
}
})
}
if (!{effect}) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
}
} else {
subtitleType()
}
typedJSFn.run(subtitleType)
when 3
script.
@@ -76,53 +70,23 @@ case source
const sub = !{JSON.stringify(subContent)}
const content = result.data.content
sub.unshift(content)
window.typed = new Typed('#subtitle', {
strings: sub,
startDelay: !{startDelay},
typeSpeed: !{typeSpeed},
loop: !{loop},
backSpeed: !{backSpeed},
})
typedJSFn.init(sub)
} else {
document.getElementById('subtitle').innerHTML = result.data.content
}
})
})
}
if (!{effect}) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
}
} else {
subtitleType()
}
typedJSFn.run(subtitleType)
default
- subContent = subContent.length ? subContent : new Array(config.subtitle)
script.
function subtitleType () {
if (!{effect}) {
window.typed = new Typed("#subtitle", {
strings: !{JSON.stringify(subContent)},
startDelay: !{startDelay},
typeSpeed: !{typeSpeed},
loop: !{loop},
backSpeed: !{backSpeed}
})
if (!{effect}) {
typedJSFn.init(!{JSON.stringify(subContent)})
} else {
document.getElementById("subtitle").innerHTML = '!{subContent[0]}'
}
}
if (!{effect}) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
}
} else {
subtitleType()
}
typedJSFn.run(subtitleType)

View File

@@ -5,8 +5,10 @@ if theme.aside.card_tags.enable
i.fas.fa-tags
span= _p('aside.card_tags')
- let tagLimit = theme.aside.card_tags.limit === 0 ? 0 : theme.aside.card_tags.limit || 40
- let { limit, orderby, order } = theme.aside.card_tags
- limit = limit === 0 ? 0 : limit || 40
if theme.aside.card_tags.color
.card-tag-cloud!= cloudTags({source: site.tags, minfontsize: 1.15, maxfontsize: 1.45, limit: tagLimit, unit: 'em'})
.card-tag-cloud!= cloudTags({source: site.tags, orderby: orderby, order: order, minfontsize: 1.15, maxfontsize: 1.45, limit: limit, unit: 'em'})
else
.card-tag-cloud!= tagcloud({min_font: 1.1, max_font: 1.5, amount: tagLimit , color: true, start_color: '#999', end_color: '#99a9bf', unit: 'em'})
.card-tag-cloud!= tagcloud({orderby: orderby, order: order, min_font: 1.1, max_font: 1.5, amount: limit , color: true, start_color: '#999', end_color: '#99a9bf', unit: 'em'})

View File

@@ -19,7 +19,7 @@
//- page
!=partial('includes/widget/card_author', {}, {cache: true})
!=partial('includes/widget/card_announcement', {}, {cache: true})
!=partial('includes/widget/card_top_self', {}, {cache: true})
!=partial('includes/widget/card_top_self', {}, {cache: true})
.sticky_layout
if showToc

View File

@@ -1,6 +1,6 @@
{
"name": "hexo-theme-butterfly",
"version": "4.6.0",
"version": "4.8.1",
"description": "A Simple and Card UI Design theme for Hexo",
"main": "package.json",
"scripts": {

View File

@@ -1,11 +1,11 @@
algolia_search_v4:
algolia_search:
name: algoliasearch
file: dist/algoliasearch-lite.umd.js
version: 4.14.3
instantsearch_v4:
version: 4.17.0
instantsearch:
name: instantsearch.js
file: dist/instantsearch.production.min.js
version: 4.49.4
version: 4.54.0
pjax:
name: pjax
file: pjax.min.js
@@ -37,17 +37,17 @@ disqusjs_css:
twikoo:
name: twikoo
file: dist/twikoo.all.min.js
version: 1.6.8
version: 1.6.14
waline_js:
name: '@waline/client'
file: dist/waline.js
other_name: waline
version: 2.14.7
version: 2.14.9
waline_css:
name: '@waline/client'
file: dist/waline.css
other_name: waline
version: 2.14.7
version: 2.14.9
sharejs:
name: butterfly-extsrc
file: sharejs/dist/js/social-share.min.js
@@ -73,7 +73,7 @@ katex_copytex:
mermaid:
name: mermaid
file: dist/mermaid.min.js
version: 9.3.0
version: 9.4.3
canvas_ribbon:
name: butterfly-extsrc
file: dist/canvas-ribbon.min.js
@@ -109,24 +109,24 @@ lazyload:
instantpage:
name: instant.page
file: instantpage.js
version: 5.1.1
version: 5.2.0
typed:
name: typed.js
file: lib/typed.min.js
version: 2.0.12
file: dist/typed.umd.js
version: 2.0.15
pangu:
name: pangu
file: dist/browser/pangu.min.js
version: 4.0.7
fancybox_css_v4:
fancybox_css:
name: '@fancyapps/ui'
file: dist/fancybox.css
version: 4.0.31
file: dist/fancybox/fancybox.css
version: 5.0.15
other_name: fancyapps-ui
fancybox_v4:
fancybox:
name: '@fancyapps/ui'
file: dist/fancybox.umd.js
version: 4.0.31
file: dist/fancybox/fancybox.umd.js
version: 5.0.15
other_name: fancyapps-ui
medium_zoom:
name: medium-zoom
@@ -140,11 +140,11 @@ snackbar:
name: node-snackbar
file: dist/snackbar.min.js
version: 0.1.16
fontawesomeV6:
fontawesome:
name: '@fortawesome/fontawesome-free'
file: css/all.min.css
other_name: font-awesome
version: 6.2.1
version: 6.4.0
flickr_justified_gallery_js:
name: flickr-justified-gallery
file: dist/fjGallery.min.js
@@ -183,11 +183,11 @@ prismjs_autoloader:
artalk_js:
name: artalk
file: dist/Artalk.js
version: 2.4.4
version: 2.5.4
artalk_css:
name: artalk
file: dist/Artalk.css
version: 2.4.4
version: 2.5.4
pace_js:
name: pace-js
other_name: pace
@@ -198,3 +198,17 @@ pace_default_css:
other_name: pace
file: themes/blue/pace-theme-minimal.css
version: 1.2.4
docsearch_js:
name: '@docsearch/js'
other_name: docsearch-js
file: dist/umd/index.js
version: 3.3.3
docsearch_css:
name: '@docsearch/css'
other_name: docsearch-css
file: dist/style.css
version: 3.3.3
abcjs_basic_js:
name: abcjs
file: dist/abcjs-basic-min.js
version: 6.2.0

View File

@@ -41,20 +41,19 @@ hexo.extend.filter.register('before_generate', () => {
}
}
const minFile = (file) => {
const minFile = file => {
return file.replace(/(?<!\.min)\.(js|css)$/g, ext => '.min' + ext)
}
const createCDNLink = (data, type, cond = '') => {
Object.keys(data).forEach(key => {
let { name, version, file, other_name } = data[key]
const min_file = minFile(file)
const cdnjs_name = other_name || name
const cdnjs_file = file.replace(/^[lib|dist]*\/|browser\//g, '')
const min_cdnjs_file = minFile(cdnjs_file)
if (cond === 'internal') file = `source/${file}`
const verType = CDN.version ? `@${version}` : ''
const min_file = minFile(file)
const verType = CDN.version ? (type === 'local' ? `?v=${version}` : `@${version}`) : ''
const value = {
version,
@@ -67,7 +66,7 @@ hexo.extend.filter.register('before_generate', () => {
}
const cdnSource = {
local: cond === 'internal' ? cdnjs_file : `/pluginsSrc/${name}/${file}`,
local: cond === 'internal' ? `${cdnjs_file + verType}` : `/pluginsSrc/${name}/${file + verType}`,
jsdelivr: `https://cdn.jsdelivr.net/npm/${name}${verType}/${min_file}`,
unpkg: `https://unpkg.com/${name}${verType}/${file}`,
cdnjs: `https://cdnjs.cloudflare.com/ajax/libs/${cdnjs_name}/${version}/${min_cdnjs_file}`,
@@ -77,7 +76,7 @@ hexo.extend.filter.register('before_generate', () => {
data[key] = cdnSource[type]
})
if (cond === 'internal') data.main_css = 'css/index.css'
if (cond === 'internal') data.main_css = 'css/index.css' + (CDN.version ? `?v=${version}` : '')
return data
}
@@ -90,6 +89,9 @@ hexo.extend.filter.register('before_generate', () => {
return obj
}
themeConfig.asset = Object.assign(createCDNLink(internalSrc, CDN.internal_provider, 'internal'),
createCDNLink(thirdPartySrc, CDN.third_party_provider), deleteNullValue(CDN.option))
themeConfig.asset = Object.assign(
createCDNLink(internalSrc, CDN.internal_provider, 'internal'),
createCDNLink(thirdPartySrc, CDN.third_party_provider),
deleteNullValue(CDN.option)
)
})

View File

@@ -6,7 +6,7 @@
'use strict'
hexo.extend.filter.register('before_post_render', function (data) {
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/i
let randomCover
let coverVal = data.cover

View File

@@ -7,7 +7,8 @@
hexo.extend.helper.register('inject_head_js', function () {
const { darkmode, aside } = this.theme
const start = darkmode.start ? darkmode.start : 6
const end = darkmode.end ? darkmode.end : 18
const { theme_color } = hexo.theme.config
const themeColorLight = (theme_color && theme_color.enable && theme_color.meta_theme_color_light) || '#ffffff'
const themeColorDark = (theme_color && theme_color.enable && theme_color.meta_theme_color_dark) || '#0d0d0d'
@@ -61,12 +62,18 @@ hexo.extend.helper.register('inject_head_js', function () {
`
const getCSS = `
win.getCSS = url => new Promise((resolve, reject) => {
win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = url
link.onload = () => resolve()
link.onerror = () => reject()
if (id) link.id = id
link.onerror = reject
link.onload = link.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
link.onload = link.onreadystatechange = null
resolve()
}
document.head.appendChild(link)
})
`
@@ -104,7 +111,7 @@ hexo.extend.helper.register('inject_head_js', function () {
else if (isNotSpecified || hasNoSupport) {
const now = new Date()
const hour = now.getHours()
const isNight = hour <= 6 || hour >= 18
const isNight = hour <= ${start} || hour >= ${end}
isNight ? activateDarkMode() : activateLightMode()
}
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
@@ -119,7 +126,7 @@ hexo.extend.helper.register('inject_head_js', function () {
darkmodeJs += `
const now = new Date()
const hour = now.getHours()
const isNight = hour <= 6 || hour >= 18
const isNight = hour <= ${start} || hour >= ${end}
if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
else if (t === 'light') activateLightMode()
else activateDarkMode()

View File

@@ -24,11 +24,8 @@ hexo.extend.helper.register('page_description', function () {
hexo.extend.helper.register('cloudTags', function (options = {}) {
const env = this
let source = options.source
const minfontsize = options.minfontsize
const maxfontsize = options.maxfontsize
const limit = options.limit
const unit = options.unit || 'px'
let { source, minfontsize, maxfontsize, limit, unit, orderby, order } = options
unit = unit || 'px'
let result = ''
if (limit > 0) {
@@ -43,7 +40,7 @@ hexo.extend.helper.register('cloudTags', function (options = {}) {
})
const length = sizes.length - 1
source.forEach(tag => {
source.sort(orderby, order).forEach(tag => {
const ratio = length ? sizes.indexOf(tag.length) / length : 0
const size = minfontsize + ((maxfontsize - minfontsize) * ratio)
let style = `font-size: ${parseFloat(size.toFixed(2))}${unit};`
@@ -97,7 +94,7 @@ hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) {
})
hexo.extend.helper.register('isImgOrUrl', function (path) {
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/i
if (path.indexOf('//') !== -1 || imgTestReg.test(path)) {
return true
}

View File

@@ -3,6 +3,7 @@
* galleryGroup and gallery
* {% galleryGroup [name] [descr] [url] [img] %}
* {% gallery [lazyload],[rowHeight],[limit] %}
* {% gallery url,[url],[lazyload],[rowHeight],[limit] %}
*/
'use strict'
@@ -12,28 +13,35 @@ const urlFor = require('hexo-util').url_for.bind(hexo)
function gallery (args, content) {
const { data, languages } = hexo.theme.i18n
args = args.join(' ').split(',')
const rowHeight = args[1] || 220
const limit = args[2] || 10
const lazyload = args[0] === 'true'
const regex = /!\[(.*?)\]\((.*?)\s*(?:["'](.*?)["']?)?\s*\)/g
const lazyloadClass = lazyload ? 'lazyload' : ''
let m
const arr = []
while ((m = regex.exec(content)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++
let rowHeight, limit, lazyload, type, dataStr
if (args[0] === 'url') {
[type, dataStr, lazyload, rowHeight = 220, limit = 10] = args // url,[link],[lazyload],[rowHeight],[limit]
} else {
[lazyload, rowHeight = 220, limit = 10] = args // [lazyload],[rowHeight],[limit]
const regex = /!\[(.*?)\]\(([^\s]*)\s*(?:["'](.*?)["']?)?\s*\)/g
let m
const arr = []
while ((m = regex.exec(content)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++
}
arr.push({
url: m[2],
alt: m[1],
title: m[3]
})
}
arr.push({
url: m[2],
alt: m[1],
title: m[3]
})
dataStr = JSON.stringify(arr)
}
type = type ? ' url' : ' data'
const lazyloadClass = lazyload === 'true' ? 'lazyload' : ''
return `<div class="gallery">
<div class="fj-gallery ${lazyloadClass}" data-rowHeight="${rowHeight}" data-limit="${limit}">
<span class="gallery-data">${JSON.stringify(arr)}</span>
<div class="fj-gallery ${lazyloadClass + type}" data-rowHeight="${rowHeight}" data-limit="${limit}">
<span class="gallery-data">${dataStr}</span>
</div>
<button class="gallery-load-more"><span>${data[languages[0]].load_more}</span><i class="fa-solid fa-arrow-down"></i></button>
</div>`

22
scripts/tag/score.js Normal file
View File

@@ -0,0 +1,22 @@
/**
* Music Score
* {% score %}
*/
'use strict';
function score(args, content) {
function escapeHtmlTags(s) {
let lookup = {
'&': "&amp;",
'"': "&quot;",
'\'': "&apos;",
'<': "&lt;",
'>': "&gt;"
};
return s.replace(/[&"'<>]/g, c => lookup[c]);
}
return `<div class="abc-music-sheet">${escapeHtmlTags(content)}</div>`;
}
hexo.extend.tag.register('score', score, {ends: true});

View File

@@ -6,7 +6,7 @@
--hr-before-color: lighten($theme-hr-color, 30%)
--search-bg: $search-bg
--search-input-color: $search-input-color
--search-result-title: $search-result-title
--search-a-color: $search-a-color
--preloader-bg: $preloader-bg
--preloader-color: $preloader-word-color
--tab-border-color: $tab-border-color
@@ -50,8 +50,8 @@ body
// scrollbar - chrome/safari
*::-webkit-scrollbar
width: 8px
height: 8px
width: 5px
height: 5px
*::-webkit-scrollbar-thumb
background: var(--scrollbar-color)

View File

@@ -52,7 +52,7 @@
transition: all .3s
&:hover
transform: rotate(540deg)
transform: rotate(360deg)
#card-info-btn
display: block
@@ -291,8 +291,8 @@
background: $theme-toc-color
color: $toc-active-color
:only-child
> .card-widget
.sticky_layout:only-child
> :first-child
margin-top: 0
.card-more-btn

View File

@@ -124,7 +124,8 @@
background: rgba(255, 255, 255, .8)
box-shadow: 0 5px 6px -5px rgba(133, 133, 133, .6)
a
a,
.site-name
color: var(--font-color)
text-shadow: none
@@ -137,10 +138,6 @@
box-shadow: 0 5px 6px -5px alpha($grey, .6)
transition: transform .2s ease-in-out, opacity .2s ease-in-out
&.fixed
top: 0
transition: all .5s
#blog-info
color: var(--font-color)
@@ -158,8 +155,13 @@
&:hover
color: $light-blue
&.nav-visible
#nav:not(.fixed)
&.fixed
#nav
top: 0
transition: all .5s
&.nav-visible:not(.fixed)
#nav
transition: all .5s
transform: translate3d(0, 100%, 0)
@@ -168,6 +170,19 @@
top: 70px
transition: top .5s
&.fixed
#nav
position: fixed
& + .layout
& > .aside-content > .sticky_layout
top: 70px
transition: top .5s
#card-toc
.toc-content
max-height: calc(100vh - 170px)
#page
h1.page-title
margin: 8px 0 20px
@@ -265,9 +280,6 @@
&.show
opacity: 1
&.fixed
position: fixed
#blog-info
flex: 1
color: var(--light-grey)

View File

@@ -144,15 +144,26 @@ beautify()
p
margin: 0 0 8px
> :last-child
margin-bottom: 0 !important
hr
margin: 20px 0
if hexo-config('beautify.enable')
if hexo-config('beautify.field') == 'site'
beautify()
else if hexo-config('beautify.field') == 'post'
&.post-content
beautify()
else
hr
margin: 20px 0
border: 1px inset
width 100%
> :last-child
margin-bottom: 0 !important
&:before
content: none
#post
.tag_share

View File

@@ -113,4 +113,16 @@ span.mathjax-overflow
content: none
.snackbar-css
border-radius: 5px !important
border-radius: 5px !important
.abc-music-sheet
margin: 0 0 20px
opacity: 0
transition: opacity .3s
&.abcjs-container
opacity: 1
+maxWidth768()
.fancybox__toolbar__column.is-middle
display: none

View File

@@ -6,7 +6,7 @@ if hexo-config('darkmode.enable') || hexo-config('display_mode') == 'dark'
--hr-before-color: alpha(#FFFFFF, .7)
--search-bg: #121212
--search-input-color: alpha(#FFFFFF, .7)
--search-result-title: alpha(#FFFFFF, .9)
--search-a-color: alpha(#FFFFFF, .7)
--preloader-bg: darken(#121212, 2)
--preloader-color: alpha(#FFFFFF, .7)
--tab-border-color: #2c2c2c

View File

@@ -18,7 +18,7 @@
padding: 20px 5px
+minWidth2000()
max-width: 1500px
max-width: 1700px
& > div:first-child:not(.recent-posts)
@extend .cardHover

View File

@@ -16,7 +16,7 @@
@extend .list-beauty
a
color: var(--search-result-title)
color: var(--search-a-color)
&:hover
color: $search-color
@@ -26,12 +26,15 @@
color: $search-keyword-highlight
font-weight: bold
.algolia-hits-item-title
font-weight: 600
.algolia-hit-item-content
margin: 0 0 8px
word-break: break-word
.ais-Pagination
margin: 20px 0 0
margin: 15px 0 0
padding: 0
text-align: center
@@ -61,22 +64,16 @@
.ais-Pagination-item--disabled
visibility: hidden
.algolia-logo
padding-top: 2px
width: 80px
height: 30px
#algolia-hits
> div
overflow-y: scroll
margin: 0 -20px
padding: 0 22px
+minWidth768()
max-height: calc(80vh - 240px)
max-height: calc(80vh - 240px)
+maxWidth768()
height: calc(100vh - 260px)
max-height: none
height: calc(var(--search-height) - 265px)
#algolia-info
div
@@ -84,10 +81,7 @@
.algolia-poweredBy
float: right
vertical-align: text-top
.apple
#algolia-search
#algolia-hits
> div
+maxWidth768()
height: calc(90vh - 260px)
svg
height: 1.1em

View File

@@ -9,6 +9,7 @@
width: 600px
border-radius: 8px
background: var(--search-bg)
--search-height: 100vh
+maxWidth768()
top: 0

View File

@@ -18,7 +18,7 @@
.search-wrap
display: none
.local-search__hit-item
.local-search-hit-item
position: relative
padding-left: 24px
line-height: 1.7
@@ -43,27 +43,32 @@
a
display: block
color: var(--search-result-title)
font-weight: 600
cursor: pointer
color: var(--search-a-color)
&:hover
color: $search-color
.search-result-title
font-weight: 600
.search-result
margin: 0 0 8px
word-break: break-word
.search-keyword
color: $search-keyword-highlight
font-weight: bold
.search-result-list
overflow-y: overlay
margin: 0 -20px
padding: 0 22px
max-height: calc(80vh - 130px)
max-height: calc(80vh - 200px)
+maxWidth768()
padding-bottom: 40px
max-height: 75vh !important
max-height: calc(var(--search-height) - 220px) !important
.no-result
& + #local-search-stats-wrap
display: none
.search-keyword
background: transparent
color: $search-keyword-highlight
font-weight: bold

View File

@@ -82,7 +82,7 @@ $search-bg = #f6f8fa
$search-input-color = $font-black
$search-color = $theme-color
$search-keyword-highlight = #F47466
$search-result-title = $font-black
$search-a-color = $font-black
// comments
$comments-switch-first-text = $bright-blue
$comments-switch-second-text = $light-orange

View File

@@ -243,8 +243,8 @@ document.addEventListener('DOMContentLoaded', function () {
return str
}
const lazyloadFn = (i, arr) => {
const loadItem = i.getAttribute('data-limit')
const lazyloadFn = (i, arr, limit) => {
const loadItem = limit
const arrLength = arr.length
if (arrLength > loadItem) i.insertAdjacentHTML('beforeend', htmlStr(arr.splice(0, loadItem)))
else {
@@ -254,29 +254,43 @@ document.addEventListener('DOMContentLoaded', function () {
return arrLength > loadItem ? loadItem : arrLength
}
ele.forEach(item => {
const arr = JSON.parse(item.querySelector('.gallery-data').textContent)
const fetchUrl = async (url) => {
const response = await fetch(url)
return await response.json()
}
const runJustifiedGallery = (item, arr) => {
if (!item.classList.contains('lazyload')) item.innerHTML = htmlStr(arr)
else {
lazyloadFn(item, arr)
const limit = item.getAttribute('data-limit')
lazyloadFn(item, arr, limit)
const clickBtnFn = () => {
const lastItemLength = lazyloadFn(item, arr)
const lastItemLength = lazyloadFn(item, arr, limit)
fjGallery(item, 'appendImages', item.querySelectorAll(`.fj-gallery-item:nth-last-child(-n+${lastItemLength})`))
btf.loadLightbox(item.querySelectorAll('img'))
lastItemLength < limit && item.nextElementSibling.removeEventListener('click', clickBtnFn)
}
item.nextElementSibling.addEventListener('click', clickBtnFn)
}
})
btf.initJustifiedGallery(item)
btf.loadLightbox(item.querySelectorAll('img'))
}
const addJustifiedGallery = () => {
ele.forEach(item => {
item.classList.contains('url')
? fetchUrl(item.textContent).then(res => { runJustifiedGallery(item, res) })
: runJustifiedGallery(item, JSON.parse(item.textContent))
})
}
if (window.fjGallery) {
setTimeout(() => { btf.initJustifiedGallery(ele) }, 100)
addJustifiedGallery()
return
}
getCSS(`${GLOBAL_CONFIG.source.justifiedGallery.css}`)
getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(() => { btf.initJustifiedGallery(ele) })
getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(addJustifiedGallery)
}
/**

View File

@@ -1,10 +1,13 @@
window.addEventListener('load', () => {
const $searchMask = document.getElementById('search-mask')
const $searchDialog = document.querySelector('#algolia-search .search-dialog')
const openSearch = () => {
const bodyStyle = document.body.style
bodyStyle.width = '100%'
bodyStyle.overflow = 'hidden'
btf.animateIn(document.getElementById('search-mask'), 'to_show 0.5s')
btf.animateIn(document.querySelector('#algolia-search .search-dialog'), 'titleScale 0.5s')
btf.animateIn($searchMask, 'to_show 0.5s')
btf.animateIn($searchDialog, 'titleScale 0.5s')
setTimeout(() => { document.querySelector('#algolia-search .ais-SearchBox-input').focus() }, 100)
// shortcut: ESC
@@ -14,22 +17,33 @@ window.addEventListener('load', () => {
document.removeEventListener('keydown', f)
}
})
fixSafariHeight()
window.addEventListener('resize', fixSafariHeight)
}
const closeSearch = () => {
const bodyStyle = document.body.style
bodyStyle.width = ''
bodyStyle.overflow = ''
btf.animateOut(document.querySelector('#algolia-search .search-dialog'), 'search_close .5s')
btf.animateOut(document.getElementById('search-mask'), 'to_hide 0.5s')
btf.animateOut($searchDialog, 'search_close .5s')
btf.animateOut($searchMask, 'to_hide 0.5s')
window.removeEventListener('resize', fixSafariHeight)
}
// fix safari
const fixSafariHeight = () => {
if (window.innerWidth < 768) {
$searchDialog.style.setProperty('--search-height', window.innerHeight + 'px')
}
}
const searchClickFn = () => {
document.querySelector('#search-button > .search').addEventListener('click', openSearch)
}
const searchClickFnOnce = () => {
document.getElementById('search-mask').addEventListener('click', closeSearch)
const searchFnOnce = () => {
$searchMask.addEventListener('click', closeSearch)
document.querySelector('#algolia-search .search-close-button').addEventListener('click', closeSearch)
}
@@ -102,9 +116,9 @@ window.addEventListener('load', () => {
: ''
return `
<a href="${link}" class="algolia-hit-item-link">
${result.title.value || 'no-title'}
</a>
<p class="algolia-hit-item-content">${content}</p>`
<span class="algolia-hits-item-title">${result.title.value || 'no-title'}</span>
<p class="algolia-hit-item-content">${content}</p>
</a>`
},
empty: function (data) {
return (
@@ -150,10 +164,10 @@ window.addEventListener('load', () => {
search.start()
searchClickFn()
searchClickFnOnce()
searchFnOnce()
window.addEventListener('pjax:complete', () => {
getComputedStyle(document.querySelector('#algolia-search .search-dialog')).display === 'block' && closeSearch()
!btf.isHidden($searchMask) && closeSearch()
searchClickFn()
})

View File

@@ -1,17 +1,311 @@
/**
* Refer to hexo-generator-searchdb
* https://github.com/next-theme/hexo-generator-searchdb/blob/main/dist/search.js
* Modified by hexo-theme-butterfly
*/
class LocalSearch {
constructor ({
path = '',
unescape = false,
top_n_per_article = 1
}) {
this.path = path
this.unescape = unescape
this.top_n_per_article = top_n_per_article
this.isfetched = false
this.datas = null
}
getIndexByWord (words, text, caseSensitive = false) {
const index = []
const included = new Set()
if (!caseSensitive) {
text = text.toLowerCase()
}
words.forEach(word => {
if (this.unescape) {
const div = document.createElement('div')
div.innerText = word
word = div.innerHTML
}
const wordLen = word.length
if (wordLen === 0) return
let startPosition = 0
let position = -1
if (!caseSensitive) {
word = word.toLowerCase()
}
while ((position = text.indexOf(word, startPosition)) > -1) {
index.push({ position, word })
included.add(word)
startPosition = position + wordLen
}
})
// Sort index by position of keyword
index.sort((left, right) => {
if (left.position !== right.position) {
return left.position - right.position
}
return right.word.length - left.word.length
})
return [index, included]
}
// Merge hits into slices
mergeIntoSlice (start, end, index) {
let item = index[0]
let { position, word } = item
const hits = []
const count = new Set()
while (position + word.length <= end && index.length !== 0) {
count.add(word)
hits.push({
position,
length: word.length
})
const wordEnd = position + word.length
// Move to next position of hit
index.shift()
while (index.length !== 0) {
item = index[0]
position = item.position
word = item.word
if (wordEnd > position) {
index.shift()
} else {
break
}
}
}
return {
hits,
start,
end,
count: count.size
}
}
// Highlight title and content
highlightKeyword (val, slice) {
let result = ''
let index = slice.start
for (const { position, length } of slice.hits) {
result += val.substring(index, position)
index = position + length
result += `<mark class="search-keyword">${val.substr(position, length)}</mark>`
}
result += val.substring(index, slice.end)
return result
}
getResultItems (keywords) {
const resultItems = []
this.datas.forEach(({ title, content, url }) => {
// The number of different keywords included in the article.
const [indexOfTitle, keysOfTitle] = this.getIndexByWord(keywords, title)
const [indexOfContent, keysOfContent] = this.getIndexByWord(keywords, content)
const includedCount = new Set([...keysOfTitle, ...keysOfContent]).size
// Show search results
const hitCount = indexOfTitle.length + indexOfContent.length
if (hitCount === 0) return
const slicesOfTitle = []
if (indexOfTitle.length !== 0) {
slicesOfTitle.push(this.mergeIntoSlice(0, title.length, indexOfTitle))
}
let slicesOfContent = []
while (indexOfContent.length !== 0) {
const item = indexOfContent[0]
const { position } = item
// Cut out 120 characters. The maxlength of .search-input is 80.
const start = Math.max(0, position - 20)
const end = Math.min(content.length, position + 100)
slicesOfContent.push(this.mergeIntoSlice(start, end, indexOfContent))
}
// Sort slices in content by included keywords' count and hits' count
slicesOfContent.sort((left, right) => {
if (left.count !== right.count) {
return right.count - left.count
} else if (left.hits.length !== right.hits.length) {
return right.hits.length - left.hits.length
}
return left.start - right.start
})
// Select top N slices in content
const upperBound = parseInt(this.top_n_per_article, 10)
if (upperBound >= 0) {
slicesOfContent = slicesOfContent.slice(0, upperBound)
}
let resultItem = ''
url = new URL(url, location.origin)
url.searchParams.append('highlight', keywords.join(' '))
if (slicesOfTitle.length !== 0) {
resultItem += `<div class="local-search-hit-item"><a href="${url.href}"><span class="search-result-title">${this.highlightKeyword(title, slicesOfTitle[0])}</span>`
} else {
resultItem += `<div class="local-search-hit-item"><a href="${url.href}"><span class="search-result-title">${title}</span>`
}
slicesOfContent.forEach(slice => {
resultItem += `<p class="search-result">${this.highlightKeyword(content, slice)}...</p></a>`
})
resultItem += '</div>'
resultItems.push({
item: resultItem,
id: resultItems.length,
hitCount,
includedCount
})
})
return resultItems
}
fetchData () {
const isXml = !this.path.endsWith('json')
fetch(this.path)
.then(response => response.text())
.then(res => {
// Get the contents from search data
this.isfetched = true
this.datas = isXml
? [...new DOMParser().parseFromString(res, 'text/xml').querySelectorAll('entry')].map(element => ({
title: element.querySelector('title').textContent,
content: element.querySelector('content').textContent,
url: element.querySelector('url').textContent
}))
: JSON.parse(res)
// Only match articles with non-empty titles
this.datas = this.datas.filter(data => data.title).map(data => {
data.title = data.title.trim()
data.content = data.content ? data.content.trim().replace(/<[^>]+>/g, '') : ''
data.url = decodeURIComponent(data.url).replace(/\/{2,}/g, '/')
return data
})
// Remove loading animation
window.dispatchEvent(new Event('search:loaded'))
})
}
// Highlight by wrapping node in mark elements with the given class name
highlightText (node, slice, className) {
const val = node.nodeValue
let index = slice.start
const children = []
for (const { position, length } of slice.hits) {
const text = document.createTextNode(val.substring(index, position))
index = position + length
const mark = document.createElement('mark')
mark.className = className
mark.appendChild(document.createTextNode(val.substr(position, length)))
children.push(text, mark)
}
node.nodeValue = val.substring(index, slice.end)
children.forEach(element => {
node.parentNode.insertBefore(element, node)
})
}
// Highlight the search words provided in the url in the text
highlightSearchWords (body) {
const params = new URL(location.href).searchParams.get('highlight')
const keywords = params ? params.split(' ') : []
if (!keywords.length || !body) return
const walk = document.createTreeWalker(body, NodeFilter.SHOW_TEXT, null)
const allNodes = []
while (walk.nextNode()) {
if (!walk.currentNode.parentNode.matches('button, select, textarea, .mermaid')) allNodes.push(walk.currentNode)
}
allNodes.forEach(node => {
const [indexOfNode] = this.getIndexByWord(keywords, node.nodeValue)
if (!indexOfNode.length) return
const slice = this.mergeIntoSlice(0, node.nodeValue.length, indexOfNode)
this.highlightText(node, slice, 'search-keyword')
})
}
}
window.addEventListener('load', () => {
// Search
const { path, top_n_per_article, unescape, languages } = GLOBAL_CONFIG.localSearch
const localSearch = new LocalSearch({
path,
top_n_per_article,
unescape
})
const input = document.querySelector('#local-search-input input')
const statsItem = document.getElementById('local-search-stats-wrap')
const $loadingStatus = document.getElementById('loading-status')
const inputEventFunction = () => {
if (!localSearch.isfetched) return
const searchText = input.value.trim().toLowerCase()
if (searchText !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>'
const keywords = searchText.split(/[-\s]+/)
const container = document.getElementById('local-search-results')
let resultItems = []
if (searchText.length > 0) {
// Perform local searching
resultItems = localSearch.getResultItems(keywords)
}
if (keywords.length === 1 && keywords[0] === '') {
container.classList.add('no-result')
container.textContent = ''
} else if (resultItems.length === 0) {
container.textContent = ''
statsItem.innerHTML = `<div class="search-result-stats">${languages.hits_empty.replace(/\$\{query}/, searchText)}</div>`
} else {
resultItems.sort((left, right) => {
if (left.includedCount !== right.includedCount) {
return right.includedCount - left.includedCount
} else if (left.hitCount !== right.hitCount) {
return right.hitCount - left.hitCount
}
return right.id - left.id
})
const stats = languages.hits_stats.replace(/\$\{hits}/, resultItems.length)
container.classList.remove('no-result')
container.innerHTML = `<div class="search-result-list">${resultItems.map(result => result.item).join('')}</div>`
statsItem.innerHTML = `<hr><div class="search-result-stats">${stats}</div>`
window.pjax && window.pjax.refresh(container)
}
$loadingStatus.innerHTML = ''
}
let loadFlag = false
let dataObj = []
const $searchMask = document.getElementById('search-mask')
const $searchDialog = document.querySelector('#local-search .search-dialog')
// fix safari
const fixSafariHeight = () => {
if (window.innerWidth < 768) {
$searchDialog.style.setProperty('--search-height', window.innerHeight + 'px')
}
}
const openSearch = () => {
const bodyStyle = document.body.style
bodyStyle.width = '100%'
bodyStyle.overflow = 'hidden'
btf.animateIn($searchMask, 'to_show 0.5s')
btf.animateIn(document.querySelector('#local-search .search-dialog'), 'titleScale 0.5s')
setTimeout(() => { document.querySelector('#local-search-input input').focus() }, 100)
btf.animateIn($searchDialog, 'titleScale 0.5s')
setTimeout(() => { input.focus() }, 300)
if (!loadFlag) {
search()
!localSearch.isfetched && localSearch.fetchData()
input.addEventListener('input', inputEventFunction)
loadFlag = true
}
// shortcut: ESC
@@ -21,176 +315,46 @@ window.addEventListener('load', () => {
document.removeEventListener('keydown', f)
}
})
fixSafariHeight()
window.addEventListener('resize', fixSafariHeight)
}
const closeSearch = () => {
const bodyStyle = document.body.style
bodyStyle.width = ''
bodyStyle.overflow = ''
btf.animateOut(document.querySelector('#local-search .search-dialog'), 'search_close .5s')
btf.animateOut($searchDialog, 'search_close .5s')
btf.animateOut($searchMask, 'to_hide 0.5s')
window.removeEventListener('resize', fixSafariHeight)
}
const searchClickFn = () => {
document.querySelector('#search-button > .search').addEventListener('click', openSearch)
}
const searchClickFnOnce = () => {
const searchFnOnce = () => {
document.querySelector('#local-search .search-close-button').addEventListener('click', closeSearch)
$searchMask.addEventListener('click', closeSearch)
if (GLOBAL_CONFIG.localSearch.preload) dataObj = fetchData(GLOBAL_CONFIG.localSearch.path)
}
// check url is json or not
const isJson = url => {
const reg = /\.json$/
return reg.test(url)
}
const fetchData = async (path) => {
let data = []
const response = await fetch(path)
if (isJson(path)) {
data = await response.json()
} else {
const res = await response.text()
const t = await new window.DOMParser().parseFromString(res, 'text/xml')
const a = await t
data = [...a.querySelectorAll('entry')].map(item => {
return {
title: item.querySelector('title').textContent,
content: item.querySelector('content') && item.querySelector('content').textContent,
url: item.querySelector('url').textContent
}
})
if (GLOBAL_CONFIG.localSearch.preload) {
localSearch.fetchData()
}
if (response.ok) {
const $loadDataItem = document.getElementById('loading-database')
$loadDataItem.nextElementSibling.style.display = 'block'
$loadDataItem.remove()
}
return data
localSearch.highlightSearchWords(document.getElementById('article-container'))
}
const search = () => {
if (!GLOBAL_CONFIG.localSearch.preload) {
dataObj = fetchData(GLOBAL_CONFIG.localSearch.path)
}
const $input = document.querySelector('#local-search-input input')
const $resultContent = document.getElementById('local-search-results')
const $loadingStatus = document.getElementById('loading-status')
$input.addEventListener('input', function () {
const keywords = this.value.trim().toLowerCase().split(/[\s]+/)
if (keywords[0] !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>'
else {
$resultContent.innerHTML = ''
return
}
let str = '<div class="search-result-list">'
if (keywords.length <= 0) return
let count = 0
// perform local searching
dataObj.then(data => {
data.forEach(data => {
let isMatch = true
let dataTitle = data.title ? data.title.trim().toLowerCase() : ''
const dataContent = data.content ? data.content.trim().replace(/<[^>]+>/g, '').toLowerCase() : ''
const dataUrl = data.url.startsWith('/') ? data.url : GLOBAL_CONFIG.root + data.url
let indexTitle = -1
let indexContent = -1
let firstOccur = -1
// only match articles with not empty titles and contents
if (dataTitle !== '' || dataContent !== '') {
keywords.forEach((keyword, i) => {
indexTitle = dataTitle.indexOf(keyword)
indexContent = dataContent.indexOf(keyword)
if (indexTitle < 0 && indexContent < 0) {
isMatch = false
} else {
if (indexContent < 0) {
indexContent = 0
}
if (i === 0) {
firstOccur = indexContent
}
}
})
} else {
isMatch = false
}
// show search results
if (isMatch) {
if (firstOccur >= 0) {
// cut out 130 characters
// let start = firstOccur - 30 < 0 ? 0 : firstOccur - 30
// let end = firstOccur + 50 > dataContent.length ? dataContent.length : firstOccur + 50
let start = firstOccur - 30
let end = firstOccur + 100
let pre = ''
let post = ''
if (start < 0) {
start = 0
}
if (start === 0) {
end = 100
} else {
pre = '...'
}
if (end > dataContent.length) {
end = dataContent.length
} else {
post = '...'
}
let matchContent = dataContent.substring(start, end)
// highlight all keywords
keywords.forEach(keyword => {
let regexStr = keyword
const specialRegex = /[^\w\s]+/ // match special characters
if (keyword.length === 1 && specialRegex.test(keyword)) {
regexStr = `\\${keyword}`
}
const regS = new RegExp(regexStr, 'gi')
matchContent = matchContent.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
dataTitle = dataTitle.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
})
str += '<div class="local-search__hit-item"><a href="' + dataUrl + '" class="search-result-title">' + dataTitle + '</a>'
count += 1
if (dataContent !== '') {
str += '<p class="search-result">' + pre + matchContent + post + '</p>'
}
}
str += '</div>'
}
})
if (count === 0) {
str += '<div id="local-search__hits-empty">' + GLOBAL_CONFIG.localSearch.languages.hits_empty.replace(/\$\{query}/, this.value.trim()) +
'</div>'
}
str += '</div>'
$resultContent.innerHTML = str
if (keywords[0] !== '') $loadingStatus.innerHTML = ''
window.pjax && window.pjax.refresh($resultContent)
})
})
}
window.addEventListener('search:loaded', () => {
const $loadDataItem = document.getElementById('loading-database')
$loadDataItem.nextElementSibling.style.display = 'block'
$loadDataItem.remove()
})
searchClickFn()
searchClickFnOnce()
searchFnOnce()
// pjax
window.addEventListener('pjax:complete', () => {
!btf.isHidden($searchMask) && closeSearch()
localSearch.highlightSearchWords(document.getElementById('article-container'))
searchClickFn()
})
})

File diff suppressed because one or more lines are too long

View File

@@ -79,31 +79,21 @@ const btf = {
const hour = minute * 60
const day = hour * 24
const month = day * 30
const { dateSuffix } = GLOBAL_CONFIG
let result
if (more) {
const monthCount = dateDiff / month
const dayCount = dateDiff / day
const hourCount = dateDiff / hour
const minuteCount = dateDiff / minute
if (!more) return parseInt(dateDiff / day)
if (monthCount > 12) {
result = datePost.toISOString().slice(0, 10)
} else if (monthCount >= 1) {
result = parseInt(monthCount) + ' ' + GLOBAL_CONFIG.date_suffix.month
} else if (dayCount >= 1) {
result = parseInt(dayCount) + ' ' + GLOBAL_CONFIG.date_suffix.day
} else if (hourCount >= 1) {
result = parseInt(hourCount) + ' ' + GLOBAL_CONFIG.date_suffix.hour
} else if (minuteCount >= 1) {
result = parseInt(minuteCount) + ' ' + GLOBAL_CONFIG.date_suffix.min
} else {
result = GLOBAL_CONFIG.date_suffix.just
}
} else {
result = parseInt(dateDiff / day)
}
return result
const monthCount = dateDiff / month
const dayCount = dateDiff / day
const hourCount = dateDiff / hour
const minuteCount = dateDiff / minute
if (monthCount > 12) return datePost.toISOString().slice(0, 10)
if (monthCount >= 1) return `${parseInt(monthCount)} ${dateSuffix.month}`
if (dayCount >= 1) return `${parseInt(dayCount)} ${dateSuffix.day}`
if (hourCount >= 1) return `${parseInt(hourCount)} ${dateSuffix.hour}`
if (minuteCount >= 1) return `${parseInt(minuteCount)} ${dateSuffix.min}`
return dateSuffix.just
},
loadComment: (dom, callback) => {
@@ -122,7 +112,8 @@ const btf = {
scrollToDest: (pos, time = 500) => {
const currentPos = window.pageYOffset
if (currentPos > pos) pos = pos - 70
const isNavFixed = document.getElementById('page-header').classList.contains('fixed')
if (currentPos > pos || isNavFixed) pos = pos - 70
if ('scrollBehavior' in document.documentElement.style) {
window.scrollTo({
@@ -242,7 +233,30 @@ const btf = {
Fancybox.bind('[data-fancybox]', {
Hash: false,
Thumbs: {
autoStart: false
showOnStart: false
},
Images: {
Panzoom: {
maxScale: 4
}
},
Carousel: {
transition: 'slide'
},
Toolbar: {
display: {
left: ['infobar'],
middle: [
'zoomIn',
'zoomOut',
'toggle1to1',
'rotateCCW',
'rotateCW',
'flipX',
'flipY'
],
right: ['slideshow', 'thumbs', 'close']
}
}
})
window.fancyboxRun = true
@@ -251,7 +265,7 @@ const btf = {
},
initJustifiedGallery: function (selector) {
selector.forEach(function (i) {
const runJustifiedGallery = i => {
if (!btf.isHidden(i)) {
fjGallery(i, {
itemSelector: '.fj-gallery-item',
@@ -262,7 +276,10 @@ const btf = {
}
})
}
})
}
if (Array.from(selector).length === 0) runJustifiedGallery(selector)
else selector.forEach(i => { runJustifiedGallery(i) })
},
updateAnchor: (anchor) => {