From 8014ddb65ef03f059edca863617a532bf4085076 Mon Sep 17 00:00:00 2001 From: Jerry Date: Thu, 15 Oct 2020 00:14:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8D=E5=86=8D=E6=94=AF=E6=8C=81=20?= =?UTF-8?q?butterfly.yml=20=E5=AF=AB=E6=B3=95=20improvement:=20=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E9=A0=81=E6=A8=99=E9=A1=8C=E6=94=B9=E7=82=BAh1(seo)?= =?UTF-8?q?=20improvement:=20=E6=94=B9=E7=94=A8hexo=20=E5=85=A7=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=20injector=20=E6=8F=92=E5=85=A5=20inject=20=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A2=BC=20improvement:=20canonical=20=E6=94=B9?= =?UTF-8?q?=E7=82=BAhexo=E6=8F=90=E4=BE=9B=E7=9A=84=E5=87=BD=E6=95=B8?= =?UTF-8?q?=E7=94=9F=E6=88=90=20improvement:=20=E5=84=AA=E5=8C=96=E6=89=8B?= =?UTF-8?q?=E6=A9=9Ftoc=20=E7=9A=84=E7=89=B9=E6=95=88=E5=92=8C=E6=8C=89?= =?UTF-8?q?=E9=88=95=E5=87=BA=E7=8F=BE=E7=9A=84=E6=99=82=E6=A9=9F=20remove?= =?UTF-8?q?:=20=E5=88=AA=E9=99=A4=E6=90=9C=E7=B4=A2=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E9=85=8D=E7=BD=AE=20remove:=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E8=B1=86=E7=93=A3=E9=85=8D=E7=BD=AE,=E5=A6=82?= =?UTF-8?q?=E9=9C=80=E9=85=8D=E7=BD=AE=EF=BC=8C=E8=AB=8B=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20hexo-butterfly-douban=20fix:=20=E4=BF=AE=E5=BE=A9=E4=B8=8A?= =?UTF-8?q?=E4=B8=80=E5=80=8B=E7=89=88=E6=9C=AC=E5=B0=8E=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=8C=89=E9=88=95=E5=9C=A8pjax=E4=B8=8B?= =?UTF-8?q?=E7=84=A1=E6=B3=95=E9=BB=9E=E6=93=8A=E7=9A=84bugs=20close=20#38?= =?UTF-8?q?7=20fix:=20=E4=BF=AE=E5=BE=A9=E4=B8=8A=E4=B8=80=E5=80=8B?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E7=9A=84toc=20z-index=20?= =?UTF-8?q?=E9=81=8E=E4=BD=8E=E7=9A=84bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 27 +++++-------------- languages/default.yml | 2 +- languages/en.yml | 2 +- languages/zh-CN.yml | 2 +- languages/zh-TW.yml | 2 +- layout/includes/additional-js.pug | 2 -- layout/includes/head.pug | 2 -- layout/includes/header/index.pug | 12 --------- layout/includes/header/post-info.pug | 3 +-- layout/includes/page/default-page.pug | 2 -- .../includes/widget/card_newest_comment.pug | 2 +- package.json | 2 +- scripts/events/{check_hexo.js => check.js} | 9 +++++++ scripts/events/replace_config.js | 18 ------------- scripts/filters/random_cover.js | 3 ++- scripts/helpers/page.js | 19 ++----------- scripts/helpers/related_post.js | 2 +- scripts/injector/inject.js | 22 +++++++++++++++ scripts/{tags => tag}/button.js | 0 scripts/{tags => tag}/gallery.js | 0 scripts/{tags => tag}/hide.js | 0 scripts/{tags => tag}/mermaid.js | 0 scripts/{tags => tag}/note.js | 0 scripts/{tags => tag}/tabs.js | 0 source/css/_global/index.styl | 13 ++++----- source/css/_highlight/highlight.styl | 1 + source/css/_layout/404.styl | 3 ++- source/css/_layout/aside.styl | 12 +++------ source/css/_layout/head.styl | 15 +++++------ source/css/_layout/rightside.styl | 2 +- source/css/var.styl | 2 +- source/js/main.js | 7 +++-- source/js/search/algolia.js | 2 +- source/js/search/local-search.js | 3 ++- 34 files changed, 80 insertions(+), 113 deletions(-) rename scripts/events/{check_hexo.js => check.js} (55%) delete mode 100644 scripts/events/replace_config.js create mode 100644 scripts/injector/inject.js rename scripts/{tags => tag}/button.js (100%) rename scripts/{tags => tag}/gallery.js (100%) rename scripts/{tags => tag}/hide.js (100%) rename scripts/{tags => tag}/mermaid.js (100%) rename scripts/{tags => tag}/note.js (100%) rename scripts/{tags => tag}/tabs.js (100%) diff --git a/_config.yml b/_config.yml index 4bb3fd3..f1aedd4 100644 --- a/_config.yml +++ b/_config.yml @@ -53,17 +53,9 @@ algolia_search: hits: per_page: 6 - labels: - input_placeholder: Search for Posts - hits_empty: "We didn't find any results for the search: ${query}" # if there are no result - hits_stats: '${hits} results found in ${time} ms' - # Local search local_search: enable: false - labels: - input_placeholder: Search for Posts - hits_empty: "We didn't find any results for the search: ${query}" # if there are no result # Math (數學) # -------------------------------------- @@ -108,7 +100,7 @@ archive_img: tag_img: # The banner image of tag page -# format: +# format: # - tag name: xxxxx tag_per_img: @@ -117,17 +109,10 @@ tag_per_img: category_img: # The banner image of category page -# format: +# format: # - category name: xxxxx category_per_img: -# If you are using hexo-douban, you can configure it (如果你有使用 hexo-douban,可配置這個) -# douban: -# meta: false -# movies_img: -# books_img: -# games_img: - cover: # display the cover or not (是否顯示文章封面) index_enable: true @@ -576,9 +561,9 @@ font: # Font settings for the site title and site subtitle # 左上角網站名字 主頁居中網站名字 -# blog_title_font: - # font_link: https://fonts.googleapis.com/css?family=Titillium+Web&display=swap - # font-family: Titillium Web, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif +blog_title_font: + font_link: + font-family: # The setting of divider icon (水平分隔線圖標設置) hr_icon: @@ -919,4 +904,4 @@ CDN: prismjs_lineNumber_js: https://cdn.jsdelivr.net/npm/prismjs/plugins/line-numbers/prism-line-numbers.min.js prismjs_autoloader: https://cdn.jsdelivr.net/npm/prismjs/plugins/autoloader/prism-autoloader.min.js - artitalk: https://cdn.jsdelivr.net/npm/artitalk \ No newline at end of file + artitalk: https://cdn.jsdelivr.net/npm/artitalk diff --git a/languages/default.yml b/languages/default.yml index aeb6406..d1699c3 100644 --- a/languages/default.yml +++ b/languages/default.yml @@ -71,7 +71,7 @@ aside: site_pv_name: PV more_button: More card_newest_comments: - heading: Newest Comments + headline: Newest Comments loading_text: loading... error: Unable to get the data, please make sure the settings are correct. card_toc: Catalog diff --git a/languages/en.yml b/languages/en.yml index aeb6406..d1699c3 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -71,7 +71,7 @@ aside: site_pv_name: PV more_button: More card_newest_comments: - heading: Newest Comments + headline: Newest Comments loading_text: loading... error: Unable to get the data, please make sure the settings are correct. card_toc: Catalog diff --git a/languages/zh-CN.yml b/languages/zh-CN.yml index f17a563..2a1a762 100644 --- a/languages/zh-CN.yml +++ b/languages/zh-CN.yml @@ -73,7 +73,7 @@ aside: site_pv_name: 本站总访问量 more_button: 查看更多 card_newest_comments: - heading: 最新评论 + headline: 最新评论 loading_text: 正在加载中... error: 无法获取资料,请确认相关配置是否正确 card_toc: 目录 diff --git a/languages/zh-TW.yml b/languages/zh-TW.yml index cb254c9..2b30d2a 100644 --- a/languages/zh-TW.yml +++ b/languages/zh-TW.yml @@ -73,7 +73,7 @@ aside: site_pv_name: 本站總訪問量 more_button: 檢視更多 card_newest_comments: - heading: 最新評論 + headline: 最新評論 loading_text: 正在加載中... error: 無法獲取資料,請確認相關配置是否正確 card_toc: 目錄 diff --git a/layout/includes/additional-js.pug b/layout/includes/additional-js.pug index 214badc..9e6c8bf 100644 --- a/layout/includes/additional-js.pug +++ b/layout/includes/additional-js.pug @@ -55,8 +55,6 @@ div else if (!is_post() && page.aside !== false) !=partial('includes/third-party/newest-comments/index', {}, {cache:theme.fragment_cache}) - !=fragment_cache('injectBottom', function(){return injectHtml(theme.inject.bottom)}) - !=partial('includes/third-party/effect', {}, {cache:theme.fragment_cache}) !=partial('includes/third-party/chat/index', {}, {cache:theme.fragment_cache}) diff --git a/layout/includes/head.pug b/layout/includes/head.pug index 9ec57e9..62d0db5 100644 --- a/layout/includes/head.pug +++ b/layout/includes/head.pug @@ -81,5 +81,3 @@ include ./head/noscript.pug !=partial('includes/head/darkmode', {}, {cache:theme.fragment_cache}) -!=fragment_cache('injectHead', function(){return injectHtml(theme.inject.head)}) - diff --git a/layout/includes/header/index.pug b/layout/includes/header/index.pug index c4ed6e6..4fe2e2c 100644 --- a/layout/includes/header/index.pug +++ b/layout/includes/header/index.pug @@ -16,18 +16,6 @@ if page.top_img !== false else - var top_img = page.top_img || theme.default_top_img - if theme.douban - - var doubanExist = false - if is_current('/movies/', [strict]) - - var top_img = theme.douban.movies_img !== false ? theme.douban.movies_img || theme.default_top_img : false - - doubanExist = true - else if is_current('/books/', [strict]) - - var top_img = theme.douban.books_img !== false ? theme.douban.books_img || theme.default_top_img : false - - doubanExist = true - else if is_current('/games/', [strict]) - - var top_img = theme.douban.games_img !== false ? theme.douban.games_img || theme.default_top_img : false - - doubanExist = true - if top_img !== false - var imgSource = top_img && top_img.indexOf('/') !== -1 ? `background-image: url(${url_for(top_img)})` : `background: ${top_img}` - var bg_img = top_img ? imgSource : '' diff --git a/layout/includes/header/post-info.pug b/layout/includes/header/post-info.pug index 9fe7134..2d94928 100644 --- a/layout/includes/header/post-info.pug +++ b/layout/includes/header/post-info.pug @@ -1,6 +1,5 @@ #post-info - #post-title - .posttitle= page.title || _p('no_title') + h1.post-title= page.title || _p('no_title') #post-meta .meta-firstline diff --git a/layout/includes/page/default-page.pug b/layout/includes/page/default-page.pug index f995e44..2d9cdda 100644 --- a/layout/includes/page/default-page.pug +++ b/layout/includes/page/default-page.pug @@ -1,5 +1,3 @@ -if theme.douban && theme.douban.meta && doubanExist - meta(name="referrer" content="no-referrer") #article-container if top_img === false h1.page-title= page.title diff --git a/layout/includes/widget/card_newest_comment.pug b/layout/includes/widget/card_newest_comment.pug index 1338338..76a19aa 100644 --- a/layout/includes/widget/card_newest_comment.pug +++ b/layout/includes/widget/card_newest_comment.pug @@ -2,6 +2,6 @@ .card-content .item-headline i.fas.fa-bolt - span= _p('aside.card_newest_comments.heading') + span= _p('aside.card_newest_comments.headline') .aside-list span= _p('aside.card_newest_comments.loading_text') diff --git a/package.json b/package.json index 30531b4..49010f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-butterfly", - "version": "3.3.0-b2", + "version": "3.3.0-b3", "description": "A Simple and Card UI Design theme for Hexo", "main": "package.json", "scripts": { diff --git a/scripts/events/check_hexo.js b/scripts/events/check.js similarity index 55% rename from scripts/events/check_hexo.js rename to scripts/events/check.js index fb341f1..33cfae8 100644 --- a/scripts/events/check_hexo.js +++ b/scripts/events/check.js @@ -9,4 +9,13 @@ hexo.extend.filter.register('before_generate', () => { logger.error('請把 Hexo 升級到 V5.0.0 或更高的版本!') process.exit(-1) } + + if (hexo.locals.get) { + const data = hexo.locals.get('data') + if (data && data.butterfly) { + logger.error(" 'butterfly.yml' is deprecated. Please use '_config.butterfly.yml' ") + logger.error(" 'butterfly.yml' 已經棄用,請使用 '_config.butterfly.yml' ") + process.exit(-1) + } + } }) diff --git a/scripts/events/replace_config.js b/scripts/events/replace_config.js deleted file mode 100644 index 3bd05a8..0000000 --- a/scripts/events/replace_config.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Note: configs in _data/butterfly.yml will merge configs with hexo.theme.config. - */ - -'use strict' - -const { deepMerge } = require('hexo-util') - -hexo.on('generateBefore', function () { - const rootConfig = hexo.config - if (hexo.locals.get) { - const data = hexo.locals.get('data') - if (data && data.butterfly) { - hexo.theme.config = deepMerge(hexo.theme.config, data.butterfly) - } - } - hexo.theme.config.rootConfig = rootConfig -}) diff --git a/scripts/filters/random_cover.js b/scripts/filters/random_cover.js index f484dd1..8455d60 100644 --- a/scripts/filters/random_cover.js +++ b/scripts/filters/random_cover.js @@ -6,7 +6,8 @@ 'use strict' hexo.extend.filter.register('before_post_render', function (data) { - if (hexo.theme.config.rootConfig.post_asset_folder) { + const { config } = this + if (config.post_asset_folder) { const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/ const topImg = data.top_img const cover = data.cover diff --git a/scripts/helpers/page.js b/scripts/helpers/page.js index 52642ee..270c166 100644 --- a/scripts/helpers/page.js +++ b/scripts/helpers/page.js @@ -2,13 +2,12 @@ * Butterfly * @example * page_description() - * injectHtml(data) * cloudTags(source, minfontsize, maxfontsize, limit) */ 'use strict' -const { stripHTML, escapeHTML } = require('hexo-util') +const { stripHTML, escapeHTML, prettyUrls } = require('hexo-util') const crypto = require('crypto') hexo.extend.helper.register('page_description', function () { @@ -23,15 +22,6 @@ hexo.extend.helper.register('page_description', function () { } }) -hexo.extend.helper.register('injectHtml', function (data) { - let result = '' - if (!data) return '' - for (let i = 0; i < data.length; i++) { - result += data[i] - } - return result -}) - hexo.extend.helper.register('cloudTags', function (options = {}) { const env = this let source = options.source @@ -65,12 +55,7 @@ hexo.extend.helper.register('cloudTags', function (options = {}) { }) hexo.extend.helper.register('urlNoIndex', function () { - const { permalink } = hexo.config - let url = this.url.replace(/index\.html$/, '') - if (!permalink.endsWith('.html')) { - url = url.replace(/\.html$/, '') - } - return url + return prettyUrls(this.url, { trailing_index: false, trailing_html: false }) }) hexo.extend.helper.register('md5', function (path) { diff --git a/scripts/helpers/related_post.js b/scripts/helpers/related_post.js index ee06e06..24992b4 100644 --- a/scripts/helpers/related_post.js +++ b/scripts/helpers/related_post.js @@ -35,7 +35,7 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) { return '' } let result = '' - const hexoConfig = hexo.theme.config.rootConfig + const hexoConfig = hexo.config const config = hexo.theme.config const limitNum = config.related_post.limit || 6 diff --git a/scripts/injector/inject.js b/scripts/injector/inject.js new file mode 100644 index 0000000..069223e --- /dev/null +++ b/scripts/injector/inject.js @@ -0,0 +1,22 @@ +// Injector + +'use strict' + +hexo.extend.injector.register('head_end', function () { + const data = hexo.config.theme_config && hexo.config.theme_config.inject.head + return genResult(data) +}) + +hexo.extend.injector.register('body_end', () => { + const data = hexo.config.theme_config && hexo.config.theme_config.inject.bottom + return genResult(data) +}) + +function genResult (data) { + let result = '' + if (!data) return '' + for (let i = 0; i < data.length; i++) { + result += data[i] + } + return result +} diff --git a/scripts/tags/button.js b/scripts/tag/button.js similarity index 100% rename from scripts/tags/button.js rename to scripts/tag/button.js diff --git a/scripts/tags/gallery.js b/scripts/tag/gallery.js similarity index 100% rename from scripts/tags/gallery.js rename to scripts/tag/gallery.js diff --git a/scripts/tags/hide.js b/scripts/tag/hide.js similarity index 100% rename from scripts/tags/hide.js rename to scripts/tag/hide.js diff --git a/scripts/tags/mermaid.js b/scripts/tag/mermaid.js similarity index 100% rename from scripts/tags/mermaid.js rename to scripts/tag/mermaid.js diff --git a/scripts/tags/note.js b/scripts/tag/note.js similarity index 100% rename from scripts/tags/note.js rename to scripts/tag/note.js diff --git a/scripts/tags/tabs.js b/scripts/tag/tabs.js similarity index 100% rename from scripts/tags/tabs.js rename to scripts/tag/tabs.js diff --git a/source/css/_global/index.styl b/source/css/_global/index.styl index a6903f2..c2b1db0 100644 --- a/source/css/_global/index.styl +++ b/source/css/_global/index.styl @@ -152,12 +152,13 @@ a color: $light-blue // font -#site-title, -#site-subtitle, -#site-name, -#aside_content .author-info__name, -#aside_content .author-info__description - font-family: $site-name-font +if $site-name-font + #site-title, + #site-subtitle, + #site-name, + #aside_content .author-info__name, + #aside_content .author-info__description + font-family: $site-name-font .is-center text-align: center diff --git a/source/css/_highlight/highlight.styl b/source/css/_highlight/highlight.styl index 687fbcb..4f0390f 100644 --- a/source/css/_highlight/highlight.styl +++ b/source/css/_highlight/highlight.styl @@ -126,6 +126,7 @@ blockquote text-transform: uppercase font-weight: bold font-size: 1.15em + user-select: none .copy-notice position: absolute diff --git a/source/css/_layout/404.styl b/source/css/_layout/404.styl index ee0d698..e7cedcb 100644 --- a/source/css/_layout/404.styl +++ b/source/css/_layout/404.styl @@ -45,7 +45,8 @@ if hexo-config('error_404.enable') padding: .5rem text-align: center font-size: 14px - font-family: $site-name-font + if $site-name-font + font-family: $site-name-font +maxWidth768() flex: 1.1 diff --git a/source/css/_layout/aside.styl b/source/css/_layout/aside.styl index ea93b5e..862a8b8 100644 --- a/source/css/_layout/aside.styl +++ b/source/css/_layout/aside.styl @@ -269,15 +269,11 @@ position: fixed right: 45px bottom: 30px - z-index: 9999 + z-index: 100 display: none width: 300px transform-origin: right bottom - animation: toc-close .3s - - &.open - display: block - animation: toc-open .3s + animation: toc-open .3s .toc-child display: block !important @@ -327,7 +323,7 @@ @keyframes toc-close 0% - transform: scale(.7) + transform: scale(1) 100% - transform: scale(1) + transform: scale(.7) diff --git a/source/css/_layout/head.styl b/source/css/_layout/head.styl index 4f93edd..58fdc85 100644 --- a/source/css/_layout/head.styl +++ b/source/css/_layout/head.styl @@ -130,19 +130,18 @@ padding: 0 1.1rem #post-info - #post-title + .post-title + @extend .limit-more-line margin-bottom: .4rem font-size: 2.5em + font-weight: normal + color: var(--white) + line-height: 1.5 + -webkit-line-clamp: 3 +maxWidth768() font-size: 1.72em - .posttitle - @extend .limit-more-line - color: var(--white) - line-height: 1.5 - -webkit-line-clamp: 3 - #post-meta color: var(--light-grey) font-size: 95% @@ -189,7 +188,7 @@ & > #post-info margin-bottom: 1.5rem - .posttitle + .post-title padding-bottom: .2rem border-bottom: 1px solid var(--light-grey) color: var(--text-highlight-color) diff --git a/source/css/_layout/rightside.styl b/source/css/_layout/rightside.styl index 46b2482..44ba2c8 100644 --- a/source/css/_layout/rightside.styl +++ b/source/css/_layout/rightside.styl @@ -36,5 +36,5 @@ #mobile-toc-button display: none - +maxWidth1024() + +maxWidth900() display: block diff --git a/source/css/var.styl b/source/css/var.styl index ba88091..70328ef 100644 --- a/source/css/var.styl +++ b/source/css/var.styl @@ -17,7 +17,7 @@ $dafault-font-family = -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica $dafault-code-font = consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', sans-serif $font-family = hexo-config('font.font-family') ? unquote(hexo-config('font.font-family')) : $dafault-font-family $code-font-family = hexo-config('font.code-font-family') ? unquote(hexo-config('font.code-font-family')) : $dafault-code-font -$site-name-font = hexo-config('blog_title_font.font-family') ? unquote(hexo-config('blog_title_font.font-family')) : $font-family +$site-name-font = hexo-config('blog_title_font.font-family') && unquote(hexo-config('blog_title_font.font-family')) // hr $hrEnable = hexo-config('hr_icon') && hexo-config('hr_icon.enable') $hr-icon = $hrEnable && hexo-config('hr_icon.icon') ? hexo-config('hr_icon.icon') : '\f0c4' diff --git a/source/js/main.js b/source/js/main.js index 9b251cd..8a5e1e7 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -351,11 +351,14 @@ $(function () { const mobileToc = { open: () => { - $cardTocLayout.addClass('open') + $cardTocLayout.css('display', 'block') }, close: () => { - $cardTocLayout.removeClass('open') + $cardTocLayout.css('animation', 'toc-close .2s') + setTimeout(() => { + $cardTocLayout.css({ display: '', animation: '' }) + }, 100) } } diff --git a/source/js/search/algolia.js b/source/js/search/algolia.js index c3f4b11..822607c 100644 --- a/source/js/search/algolia.js +++ b/source/js/search/algolia.js @@ -36,7 +36,7 @@ $(function () { searchClickFn() - window.addEventListener('pjax:send', function () { + window.addEventListener('pjax:complete', function () { closeSearch() searchClickFn() }) diff --git a/source/js/search/local-search.js b/source/js/search/local-search.js index 42ec4e4..088d54c 100644 --- a/source/js/search/local-search.js +++ b/source/js/search/local-search.js @@ -47,7 +47,8 @@ $(function () { } searchClickFn() - window.addEventListener('pjax:send', function () { + + window.addEventListener('pjax:complete', function () { $('#local-search').is(':visible') && closeSearch() searchClickFn() })