🐛 修復POST-META關閉閲讀分鐘和訪問量後,評論量前有分割線的bug

🐛 修復canvas_ribbon透明度變為1再變回預設值bug
🐛 修復當default_cover沒設置時,會出現無圖片的bug
🎨 部分js調整
This commit is contained in:
Jerry 2020-04-02 22:16:01 +08:00
parent 5e37ab641a
commit eb11e4afeb
18 changed files with 433 additions and 315 deletions

View File

@ -17,7 +17,6 @@ html(lang=config.language data-theme=theme.display_mode)
h1#error_title= '404' h1#error_title= '404'
#error_subtitle= theme.error_404.subtitle #error_subtitle= theme.error_404.subtitle
include includes/rightside.pug include includes/rightside.pug
include includes/search/index.pug !=partial('includes/search/index', {}, {cache:theme.fragment_cache})
each item in theme.CDN_USE.js !=fragment_cache('my_js', function(){return my_html('js',theme.CDN_USE.js)})
script(src=url_for(item))
include includes/additional-js.pug include includes/additional-js.pug

View File

@ -62,21 +62,21 @@
span.post-meta-commentcount span.post-meta-commentcount
- var commentCount = theme.fontawesome_v5 && theme.fontawesome_v5.enable ? 'far fa-comments' : 'fa fa-comment-o' - var commentCount = theme.fontawesome_v5 && theme.fontawesome_v5.enable ? 'far fa-comments' : 'fa fa-comment-o'
if ((theme.disqus && theme.disqus.enable && theme.disqus.count && page.comments !== false) || (theme.disqusjs && theme.disqusjs.enable && theme.disqusjs.count && page.comments !== false)) if ((theme.disqus && theme.disqus.enable && theme.disqus.count && page.comments !== false) || (theme.disqusjs && theme.disqusjs.enable && theme.disqusjs.count && page.comments !== false))
if (theme.busuanzi && theme.busuanzi.page_pv) if (postWordcount || theme.busuanzi.page_pv)
span.post-meta__separator | span.post-meta__separator |
i.post-meta__icon(class=commentCount aria-hidden="true") i.post-meta__icon(class=commentCount aria-hidden="true")
span= _p('post.comments') + ':' span= _p('post.comments') + ':'
span.disqus-comment-count.comment-count span.disqus-comment-count.comment-count
a(href=full_url_for(page.path) + '#disqus_thread') a(href=full_url_for(page.path) + '#disqus_thread')
else if (theme.valine && theme.valine.enable && theme.valine.count && page.comments !== false) else if (theme.valine && theme.valine.enable && theme.valine.count && page.comments !== false)
if (theme.busuanzi && theme.busuanzi.page_pv) if (postWordcount || theme.busuanzi.page_pv)
span.post-meta__separator | span.post-meta__separator |
i.post-meta__icon(class=commentCount aria-hidden="true") i.post-meta__icon(class=commentCount aria-hidden="true")
span= _p('post.comments') + ':' span= _p('post.comments') + ':'
a(href=url_for(page.path) + '#post-comment' itemprop="discussionUrl") a(href=url_for(page.path) + '#post-comment' itemprop="discussionUrl")
span.valine-comment-count.comment-count(data-xid=url_for(page.path) itemprop="commentCount") span.valine-comment-count.comment-count(data-xid=url_for(page.path) itemprop="commentCount")
else if (theme.gitalk && theme.gitalk.enable && theme.gitalk.count && page.comments !== false) else if (theme.gitalk && theme.gitalk.enable && theme.gitalk.count && page.comments !== false)
if (theme.busuanzi && theme.busuanzi.page_pv) if (postWordcount || theme.busuanzi.page_pv)
span.post-meta__separator | span.post-meta__separator |
i.post-meta__icon(class=commentCount aria-hidden="true") i.post-meta__icon(class=commentCount aria-hidden="true")
span= _p('post.comments') + ':' span= _p('post.comments') + ':'

View File

@ -1,8 +1,15 @@
hexo.extend.generator.register('404', function(locals){ /**
* Butterfly
* 404 error page
*/
'use strict'
hexo.extend.generator.register('404', function (locals) {
if (!hexo.theme.config.error_404.enable) return if (!hexo.theme.config.error_404.enable) return
return { return {
path: '404.html', path: '404.html',
data: locals.posts, data: locals.posts,
layout: ['404'] layout: ['404']
} }
}); })

