feature: 增加 tags 標簽外掛 - label

improvement: 優化 pjax 下 404 頁面
This commit is contained in:
Jerry 2021-04-25 22:08:07 +08:00
parent 597f0d2019
commit aa7173fc69
12 changed files with 90 additions and 75 deletions

View File

@ -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

17
layout/includes/404.pug Normal file
View File

@ -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')

View File

@ -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)}'
}

View File

@ -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})

View File

@ -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')
}
})

View File

@ -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": {

View File

@ -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
}
}
})

16
scripts/tag/label.js Normal file
View File

@ -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 `<mark class="hl-label ${className}">${text}</mark> `
}
hexo.extend.tag.register('label', addLabel, { ends: false })

View File

@ -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,

View File

@ -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

View File

@ -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')

View File

@ -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)
}
}