From aa7173fc6914d8994e4270c5cd8bf06924c098d8 Mon Sep 17 00:00:00 2001 From: Jerry Date: Sun, 25 Apr 2021 22:08:07 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E5=A2=9E=E5=8A=A0=20tags=20?= =?UTF-8?q?=E6=A8=99=E7=B0=BD=E5=A4=96=E6=8E=9B=20-=20label=20improvement:?= =?UTF-8?q?=20=E5=84=AA=E5=8C=96=20pjax=20=E4=B8=8B=20404=20=E9=A0=81?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layout/404.pug | 28 ------------------- layout/includes/404.pug | 17 ++++++++++++ layout/includes/head/config_site.pug | 18 ++++++------- layout/includes/layout.pug | 40 +++++++++++++++------------- layout/includes/third-party/pjax.pug | 4 --- package.json | 2 +- scripts/events/404.js | 7 +++-- scripts/tag/label.js | 16 +++++++++++ source/css/_mode/darkmode.styl | 1 + source/css/_mode/readmode.styl | 15 +++-------- source/css/_tags/label.styl | 11 ++++++++ source/js/main.js | 6 ++++- 12 files changed, 90 insertions(+), 75 deletions(-) delete mode 100644 layout/404.pug create mode 100644 layout/includes/404.pug create mode 100644 scripts/tag/label.js create mode 100644 source/css/_tags/label.styl diff --git a/layout/404.pug b/layout/404.pug deleted file mode 100644 index e4b46e4..0000000 --- a/layout/404.pug +++ /dev/null @@ -1,28 +0,0 @@ -- var top_img = theme.error_404.background || theme.default_top_img -- var bg_img = `background-image: url('${url_for(top_img)}')` - -doctype html -html(lang=config.language data-theme=theme.display_mode) - head - include includes/head.pug - body - if theme.preloader - !=partial('includes/loading/loading', {}, {cache: true}) - - if theme.fireworks && theme.fireworks.enable - canvas.fireworks - - if theme.background - #web_bg - - #error-wrap - .error-content - .error-img(style=bg_img) - .error-info - h1.error_title= '404' - .error_subtitle= theme.error_404.subtitle - a.button--animated(href=config.root) - i.fas.fa-rocket - = _p('error404.back_button') - - include includes/additional-js.pug diff --git a/layout/includes/404.pug b/layout/includes/404.pug new file mode 100644 index 0000000..1b6b4e2 --- /dev/null +++ b/layout/includes/404.pug @@ -0,0 +1,17 @@ +- var top_img = theme.error_404.background || theme.default_top_img +- var bg_img = `background-image: url('${url_for(top_img)}')` + +#body-wrap.error + div(style='display: none') + include ./header/index.pug + + #error-wrap + .error-content + .error-img(style=bg_img) + .error-info + h1.error_title= '404' + .error_subtitle= theme.error_404.subtitle + a.button--animated(href=config.root) + i.fas.fa-rocket + = _p('error404.back_button') + diff --git a/layout/includes/head/config_site.pug b/layout/includes/head/config_site.pug index 1b951be..2dbd463 100644 --- a/layout/includes/head/config_site.pug +++ b/layout/includes/head/config_site.pug @@ -8,12 +8,12 @@ var showToc = is_post() && theme.aside.enable && pageToc && (toc(page.content) !== '' || page.encrypt == true ) - -script#config-diff - . - var GLOBAL_CONFIG_SITE = { - isPost: !{is_post()}, - isHome: !{is_home()}, - isHighlightShrink: !{isHighlightShrink}, - isToc: !{showToc}, - postUpdate: '!{full_date(page.updated)}' - } +script#config-diff. + var GLOBAL_CONFIG_SITE = { + title: '!{pageTitle}', + isPost: !{is_post()}, + isHome: !{is_home()}, + isHighlightShrink: !{isHighlightShrink}, + isToc: !{showToc}, + postUpdate: '!{full_date(page.updated)}' + } diff --git a/layout/includes/layout.pug b/layout/includes/layout.pug index 6d2cc2c..5245cce 100644 --- a/layout/includes/layout.pug +++ b/layout/includes/layout.pug @@ -15,28 +15,32 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside !=partial('includes/sidebar', {}, {cache: true}) - #body-wrap(class=pageType) - include ./header/index.pug + if page.type !== '404' + #body-wrap(class=pageType) + include ./header/index.pug - main#content-inner.layout(class=hideAside) - if body - div!= body + main#content-inner.layout(class=hideAside) + if body + div!= body + else + block content + if theme.aside.enable && page.aside !== false + include widget/index.pug + + - var footerBg = theme.footer_bg + if (footerBg) + if (footerBg === true) + - var footer_bg = bg_img + else + - var footer_bg = theme.footer_bg.indexOf('/') !== -1 ? `background-image: url('${url_for(footerBg)}')` : `background: ${footerBg}` else - block content - if theme.aside.enable && page.aside !== false - include widget/index.pug + - var footer_bg = '' - - var footerBg = theme.footer_bg - if (footerBg) - if (footerBg === true) - - var footer_bg = bg_img - else - - var footer_bg = theme.footer_bg.indexOf('/') !== -1 ? `background-image: url('${url_for(footerBg)}')` : `background: ${footerBg}` - else - - var footer_bg = '' + footer#footer(style=footer_bg) + !=partial('includes/footer', {}, {cache: true}) - footer#footer(style=footer_bg) - !=partial('includes/footer', {}, {cache: true}) + else + include ./404.pug include ./rightside.pug !=partial('includes/third-party/search/index', {}, {cache: true}) diff --git a/layout/includes/third-party/pjax.pug b/layout/includes/third-party/pjax.pug index 8989f30..0246051 100644 --- a/layout/includes/third-party/pjax.pug +++ b/layout/includes/third-party/pjax.pug @@ -86,10 +86,6 @@ script. document.addEventListener('pjax:error', (e) => { if (e.request.status === 404) { - if (!{theme.anchor}) { - location.hash && e.request.responseURL !== location.href ? pjax.loadUrl(location.href) : pjax.loadUrl('/404.html') - return - } pjax.loadUrl('/404.html') } }) diff --git a/package.json b/package.json index 2b5a271..50e54ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-butterfly", - "version": "3.7.5-b4", + "version": "3.7.5-b5", "description": "A Simple and Card UI Design theme for Hexo", "main": "package.json", "scripts": { diff --git a/scripts/events/404.js b/scripts/events/404.js index c37daae..02491ce 100644 --- a/scripts/events/404.js +++ b/scripts/events/404.js @@ -9,7 +9,10 @@ hexo.extend.generator.register('404', function (locals) { if (!hexo.theme.config.error_404.enable) return return { path: '404.html', - data: locals.posts, - layout: ['404'] + layout: ['page'], + data: { + type: '404', + top_img: false + } } }) diff --git a/scripts/tag/label.js b/scripts/tag/label.js new file mode 100644 index 0000000..877c909 --- /dev/null +++ b/scripts/tag/label.js @@ -0,0 +1,16 @@ +/** + * Butterfly + * label + * {% label text color %} + */ + +'use strict' + +function addLabel (args, content) { + const text = args[0] + const className = args[1] || 'default' + + return `${text} ` +} + +hexo.extend.tag.register('label', addLabel, { ends: false }) diff --git a/source/css/_mode/darkmode.styl b/source/css/_mode/darkmode.styl index 0005450..d287bfc 100644 --- a/source/css/_mode/darkmode.styl +++ b/source/css/_mode/darkmode.styl @@ -91,6 +91,7 @@ if hexo-config('darkmode.enable') || hexo-config('display_mode') == 'dark' .hide-button, .btn-beautify, .mermaid, + .hl-label, .post-outdate-notice, .error-img, #article-container iframe, diff --git a/source/css/_mode/readmode.styl b/source/css/_mode/readmode.styl index 0ef3b36..aa16207 100644 --- a/source/css/_mode/readmode.styl +++ b/source/css/_mode/readmode.styl @@ -173,24 +173,15 @@ if hexo-config('readmode') border: 1px solid var(--gray) !important .hide-button, - .btn-beautify + .btn-beautify, + .hl-label + border: 1px solid var(--gray) !important background: var(--readmode-light-color) !important color: var(--font-color) !important - .btn-beautify - border: 1px solid var(--gray) !important - .button--animated:before background: var(--readmode-light-color) !important - .hide-inline, - .hide-block - & >.hide-button - border: 1px solid var(--gray) - - & > .button--animated:before - background: var(--readmode-light-color) - .note border: 2px solid var(--gray) border-left-color: var(--gray) !important diff --git a/source/css/_tags/label.styl b/source/css/_tags/label.styl new file mode 100644 index 0000000..56261f1 --- /dev/null +++ b/source/css/_tags/label.styl @@ -0,0 +1,11 @@ +.hl-label + padding: 2px 4px + border-radius: 3px + color: $btn-color + + &.default + background-color: $btn-default-color + + for $type in $tagsP-types + &.{$type} + background-color: lookup('$tagsP-' + $type + '-color') diff --git a/source/js/main.js b/source/js/main.js index c444428..2d73c60 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -413,7 +413,11 @@ document.addEventListener('DOMContentLoaded', function () { const updateAnchor = function (anchor) { if (window.history.replaceState && anchor !== window.location.hash) { if (!anchor) anchor = location.pathname - window.history.replaceState({}, '', anchor) + const title = GLOBAL_CONFIG_SITE.title + window.history.replaceState({ + url: location.href, + title: title + }, title, anchor) } }