View File

@ -2,6 +2,8 @@
* Note: configs in _data/butterfly.yml will replace configs in hexo.theme.config. * Note: configs in _data/butterfly.yml will replace configs in hexo.theme.config.
*/ */
'use strict'
hexo.on('generateBefore', function () { hexo.on('generateBefore', function () {
const rootConfig = hexo.config const rootConfig = hexo.config
if (hexo.locals.get) { if (hexo.locals.get) {
@ -9,4 +11,4 @@ hexo.on('generateBefore', function () {
data && data.butterfly && (hexo.theme.config = data.butterfly) data && data.butterfly && (hexo.theme.config = data.butterfly)
} }
hexo.theme.config.rootConfig = rootConfig hexo.theme.config.rootConfig = rootConfig
}) })

View File

@ -4,60 +4,63 @@
* modify by Jerry * modify by Jerry
*/ */
'use strict'; 'use strict'
var public_generators = []; var public_generators = []
hexo.extend.filter.register('before_generate', function () { hexo.extend.filter.register('before_generate', function () {
this._bindLocals(); this._bindLocals()
const all_posts = this.locals.get('posts'); const all_posts = this.locals.get('posts')
const hidden_posts = all_posts.find({ const hidden_posts = all_posts.find({
'hide': true hide: true
}); })
const normal_posts = all_posts.filter(post => !post['hide']); const normal_posts = all_posts.filter(post => !post.hide)
this.locals.set('all_posts', all_posts); this.locals.set('all_posts', all_posts)
this.locals.set('hidden_posts', hidden_posts); this.locals.set('hidden_posts', hidden_posts)
this.locals.set('posts', normal_posts); this.locals.set('posts', normal_posts)
}); })
hexo.extend.filter.register('after_init', function () { hexo.extend.filter.register('after_init', function () {
const original = {}
const original = {};
for (const name in hexo.extend.generator.list()) { for (const name in hexo.extend.generator.list()) {
original[name] = hexo.extend.generator.get(name); original[name] = hexo.extend.generator.get(name)
} }
hexo.extend.generator.register('post', async function (locals) { hexo.extend.generator.register('post', async function (locals) {
const fg = original.post.bind(this); const fg = original.post.bind(this)
const generated_public = await fg(locals); const generated_public = await fg(locals)
const generated_hidden = await fg(Object.assign({}, locals, { const generated_hidden = await fg(
posts: locals.hidden_posts Object.assign({}, locals, {
})); posts: locals.hidden_posts
})
)
// Remove post.prev and post.next for hidden posts // Remove post.prev and post.next for hidden posts
generated_hidden.forEach(ele => { generated_hidden.forEach(ele => {
ele.data.prev = ele.data.next = null; ele.data.prev = ele.data.next = null
}); })
return generated_public.concat(generated_hidden); return generated_public.concat(generated_hidden)
}); })
// Then we hack into other generators if necessary // Then we hack into other generators if necessary
public_generators.filter( public_generators
name => Object.keys(original).includes(name) .filter(name => Object.keys(original).includes(name))
).forEach(name => { .forEach(name => {
// Overwrite original generator // Overwrite original generator
hexo.extend.generator.register(name, function (locals) { hexo.extend.generator.register(name, function (locals) {
const fg = original[name].bind(this); const fg = original[name].bind(this)
return fg(Object.assign({}, locals, { return fg(
posts: new locals.posts.constructor( Object.assign({}, locals, {
locals.posts.data.concat(locals.hidden_posts.data) posts: new locals.posts.constructor(
locals.posts.data.concat(locals.hidden_posts.data)
)
})
) )
})); })
}); })
}); })
});

View File

@ -1,29 +1,39 @@
'use strict'; /**
* Butterfly
* lazyload
* replace src to data-src
* add class 'lazyload'
*/
const url_for = require('hexo-util').url_for.bind(hexo); 'use strict'
function lazyProcess(htmlContent) { const url_for = require('hexo-util').url_for.bind(hexo)
var bg = url_for(hexo.theme.config.lodding_bg.post);
return htmlContent.replace(/<img(.*?)src="(.*?)"(.*?)>/gi, (str, p1, p2, p3) => { function lazyProcess (htmlContent) {
if (/data-src/gi.test(str)) { var bg = url_for(hexo.theme.config.lodding_bg.post)
return str; return htmlContent.replace(
} /<img(.*?)src="(.*?)"(.*?)>/gi,
if (/class="(.*?)"/gi.test(str)){ (str, p1, p2, p3) => {
str = str.replace(/class="(.*?)"/gi, (classStr, p1) => { if (/data-src/gi.test(str)) {
return classStr.replace(p1, `${p1} lazyload`); return str
}) }
if (/class="(.*?)"/gi.test(str)) {
str = str.replace(/class="(.*?)"/gi, (classStr, p1) => {
return classStr.replace(p1, `${p1} lazyload`)
})
str = str.replace(p2, `${bg}`)
return str.replace('>', ` data-src="${p2}">`)
}
str = str.replace(p2, `${bg}`) str = str.replace(p2, `${bg}`)
return str.replace('>', ` data-src="${p2}">`); return str.replace(p3, ` class="lazyload" data-src="${p2}" ${p3}`)
} }
str = str.replace(p2, `${bg}`) )
return str.replace(p3, ` class="lazyload" data-src="${p2}" ${p3}`);
});
} }
var processPost = function(data) { var processPost = function (data) {
if (!hexo.theme.config.lazyload.enable) return; if (!hexo.theme.config.lazyload.enable) return
data.content = lazyProcess.call(this, data.content); data.content = lazyProcess.call(this, data.content)
return data; return data
}; }
hexo.extend.filter.register('after_post_render', processPost); hexo.extend.filter.register('after_post_render', processPost)

View File

@ -1,23 +1,34 @@
hexo.extend.filter.register("before_post_render", function(data) { /**
if (data.cover == false) { * Butterfly
data.randomcover = random_cover(); * ramdom cover
return data; */
}
data.cover = data.cover || random_cover();
return data;
});
var random_cover = function() { 'use strict'
var cover;
var num; hexo.extend.filter.register('before_post_render', function (data) {
if (!Array.isArray(hexo.theme.config.cover.default_cover)) { if (data.cover === false) {
cover = hexo.theme.config.cover.default_cover; data.randomcover = randomCover()
return cover; return data
} else {
num = Math.floor(
Math.random() * hexo.theme.config.cover.default_cover.length
);
cover = hexo.theme.config.cover.default_cover[num];
return cover;
} }
}; data.cover = data.cover || randomCover()
return data
})
var randomCover = function () {
var theme = hexo.theme.config
var cover
var num
if (theme.cover.default_cover) {
if (!Array.isArray(theme.cover.default_cover)) {
cover = theme.cover.default_cover
return cover
} else {
num = Math.floor(Math.random() * theme.cover.default_cover.length)
cover = theme.cover.default_cover[num]
return cover
}
} else {
return theme.default_top_img
}
}

View File

@ -1,50 +1,55 @@
"use strict"; /**
* Butterfly
* for aside archives
*/
hexo.extend.helper.register("list_archives", function(options = {}) { 'use strict'
const { config } = this;
const archiveDir = config.archive_dir; hexo.extend.helper.register('list_archives', function (options = {}) {
const { timezone } = config; const { config } = this
const lang = this.page.lang || this.page.language || config.language; const archiveDir = config.archive_dir
let { format } = options; const { timezone } = config
const type = options.type || "monthly"; const lang = this.page.lang || this.page.language || config.language
const { style = "list", transform, separator = ", " } = options; let { format } = options
const showCount = Object.prototype.hasOwnProperty.call(options, "show_count") const type = options.type || 'monthly'
const { transform } = options
const showCount = Object.prototype.hasOwnProperty.call(options, 'show_count')
? options.show_count ? options.show_count
: true; : true
const order = options.order || -1; const order = options.order || -1
const limit = 8; const limit = 8
let result = ""; let result = ''
var more_button; var moreButton
if (lang === "zh-CN") { if (lang === 'zh-CN') {
more_button = "查看更多"; moreButton = '查看更多'
} else if (lang === "zh-TW") { } else if (lang === 'zh-TW') {
more_button = "查看更多"; moreButton = '查看更多'
} else { } else {
more_button = "More"; moreButton = 'More'
} }
if (!format) { if (!format) {
format = type === "monthly" ? "MMMM YYYY" : "YYYY"; format = type === 'monthly' ? 'MMMM YYYY' : 'YYYY'
} }
const posts = this.site.posts.sort("date", order); const posts = this.site.posts.sort('date', order)
if (!posts.length) return result; if (!posts.length) return result
const data = []; const data = []
let length = 0; let length = 0
posts.forEach(post => { posts.forEach(post => {
// Clone the date object to avoid pollution // Clone the date object to avoid pollution
let date = post.date.clone(); let date = post.date.clone()
if (timezone) date = date.tz(timezone); if (timezone) date = date.tz(timezone)
if (lang) date = date.locale(lang); if (lang) date = date.locale(lang)
const year = date.year(); const year = date.year()
const month = date.month() + 1; const month = date.month() + 1
const name = date.format(format); const name = date.format(format)
const lastData = data[length - 1]; const lastData = data[length - 1]
if (!lastData || lastData.name !== name) { if (!lastData || lastData.name !== name) {
length = data.push({ length = data.push({
@ -52,52 +57,50 @@ hexo.extend.helper.register("list_archives", function(options = {}) {
year, year,
month, month,
count: 1 count: 1
}); })
} else { } else {
lastData.count++; lastData.count++
} }
}); })
const link = item => { const link = item => {
let url = `${archiveDir}/${item.year}/`; let url = `${archiveDir}/${item.year}/`
if (type === "monthly") { if (type === 'monthly') {
if (item.month < 10) url += "0"; if (item.month < 10) url += '0'
url += `${item.month}/`; url += `${item.month}/`
} }
return this.url_for(url); return this.url_for(url)
}; }
result += `<ul class="archive-list">`; result += '<ul class="archive-list">'
for (let i = 0, len = data.length; i < Math.min(len, limit); i++) { for (let i = 0, len = data.length; i < Math.min(len, limit); i++) {
const item = data[i]; const item = data[i]
result += `<li class="archive-list-item">`; result += '<li class="archive-list-item">'
result += `<a class="archive-list-link" href="${link(item)}">`; result += `<a class="archive-list-link" href="${link(item)}">`
result += `<span class="archive-list-date">`; result += '<span class="archive-list-date">'
result += transform ? transform(item.name) : item.name; result += transform ? transform(item.name) : item.name
result += `</span>`; result += '</span>'
if (showCount) { if (showCount) {
result += `<span class="archive-list-count">${item.count}</span>`; result += `<span class="archive-list-count">${item.count}</span>`
} }
result += "</a>"; result += '</a>'
result += "</li>"; result += '</li>'
} }
if (data.length > limit) { if (data.length > limit) {
result += `<li class="archive-list-item is-center">`; result += '<li class="archive-list-item is-center">'
result += result +=
`<a class="archive-list-link-more" href="` + '<a class="archive-list-link-more" href="' + '/' + `${archiveDir}" >`
"/" + result += moreButton
`${archiveDir}" >`; result += '</a>'
result += more_button; result += '</li>'
result += "</a>";
result += "</li>";
} }
result += "</ul>"; result += '</ul>'
return result; return result
}); })

View File

@ -1,23 +1,24 @@
"use strict"; /**
* Butterfly
* Generate js and css according to user setting
*/
hexo.extend.helper.register("my_html", function(type, data) { 'use strict'
var result = "";
var tag = type === "css" ? "css" : "script"; hexo.extend.helper.register('my_html', function (type, data) {
var result = ''
var tag = type === 'css' ? 'css' : 'script'
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
var src = data[i].split("||")[0].trim(); var src = data[i].split('||')[0].trim()
var other = data[i].split("||")[1] ? data[i].split("||")[1].trim() : ""; var other = data[i].split('||')[1] ? data[i].split('||')[1].trim() : ''
if (tag === "css") { if (tag === 'css') {
result += result +=
'<link rel="stylesheet" href="' + '<link rel="stylesheet" href="' + this.url_for(src) + '" ' + other + '>'
this.url_for(src) +
'" ' +
other +
">";
} else { } else {
result += result +=
'<script src="' + this.url_for(src) + '" ' + other + "></script>"; '<script src="' + this.url_for(src) + '" ' + other + '></script>'
} }
} }
return result; return result
}); })

View File

@ -1,5 +1,13 @@
/**
* Butterfly
* Related Posts
* According the tag
*/
'use strict'
hexo.extend.helper.register('related_posts', function (currentPost, allPosts) { hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
var relatedPosts = []; var relatedPosts = []
currentPost.tags.forEach(function (tag) { currentPost.tags.forEach(function (tag) {
allPosts.forEach(function (post) { allPosts.forEach(function (post) {
if (isTagRelated(tag.name, post.tags)) { if (isTagRelated(tag.name, post.tags)) {
@ -11,80 +19,108 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
weight: 1, weight: 1,
updated: post.updated, updated: post.updated,
created: post.date created: post.date
}; }
var index = findItem(relatedPosts, 'path', post.path); var index = findItem(relatedPosts, 'path', post.path)
if (index != -1) { if (index !== -1) {
relatedPosts[index].weight += 1; relatedPosts[index].weight += 1
} else { } else {
if (currentPost.path != post.path) { if (currentPost.path !== post.path) {
relatedPosts.push(relatedPost); relatedPosts.push(relatedPost)
}; }
}; }
}; }
}); })
}); })
if (relatedPosts.length == 0) { if (relatedPosts.length === 0) {
return '' return ''
}; }
var result = ""; var result = ''
const hexoConfig = hexo.theme.config.rootConfig; const hexoConfig = hexo.theme.config.rootConfig
const config = hexo.theme.config; const config = hexo.theme.config
var limit_num = config.related_post.limit || 6 var limitNum = config.related_post.limit || 6
var date_type = config.related_post.date_type || 'created' var dateType = config.related_post.date_type || 'created'
var headline_lang = this._p('post.recommend') var headlineLang = this._p('post.recommend')
var lazySrc = config.lazyload.enable ? 'data-src' : 'src'
relatedPosts = relatedPosts.sort(compare('weight')); var lazyClass = config.lazyload.enable ? 'lazyload' : ''
var lazy_src = config.lazyload.enable ? lazy_src = 'data-src' : lazy_src = 'src'
var lazy_class = config.lazyload.enable ? lazy_class = 'lazyload' : lazy_class = '' relatedPosts = relatedPosts.sort(compare('weight'))
if (relatedPosts.length > 0) { if (relatedPosts.length > 0) {
result += '<div class="relatedPosts">' result += '<div class="relatedPosts">'
result += '<div class="relatedPosts_headline"><i class="fa fa-fw fa-thumbs-up" aria-hidden="true"></i><span>' + ' ' + headline_lang + '</span></div>' result +=
'<div class="relatedPosts_headline"><i class="fa fa-fw fa-thumbs-up" aria-hidden="true"></i><span>' +
' ' +
headlineLang +
'</span></div>'
result += '<div class="relatedPosts_list">' result += '<div class="relatedPosts_list">'
for (var i = 0; i < Math.min(relatedPosts.length, limit_num); i++) { for (var i = 0; i < Math.min(relatedPosts.length, limitNum); i++) {
var cover = relatedPosts[i].cover === false ? relatedPosts[i].randomcover : relatedPosts[i].cover var cover =
result += '<div class="relatedPosts_item"><a href="' + hexoConfig.root + relatedPosts[i].path + '" title="' + relatedPosts[i].title + '">'; relatedPosts[i].cover === false
result += '<img class="relatedPosts_cover ' + lazy_class + '"' + lazy_src + '="' + cover + '">'; ? relatedPosts[i].randomcover
if (date_type == 'created') { : relatedPosts[i].cover
result += '<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i>' + ' ' + this.date(relatedPosts[i].created,hexoConfig.date_format) + '</div>' result +=
'<div class="relatedPosts_item"><a href="' +
hexoConfig.root +
relatedPosts[i].path +
'" title="' +
relatedPosts[i].title +
'">'
result +=
'<img class="relatedPosts_cover ' +
lazyClass +
'"' +
lazySrc +
'="' +
cover +
'">'
if (dateType === 'created') {
result +=
'<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i>' +
' ' +
this.date(relatedPosts[i].created, hexoConfig.date_format) +
'</div>'
} else { } else {
result += '<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-history fa-fw" aria-hidden="true"></i>' + ' ' + this.date(relatedPosts[i].updated,hexoConfig.date_format) + '</div>' result +=
'<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-history fa-fw" aria-hidden="true"></i>' +
' ' +
this.date(relatedPosts[i].updated, hexoConfig.date_format) +
'</div>'
} }
result += '<div class="relatedPosts_title">' + relatedPosts[i].title + '</div>'; result +=
'<div class="relatedPosts_title">' + relatedPosts[i].title + '</div>'
result += '</div></a></div>' result += '</div></a></div>'
}; }
result += '</div><div class="clear_both"></div></div>' result += '</div><div class="clear_both"></div></div>'
return result; return result
} }
}); })
function isTagRelated(tagName, TBDtags) { function isTagRelated (tagName, TBDtags) {
var result = false; var result = false
TBDtags.forEach(function (tag) { TBDtags.forEach(function (tag) {
if (tagName == tag.name) { if (tagName === tag.name) {
result = true; result = true
}; }
}) })
return result; return result
} }
function findItem(arrayToSearch, attr, val) { function findItem (arrayToSearch, attr, val) {
for (var i = 0; i < arrayToSearch.length; i++) { for (var i = 0; i < arrayToSearch.length; i++) {
if (arrayToSearch[i][attr] == val) { if (arrayToSearch[i][attr] === val) {
return i return i
}; }
}; }
return -1; return -1
} }
function compare(attr) { function compare (attr) {
return function (a, b) { return function (a, b) {
var val1 = a[attr]; var val1 = a[attr]
var val2 = b[attr]; var val2 = b[attr]
return val2 - val1; return val2 - val1
} }
} }

View File

@ -1,11 +1,18 @@
const url_for = require('hexo-util').url_for.bind(hexo); /**
* Butterfly
* galleryGroup and allery
*/
function gallery(args, content) { 'use strict'
return `<div class="justified-gallery">${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')}
</div>`; const url_for = require('hexo-util').url_for.bind(hexo)
function gallery (args, content) {
return `<div class="justified-gallery">${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')}
</div>`
} }
function galleryGroup(args){ function galleryGroup (args) {
const name = args[0] const name = args[0]
const desrc = args[1] const desrc = args[1]
const url = url_for(args[2]) const url = url_for(args[2])
@ -23,5 +30,5 @@ function galleryGroup(args){
` `
} }
hexo.extend.tag.register('gallery', gallery, {ends: true}); hexo.extend.tag.register('gallery', gallery, { ends: true })
hexo.extend.tag.register('galleryGroup', galleryGroup); hexo.extend.tag.register('galleryGroup', galleryGroup)

View File

@ -1,33 +1,35 @@
/** /**
* {% hideInline content,display,bg,color %} * Butterfly
* content不能包含當引號可用 &apos; * hideInline
* {% hideInline content,display,bg,color %}
* content不能包含當引號可用 &apos;
* hideBlock
* {% hideBlock display,bg,color %}
* content
* {% endhideBlock %}
*/ */
function hideInline(args) {
'use strict'
function hideInline (args) {
args = args.join(' ').split(',') args = args.join(' ').split(',')
let content = args[0].trim() const content = args[0].trim()
let display = args[1] || 'Click' const display = args[1] || 'Click'
let bg = args[2] ==='' || typeof args[2] ==='undefined' ? '' : `background-color:${args[2]}` const bg = args[2] === '' || typeof args[2] === 'undefined' ? '' : `background-color:${args[2]}`
let color = args[3] || '#fff' const color = args[3] || '#fff'
return `<span class="hide-inline"><a class="hide-button button--primary button--animated" style="color:${color};${bg}">${display} return `<span class="hide-inline"><a class="hide-button button--primary button--animated" style="color:${color};${bg}">${display}
</a><span class="hide-content">${content}</span></span>` </a><span class="hide-content">${content}</span></span>`
} }
/** function hideBlock (args, content) {
* {% hideBlock display,bg,color %}
* content
* {% endhideBlock %}
*/
function hideBlock(args,content) {
args = args.join(' ').split(',') args = args.join(' ').split(',')
let display = args[0] || 'Click' const display = args[0] || 'Click'
let bg = args[1] ==='' || typeof args[2] ==='undefined' ? '' : `background-color:${args[2]}` const bg = args[1] === '' || typeof args[2] === 'undefined' ? '' : `background-color:${args[2]}`
let color = args[2] || '#fff' const color = args[2] || '#fff'
return `<div class="hide-block"><a class="hide-button button--primary button--animated" style="color:${color};${bg}">${display}
</a><span class="hide-content">${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')}</span></div>`
return `<div class="hide-block"><a class="hide-button button--primary button--animated" style="color:${color};${bg}">${display}
</a><span class="hide-content">${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')}</span></div>`
} }
hexo.extend.tag.register('hideInline', hideInline); hexo.extend.tag.register('hideInline', hideInline)
hexo.extend.tag.register('hideBlock', hideBlock, {ends: true}); hexo.extend.tag.register('hideBlock', hideBlock, { ends: true })

View File

@ -1,7 +1,15 @@
function mermaid(args, content) { /**
* Butterfly
* mermaid
* https://github.com/mermaid-js/mermaid
*/
'use strict'
function mermaid (args, content) {
return `<div class="mermaid"> return `<div class="mermaid">
${content} ${content}
</div>`; </div>`
} }
hexo.extend.tag.register('mermaid', mermaid, {ends: true}); hexo.extend.tag.register('mermaid', mermaid, { ends: true })

View File

@ -3,13 +3,13 @@
* transplant from hexo-theme-next * transplant from hexo-theme-next
*/ */
'use strict'; 'use strict'
function postNote(args, content) { function postNote (args, content) {
return `<div class="note ${args.join(' ')}"> return `<div class="note ${args.join(' ')}">
${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')} ${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')}
</div>`; </div>`
} }
hexo.extend.tag.register('note', postNote, {ends: true}); hexo.extend.tag.register('note', postNote, { ends: true })
hexo.extend.tag.register('subnote', postNote, {ends: true}); hexo.extend.tag.register('subnote', postNote, { ends: true })

View File

@ -244,12 +244,10 @@ img:not([src])
.post-ad .post-ad
margin: 2rem 0 margin: 2rem 0
overflow-x: scroll
.ad_height .ad_height
display: block !important display: block !important
height: auto !important height: auto !important
overflow-x: scroll !important
#content-inner, #content-inner,
#footer #footer
@ -262,10 +260,13 @@ img:not([src])
#site_subtitle #site_subtitle
animation: titlescale 1s animation: titlescale 1s
canvas, canvas:not(#ribbon-canvas),
#web_bg #web_bg
animation: to_show 4s animation: to_show 4s
#ribbon-canvas
animation: ribbon_to_show 4s
.card-announcement-animation .card-announcement-animation
color: #FF0000 color: #FF0000
animation: announ_animation .8s linear infinite animation: announ_animation .8s linear infinite
@ -363,6 +364,13 @@ if hexo-config('avatar.effect') == true
100% 100%
opacity: 1 opacity: 1
@keyframes ribbon_to_show
0%
opacity: 0
100%
opacity: hexo-config('canvas_ribbon.alpha')
@keyframes avatar_turn_around @keyframes avatar_turn_around
from from
transform: rotate(0) transform: rotate(0)

View File

@ -311,4 +311,9 @@
.post-meta-pv-cv .post-meta-pv-cv
.post-meta__separator:first-child .post-meta__separator:first-child
display: none display: none
if !hexo-config('busuanzi.page_pv')
.post-meta-commentcount
.post-meta__separator
display: none

View File

@ -5,31 +5,32 @@
* GitHub: https://github.com/hustcc/ribbon.js * GitHub: https://github.com/hustcc/ribbon.js
**/ **/
!(function () { !(function() {
var script = document.getElementById("ribbon");
var script = document.getElementById('ribbon'); var mb = script.getAttribute("mobile");
var mb = script.getAttribute("mobile"); if (
if (mb == 'false' && (/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent))) { mb == "false" &&
/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)
) {
return; return;
} }
config = { config = {
z: attr(script, 'zIndex', -1), // z-index z: attr(script, "zIndex", -1), // z-index
a: attr(script, 'alpha', 0.6), // alpha a: attr(script, "alpha", 0.6), // alpha
s: attr(script, 'size', 90), // size s: attr(script, "size", 90), // size
c: attr(script, 'data-click', true) // click-to-change c: attr(script, "data-click", true) // click-to-change
} };
function attr(node, attr, default_value) {
function attr (node, attr, default_value) {
if (default_value === true) { if (default_value === true) {
return node.getAttribute(attr) || default_value return node.getAttribute(attr) || default_value;
} }
return Number(node.getAttribute(attr)) || default_value return Number(node.getAttribute(attr)) || default_value;
} }
var canvas = document.createElement('canvas'), var canvas = document.createElement("canvas"),
g2d = canvas.getContext('2d'), g2d = canvas.getContext("2d"),
pr = window.devicePixelRatio || 1, pr = window.devicePixelRatio || 1,
width = window.innerWidth, width = window.innerWidth,
height = window.innerHeight, height = window.innerHeight,
@ -40,52 +41,67 @@
r = 0, r = 0,
pi = m.PI * 2, pi = m.PI * 2,
cos = m.cos, cos = m.cos,
random = m.random random = m.random;
canvas.width = width * pr canvas.id = "ribbon-canvas";
canvas.height = height * pr canvas.width = width * pr;
g2d.scale(pr, pr) canvas.height = height * pr;
g2d.globalAlpha = config.a g2d.scale(pr, pr);
g2d.globalAlpha = config.a;
canvas.style.cssText = canvas.style.cssText =
'opacity: ' + "opacity: " +
config.a + config.a +
';position:fixed;top:0;left:0;z-index: ' + ";position:fixed;top:0;left:0;z-index: " +
config.z + config.z +
';width:100%;height:100%;pointer-events:none;' ";width:100%;height:100%;pointer-events:none;";
// create canvas // create canvas
document.getElementsByTagName('body')[0].appendChild(canvas) document.getElementsByTagName("body")[0].appendChild(canvas);
function redraw () { function redraw() {
g2d.clearRect(0, 0, width, height) g2d.clearRect(0, 0, width, height);
q = [{ x: 0, y: height * 0.7 + f }, { x: 0, y: height * 0.7 - f }] q = [
while (q[1].x < width + f) draw(q[0], q[1]) {
x: 0,
y: height * 0.7 + f
},
{
x: 0,
y: height * 0.7 - f
}
];
while (q[1].x < width + f) draw(q[0], q[1]);
} }
function draw (i, j) {
g2d.beginPath() function draw(i, j) {
g2d.moveTo(i.x, i.y) g2d.beginPath();
g2d.lineTo(j.x, j.y) g2d.moveTo(i.x, i.y);
g2d.lineTo(j.x, j.y);
var k = j.x + (random() * 2 - 0.25) * f, var k = j.x + (random() * 2 - 0.25) * f,
n = line(j.y) n = line(j.y);
g2d.lineTo(k, n) g2d.lineTo(k, n);
g2d.closePath() g2d.closePath();
r -= pi / -50 r -= pi / -50;
g2d.fillStyle = g2d.fillStyle =
'#' + "#" +
( (
((cos(r) * 127 + 128) << 16) | ((cos(r) * 127 + 128) << 16) |
((cos(r + pi / 3) * 127 + 128) << 8) | ((cos(r + pi / 3) * 127 + 128) << 8) |
(cos(r + (pi / 3) * 2) * 127 + 128) (cos(r + (pi / 3) * 2) * 127 + 128)
).toString(16) ).toString(16);
g2d.fill() g2d.fill();
q[0] = q[1] q[0] = q[1];
q[1] = { x: k, y: n } q[1] = {
x: k,
y: n
};
} }
function line (p) {
t = p + (random() * 2 - 1.1) * f function line(p) {
return t > height || t < 0 ? line(p) : t t = p + (random() * 2 - 1.1) * f;
return t > height || t < 0 ? line(p) : t;
} }
if (config.c !== 'false') { if (config.c !== "false") {
document.onclick = redraw document.onclick = redraw;
document.ontouchstart = redraw document.ontouchstart = redraw;
} }
redraw() redraw();
})() })();

View File

@ -48,10 +48,10 @@ function throttle (func, wait, options) {
return throttled return throttled
} }
function sidebarPaddingR() { function sidebarPaddingR () {
let innerWidth = window.innerWidth var innerWidth = window.innerWidth
let clientWidth = document.body.clientWidth var clientWidth = document.body.clientWidth
let paddingRight = innerWidth - clientWidth var paddingRight = innerWidth - clientWidth
if (innerWidth !== clientWidth) { if (innerWidth !== clientWidth) {
$('body').css('padding-right', paddingRight) $('body').css('padding-right', paddingRight)
} }
@ -59,7 +59,7 @@ function sidebarPaddingR() {
// iPadOS // iPadOS
function isIpad () { function isIpad () {
return navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1 return navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1
} }
function isTMobile () { function isTMobile () {