mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
🐛 修復POST-META關閉閲讀分鐘和訪問量後,評論量前有分割線的bug
🐛 修復canvas_ribbon透明度變為1再變回預設值bug 🐛 修復當default_cover沒設置時,會出現無圖片的bug 🎨 部分js調整
This commit is contained in:
parent
5e37ab641a
commit
eb11e4afeb
@ -17,7 +17,6 @@ html(lang=config.language data-theme=theme.display_mode)
|
||||
h1#error_title= '404'
|
||||
#error_subtitle= theme.error_404.subtitle
|
||||
include includes/rightside.pug
|
||||
include includes/search/index.pug
|
||||
each item in theme.CDN_USE.js
|
||||
script(src=url_for(item))
|
||||
!=partial('includes/search/index', {}, {cache:theme.fragment_cache})
|
||||
!=fragment_cache('my_js', function(){return my_html('js',theme.CDN_USE.js)})
|
||||
include includes/additional-js.pug
|
||||
|
||||
@ -62,21 +62,21 @@
|
||||
span.post-meta-commentcount
|
||||
- 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.busuanzi && theme.busuanzi.page_pv)
|
||||
if (postWordcount || theme.busuanzi.page_pv)
|
||||
span.post-meta__separator |
|
||||
i.post-meta__icon(class=commentCount aria-hidden="true")
|
||||
span= _p('post.comments') + ':'
|
||||
span.disqus-comment-count.comment-count
|
||||
a(href=full_url_for(page.path) + '#disqus_thread')
|
||||
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 |
|
||||
i.post-meta__icon(class=commentCount aria-hidden="true")
|
||||
span= _p('post.comments') + ':'
|
||||
a(href=url_for(page.path) + '#post-comment' itemprop="discussionUrl")
|
||||
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)
|
||||
if (theme.busuanzi && theme.busuanzi.page_pv)
|
||||
if (postWordcount || theme.busuanzi.page_pv)
|
||||
span.post-meta__separator |
|
||||
i.post-meta__icon(class=commentCount aria-hidden="true")
|
||||
span= _p('post.comments') + ':'
|
||||
|
||||
@ -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
|
||||
return {
|
||||
path: '404.html',
|
||||
data: locals.posts,
|
||||
layout: ['404']
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
* Note: configs in _data/butterfly.yml will replace configs in hexo.theme.config.
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
hexo.on('generateBefore', function () {
|
||||
const rootConfig = hexo.config
|
||||
if (hexo.locals.get) {
|
||||
|
||||
@ -4,60 +4,63 @@
|
||||
* modify by Jerry
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var public_generators = [];
|
||||
var public_generators = []
|
||||
|
||||
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({
|
||||
'hide': true
|
||||
});
|
||||
const normal_posts = all_posts.filter(post => !post['hide']);
|
||||
hide: true
|
||||
})
|
||||
const normal_posts = all_posts.filter(post => !post.hide)
|
||||
|
||||
this.locals.set('all_posts', all_posts);
|
||||
this.locals.set('hidden_posts', hidden_posts);
|
||||
this.locals.set('posts', normal_posts);
|
||||
});
|
||||
this.locals.set('all_posts', all_posts)
|
||||
this.locals.set('hidden_posts', hidden_posts)
|
||||
this.locals.set('posts', normal_posts)
|
||||
})
|
||||
|
||||
hexo.extend.filter.register('after_init', function () {
|
||||
|
||||
const original = {};
|
||||
const original = {}
|
||||
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) {
|
||||
const fg = original.post.bind(this);
|
||||
const fg = original.post.bind(this)
|
||||
|
||||
const generated_public = await fg(locals);
|
||||
const generated_hidden = await fg(Object.assign({}, locals, {
|
||||
posts: locals.hidden_posts
|
||||
}));
|
||||
const generated_public = await fg(locals)
|
||||
const generated_hidden = await fg(
|
||||
Object.assign({}, locals, {
|
||||
posts: locals.hidden_posts
|
||||
})
|
||||
)
|
||||
|
||||
// Remove post.prev and post.next for hidden posts
|
||||
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
|
||||
public_generators.filter(
|
||||
name => Object.keys(original).includes(name)
|
||||
).forEach(name => {
|
||||
// Overwrite original generator
|
||||
hexo.extend.generator.register(name, function (locals) {
|
||||
const fg = original[name].bind(this);
|
||||
public_generators
|
||||
.filter(name => Object.keys(original).includes(name))
|
||||
.forEach(name => {
|
||||
// Overwrite original generator
|
||||
hexo.extend.generator.register(name, function (locals) {
|
||||
const fg = original[name].bind(this)
|
||||
|
||||
return fg(Object.assign({}, locals, {
|
||||
posts: new locals.posts.constructor(
|
||||
locals.posts.data.concat(locals.hidden_posts.data)
|
||||
return fg(
|
||||
Object.assign({}, locals, {
|
||||
posts: new locals.posts.constructor(
|
||||
locals.posts.data.concat(locals.hidden_posts.data)
|
||||
)
|
||||
})
|
||||
)
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -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) {
|
||||
var bg = url_for(hexo.theme.config.lodding_bg.post);
|
||||
return htmlContent.replace(/<img(.*?)src="(.*?)"(.*?)>/gi, (str, p1, p2, p3) => {
|
||||
if (/data-src/gi.test(str)) {
|
||||
return str;
|
||||
}
|
||||
if (/class="(.*?)"/gi.test(str)){
|
||||
str = str.replace(/class="(.*?)"/gi, (classStr, p1) => {
|
||||
return classStr.replace(p1, `${p1} lazyload`);
|
||||
})
|
||||
const url_for = require('hexo-util').url_for.bind(hexo)
|
||||
|
||||
function lazyProcess (htmlContent) {
|
||||
var bg = url_for(hexo.theme.config.lodding_bg.post)
|
||||
return htmlContent.replace(
|
||||
/<img(.*?)src="(.*?)"(.*?)>/gi,
|
||||
(str, p1, p2, p3) => {
|
||||
if (/data-src/gi.test(str)) {
|
||||
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}`)
|
||||
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) {
|
||||
if (!hexo.theme.config.lazyload.enable) return;
|
||||
data.content = lazyProcess.call(this, data.content);
|
||||
return data;
|
||||
};
|
||||
var processPost = function (data) {
|
||||
if (!hexo.theme.config.lazyload.enable) return
|
||||
data.content = lazyProcess.call(this, data.content)
|
||||
return data
|
||||
}
|
||||
|
||||
hexo.extend.filter.register('after_post_render', processPost);
|
||||
hexo.extend.filter.register('after_post_render', processPost)
|
||||
|
||||
@ -1,23 +1,34 @@
|
||||
hexo.extend.filter.register("before_post_render", function(data) {
|
||||
if (data.cover == false) {
|
||||
data.randomcover = random_cover();
|
||||
return data;
|
||||
}
|
||||
data.cover = data.cover || random_cover();
|
||||
return data;
|
||||
});
|
||||
/**
|
||||
* Butterfly
|
||||
* ramdom cover
|
||||
*/
|
||||
|
||||
var random_cover = function() {
|
||||
var cover;
|
||||
var num;
|
||||
if (!Array.isArray(hexo.theme.config.cover.default_cover)) {
|
||||
cover = hexo.theme.config.cover.default_cover;
|
||||
return cover;
|
||||
} else {
|
||||
num = Math.floor(
|
||||
Math.random() * hexo.theme.config.cover.default_cover.length
|
||||
);
|
||||
cover = hexo.theme.config.cover.default_cover[num];
|
||||
return cover;
|
||||
'use strict'
|
||||
|
||||
hexo.extend.filter.register('before_post_render', function (data) {
|
||||
if (data.cover === false) {
|
||||
data.randomcover = randomCover()
|
||||
return data
|
||||
}
|
||||
};
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,50 +1,55 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Butterfly
|
||||
* for aside archives
|
||||
*/
|
||||
|
||||
hexo.extend.helper.register("list_archives", function(options = {}) {
|
||||
const { config } = this;
|
||||
const archiveDir = config.archive_dir;
|
||||
const { timezone } = config;
|
||||
const lang = this.page.lang || this.page.language || config.language;
|
||||
let { format } = options;
|
||||
const type = options.type || "monthly";
|
||||
const { style = "list", transform, separator = ", " } = options;
|
||||
const showCount = Object.prototype.hasOwnProperty.call(options, "show_count")
|
||||
'use strict'
|
||||
|
||||
hexo.extend.helper.register('list_archives', function (options = {}) {
|
||||
const { config } = this
|
||||
const archiveDir = config.archive_dir
|
||||
const { timezone } = config
|
||||
const lang = this.page.lang || this.page.language || config.language
|
||||
let { format } = options
|
||||
const type = options.type || 'monthly'
|
||||
const { transform } = options
|
||||
const showCount = Object.prototype.hasOwnProperty.call(options, 'show_count')
|
||||
? options.show_count
|
||||
: true;
|
||||
const order = options.order || -1;
|
||||
const limit = 8;
|
||||
let result = "";
|
||||
: true
|
||||
const order = options.order || -1
|
||||
const limit = 8
|
||||
let result = ''
|
||||
|
||||
var more_button;
|
||||
if (lang === "zh-CN") {
|
||||
more_button = "查看更多";
|
||||
} else if (lang === "zh-TW") {
|
||||
more_button = "查看更多";
|
||||
var moreButton
|
||||
if (lang === 'zh-CN') {
|
||||
moreButton = '查看更多'
|
||||
} else if (lang === 'zh-TW') {
|
||||
moreButton = '查看更多'
|
||||
} else {
|
||||
more_button = "More";
|
||||
moreButton = 'More'
|
||||
}
|
||||
|
||||
if (!format) {
|
||||
format = type === "monthly" ? "MMMM YYYY" : "YYYY";
|
||||
format = type === 'monthly' ? 'MMMM YYYY' : 'YYYY'
|
||||
}
|
||||
|
||||
const posts = this.site.posts.sort("date", order);
|
||||
if (!posts.length) return result;
|
||||
const posts = this.site.posts.sort('date', order)
|
||||
if (!posts.length) return result
|
||||
|
||||
const data = [];
|
||||
let length = 0;
|
||||
const data = []
|
||||
let length = 0
|
||||
|
||||
posts.forEach(post => {
|
||||
// Clone the date object to avoid pollution
|
||||
let date = post.date.clone();
|
||||
let date = post.date.clone()
|
||||
|
||||
if (timezone) date = date.tz(timezone);
|
||||
if (lang) date = date.locale(lang);
|
||||
if (timezone) date = date.tz(timezone)
|
||||
if (lang) date = date.locale(lang)
|
||||
|
||||
const year = date.year();
|
||||
const month = date.month() + 1;
|
||||
const name = date.format(format);
|
||||
const lastData = data[length - 1];
|
||||
const year = date.year()
|
||||
const month = date.month() + 1
|
||||
const name = date.format(format)
|
||||
const lastData = data[length - 1]
|
||||
|
||||
if (!lastData || lastData.name !== name) {
|
||||
length = data.push({
|
||||
@ -52,52 +57,50 @@ hexo.extend.helper.register("list_archives", function(options = {}) {
|
||||
year,
|
||||
month,
|
||||
count: 1
|
||||
});
|
||||
})
|
||||
} else {
|
||||
lastData.count++;
|
||||
lastData.count++
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
const link = item => {
|
||||
let url = `${archiveDir}/${item.year}/`;
|
||||
let url = `${archiveDir}/${item.year}/`
|
||||
|
||||
if (type === "monthly") {
|
||||
if (item.month < 10) url += "0";
|
||||
url += `${item.month}/`;
|
||||
if (type === 'monthly') {
|
||||
if (item.month < 10) url += '0'
|
||||
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++) {
|
||||
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 += `<span class="archive-list-date">`;
|
||||
result += transform ? transform(item.name) : item.name;
|
||||
result += `</span>`;
|
||||
result += `<a class="archive-list-link" href="${link(item)}">`
|
||||
result += '<span class="archive-list-date">'
|
||||
result += transform ? transform(item.name) : item.name
|
||||
result += '</span>'
|
||||
|
||||
if (showCount) {
|
||||
result += `<span class="archive-list-count">${item.count}</span>`;
|
||||
result += `<span class="archive-list-count">${item.count}</span>`
|
||||
}
|
||||
result += "</a>";
|
||||
result += "</li>";
|
||||
result += '</a>'
|
||||
result += '</li>'
|
||||
}
|
||||
|
||||
if (data.length > limit) {
|
||||
result += `<li class="archive-list-item is-center">`;
|
||||
result += '<li class="archive-list-item is-center">'
|
||||
result +=
|
||||
`<a class="archive-list-link-more" href="` +
|
||||
"/" +
|
||||
`${archiveDir}" >`;
|
||||
result += more_button;
|
||||
result += "</a>";
|
||||
result += "</li>";
|
||||
'<a class="archive-list-link-more" href="' + '/' + `${archiveDir}" >`
|
||||
result += moreButton
|
||||
result += '</a>'
|
||||
result += '</li>'
|
||||
}
|
||||
result += "</ul>";
|
||||
return result;
|
||||
});
|
||||
result += '</ul>'
|
||||
return result
|
||||
})
|
||||
|
||||
@ -1,23 +1,24 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Butterfly
|
||||
* Generate js and css according to user setting
|
||||
*/
|
||||
|
||||
hexo.extend.helper.register("my_html", function(type, data) {
|
||||
var result = "";
|
||||
var tag = type === "css" ? "css" : "script";
|
||||
'use strict'
|
||||
|
||||
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++) {
|
||||
var src = data[i].split("||")[0].trim();
|
||||
var other = data[i].split("||")[1] ? data[i].split("||")[1].trim() : "";
|
||||
var src = data[i].split('||')[0].trim()
|
||||
var other = data[i].split('||')[1] ? data[i].split('||')[1].trim() : ''
|
||||
|
||||
if (tag === "css") {
|
||||
if (tag === 'css') {
|
||||
result +=
|
||||
'<link rel="stylesheet" href="' +
|
||||
this.url_for(src) +
|
||||
'" ' +
|
||||
other +
|
||||
">";
|
||||
'<link rel="stylesheet" href="' + this.url_for(src) + '" ' + other + '>'
|
||||
} else {
|
||||
result +=
|
||||
'<script src="' + this.url_for(src) + '" ' + other + "></script>";
|
||||
'<script src="' + this.url_for(src) + '" ' + other + '></script>'
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
return result
|
||||
})
|
||||
|
||||
@ -1,5 +1,13 @@
|
||||
/**
|
||||
* Butterfly
|
||||
* Related Posts
|
||||
* According the tag
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
||||
var relatedPosts = [];
|
||||
var relatedPosts = []
|
||||
currentPost.tags.forEach(function (tag) {
|
||||
allPosts.forEach(function (post) {
|
||||
if (isTagRelated(tag.name, post.tags)) {
|
||||
@ -11,80 +19,108 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
||||
weight: 1,
|
||||
updated: post.updated,
|
||||
created: post.date
|
||||
};
|
||||
var index = findItem(relatedPosts, 'path', post.path);
|
||||
if (index != -1) {
|
||||
relatedPosts[index].weight += 1;
|
||||
}
|
||||
var index = findItem(relatedPosts, 'path', post.path)
|
||||
if (index !== -1) {
|
||||
relatedPosts[index].weight += 1
|
||||
} else {
|
||||
if (currentPost.path != post.path) {
|
||||
relatedPosts.push(relatedPost);
|
||||
};
|
||||
};
|
||||
};
|
||||
});
|
||||
});
|
||||
if (relatedPosts.length == 0) {
|
||||
if (currentPost.path !== post.path) {
|
||||
relatedPosts.push(relatedPost)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
if (relatedPosts.length === 0) {
|
||||
return ''
|
||||
};
|
||||
var result = "";
|
||||
const hexoConfig = hexo.theme.config.rootConfig;
|
||||
const config = hexo.theme.config;
|
||||
}
|
||||
var result = ''
|
||||
const hexoConfig = hexo.theme.config.rootConfig
|
||||
const config = hexo.theme.config
|
||||
|
||||
var limit_num = config.related_post.limit || 6
|
||||
var date_type = config.related_post.date_type || 'created'
|
||||
var headline_lang = this._p('post.recommend')
|
||||
var limitNum = config.related_post.limit || 6
|
||||
var dateType = config.related_post.date_type || 'created'
|
||||
var headlineLang = this._p('post.recommend')
|
||||
var lazySrc = config.lazyload.enable ? 'data-src' : 'src'
|
||||
var lazyClass = config.lazyload.enable ? 'lazyload' : ''
|
||||
|
||||
relatedPosts = relatedPosts.sort(compare('weight'));
|
||||
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) {
|
||||
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">'
|
||||
|
||||
for (var i = 0; i < Math.min(relatedPosts.length, limit_num); i++) {
|
||||
var cover = relatedPosts[i].cover === false ? relatedPosts[i].randomcover : relatedPosts[i].cover
|
||||
result += '<div class="relatedPosts_item"><a href="' + hexoConfig.root + relatedPosts[i].path + '" title="' + relatedPosts[i].title + '">';
|
||||
result += '<img class="relatedPosts_cover ' + lazy_class + '"' + lazy_src + '="' + cover + '">';
|
||||
if (date_type == '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>'
|
||||
for (var i = 0; i < Math.min(relatedPosts.length, limitNum); i++) {
|
||||
var cover =
|
||||
relatedPosts[i].cover === false
|
||||
? relatedPosts[i].randomcover
|
||||
: relatedPosts[i].cover
|
||||
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 {
|
||||
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><div class="clear_both"></div></div>'
|
||||
return result;
|
||||
|
||||
return result
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
function isTagRelated(tagName, TBDtags) {
|
||||
var result = false;
|
||||
function isTagRelated (tagName, TBDtags) {
|
||||
var result = false
|
||||
TBDtags.forEach(function (tag) {
|
||||
if (tagName == tag.name) {
|
||||
result = true;
|
||||
};
|
||||
if (tagName === tag.name) {
|
||||
result = true
|
||||
}
|
||||
})
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
function findItem(arrayToSearch, attr, val) {
|
||||
function findItem (arrayToSearch, attr, val) {
|
||||
for (var i = 0; i < arrayToSearch.length; i++) {
|
||||
if (arrayToSearch[i][attr] == val) {
|
||||
if (arrayToSearch[i][attr] === val) {
|
||||
return i
|
||||
};
|
||||
};
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
function compare(attr) {
|
||||
function compare (attr) {
|
||||
return function (a, b) {
|
||||
var val1 = a[attr];
|
||||
var val2 = b[attr];
|
||||
return val2 - val1;
|
||||
var val1 = a[attr]
|
||||
var val2 = b[attr]
|
||||
return val2 - val1
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,18 @@
|
||||
const url_for = require('hexo-util').url_for.bind(hexo);
|
||||
/**
|
||||
* Butterfly
|
||||
* galleryGroup and allery
|
||||
*/
|
||||
|
||||
function gallery(args, content) {
|
||||
return `<div class="justified-gallery">${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')}
|
||||
</div>`;
|
||||
'use strict'
|
||||
|
||||
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 desrc = args[1]
|
||||
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('galleryGroup', galleryGroup);
|
||||
hexo.extend.tag.register('gallery', gallery, { ends: true })
|
||||
hexo.extend.tag.register('galleryGroup', galleryGroup)
|
||||
|
||||
@ -1,33 +1,35 @@
|
||||
|
||||
/**
|
||||
* {% hideInline content,display,bg,color %}
|
||||
* content不能包含當引號,可用 '
|
||||
* Butterfly
|
||||
* hideInline
|
||||
* {% hideInline content,display,bg,color %}
|
||||
* content不能包含當引號,可用 '
|
||||
* hideBlock
|
||||
* {% hideBlock display,bg,color %}
|
||||
* content
|
||||
* {% endhideBlock %}
|
||||
*/
|
||||
function hideInline(args) {
|
||||
|
||||
'use strict'
|
||||
|
||||
function hideInline (args) {
|
||||
args = args.join(' ').split(',')
|
||||
let content = args[0].trim()
|
||||
let display = args[1] || 'Click'
|
||||
let bg = args[2] ==='' || typeof args[2] ==='undefined' ? '' : `background-color:${args[2]}`
|
||||
let color = args[3] || '#fff'
|
||||
return `<span class="hide-inline"><a class="hide-button button--primary button--animated" style="color:${color};${bg}">${display}
|
||||
const content = args[0].trim()
|
||||
const display = args[1] || 'Click'
|
||||
const bg = args[2] === '' || typeof args[2] === 'undefined' ? '' : `background-color:${args[2]}`
|
||||
const color = args[3] || '#fff'
|
||||
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>`
|
||||
}
|
||||
|
||||
/**
|
||||
* {% hideBlock display,bg,color %}
|
||||
* content
|
||||
* {% endhideBlock %}
|
||||
*/
|
||||
function hideBlock(args,content) {
|
||||
function hideBlock (args, content) {
|
||||
args = args.join(' ').split(',')
|
||||
let display = args[0] || 'Click'
|
||||
let bg = args[1] ==='' || typeof args[2] ==='undefined' ? '' : `background-color:${args[2]}`
|
||||
let 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>`
|
||||
const display = args[0] || 'Click'
|
||||
const bg = args[1] === '' || typeof args[2] === 'undefined' ? '' : `background-color:${args[2]}`
|
||||
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>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('hideInline', hideInline);
|
||||
hexo.extend.tag.register('hideBlock', hideBlock, {ends: true});
|
||||
hexo.extend.tag.register('hideInline', hideInline)
|
||||
hexo.extend.tag.register('hideBlock', hideBlock, { ends: true })
|
||||
|
||||
@ -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">
|
||||
${content}
|
||||
</div>`;
|
||||
</div>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('mermaid', mermaid, {ends: true});
|
||||
hexo.extend.tag.register('mermaid', mermaid, { ends: true })
|
||||
|
||||
@ -3,13 +3,13 @@
|
||||
* transplant from hexo-theme-next
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
function postNote(args, content) {
|
||||
function postNote (args, content) {
|
||||
return `<div class="note ${args.join(' ')}">
|
||||
${hexo.render.renderSync({text: content, engine: 'markdown'}).split('\n').join('')}
|
||||
</div>`;
|
||||
${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')}
|
||||
</div>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('note', postNote, {ends: true});
|
||||
hexo.extend.tag.register('subnote', postNote, {ends: true});
|
||||
hexo.extend.tag.register('note', postNote, { ends: true })
|
||||
hexo.extend.tag.register('subnote', postNote, { ends: true })
|
||||
|
||||
@ -244,12 +244,10 @@ img:not([src])
|
||||
|
||||
.post-ad
|
||||
margin: 2rem 0
|
||||
overflow-x: scroll
|
||||
|
||||
.ad_height
|
||||
display: block !important
|
||||
height: auto !important
|
||||
overflow-x: scroll !important
|
||||
|
||||
#content-inner,
|
||||
#footer
|
||||
@ -262,10 +260,13 @@ img:not([src])
|
||||
#site_subtitle
|
||||
animation: titlescale 1s
|
||||
|
||||
canvas,
|
||||
canvas:not(#ribbon-canvas),
|
||||
#web_bg
|
||||
animation: to_show 4s
|
||||
|
||||
#ribbon-canvas
|
||||
animation: ribbon_to_show 4s
|
||||
|
||||
.card-announcement-animation
|
||||
color: #FF0000
|
||||
animation: announ_animation .8s linear infinite
|
||||
@ -363,6 +364,13 @@ if hexo-config('avatar.effect') == true
|
||||
100%
|
||||
opacity: 1
|
||||
|
||||
@keyframes ribbon_to_show
|
||||
0%
|
||||
opacity: 0
|
||||
|
||||
100%
|
||||
opacity: hexo-config('canvas_ribbon.alpha')
|
||||
|
||||
@keyframes avatar_turn_around
|
||||
from
|
||||
transform: rotate(0)
|
||||
|
||||
@ -312,3 +312,8 @@
|
||||
.post-meta-pv-cv
|
||||
.post-meta__separator:first-child
|
||||
display: none
|
||||
|
||||
if !hexo-config('busuanzi.page_pv')
|
||||
.post-meta-commentcount
|
||||
.post-meta__separator
|
||||
display: none
|
||||
114
source/js/third-party/canvas-ribbon.js
vendored
114
source/js/third-party/canvas-ribbon.js
vendored
@ -5,31 +5,32 @@
|
||||
* GitHub: https://github.com/hustcc/ribbon.js
|
||||
**/
|
||||
|
||||
!(function () {
|
||||
|
||||
var script = document.getElementById('ribbon');
|
||||
!(function() {
|
||||
var script = document.getElementById("ribbon");
|
||||
var mb = script.getAttribute("mobile");
|
||||
if (mb == 'false' && (/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent))) {
|
||||
if (
|
||||
mb == "false" &&
|
||||
/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
config = {
|
||||
z: attr(script, 'zIndex', -1), // z-index
|
||||
a: attr(script, 'alpha', 0.6), // alpha
|
||||
s: attr(script, 'size', 90), // size
|
||||
c: attr(script, 'data-click', true) // click-to-change
|
||||
}
|
||||
z: attr(script, "zIndex", -1), // z-index
|
||||
a: attr(script, "alpha", 0.6), // alpha
|
||||
s: attr(script, "size", 90), // size
|
||||
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) {
|
||||
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'),
|
||||
g2d = canvas.getContext('2d'),
|
||||
var canvas = document.createElement("canvas"),
|
||||
g2d = canvas.getContext("2d"),
|
||||
pr = window.devicePixelRatio || 1,
|
||||
width = window.innerWidth,
|
||||
height = window.innerHeight,
|
||||
@ -40,52 +41,67 @@
|
||||
r = 0,
|
||||
pi = m.PI * 2,
|
||||
cos = m.cos,
|
||||
random = m.random
|
||||
canvas.width = width * pr
|
||||
canvas.height = height * pr
|
||||
g2d.scale(pr, pr)
|
||||
g2d.globalAlpha = config.a
|
||||
random = m.random;
|
||||
canvas.id = "ribbon-canvas";
|
||||
canvas.width = width * pr;
|
||||
canvas.height = height * pr;
|
||||
g2d.scale(pr, pr);
|
||||
g2d.globalAlpha = config.a;
|
||||
canvas.style.cssText =
|
||||
'opacity: ' +
|
||||
"opacity: " +
|
||||
config.a +
|
||||
';position:fixed;top:0;left:0;z-index: ' +
|
||||
";position:fixed;top:0;left:0;z-index: " +
|
||||
config.z +
|
||||
';width:100%;height:100%;pointer-events:none;'
|
||||
";width:100%;height:100%;pointer-events:none;";
|
||||
// create canvas
|
||||
document.getElementsByTagName('body')[0].appendChild(canvas)
|
||||
document.getElementsByTagName("body")[0].appendChild(canvas);
|
||||
|
||||
function redraw () {
|
||||
g2d.clearRect(0, 0, width, height)
|
||||
q = [{ 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 redraw() {
|
||||
g2d.clearRect(0, 0, width, height);
|
||||
q = [
|
||||
{
|
||||
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()
|
||||
g2d.moveTo(i.x, i.y)
|
||||
g2d.lineTo(j.x, j.y)
|
||||
|
||||
function draw(i, j) {
|
||||
g2d.beginPath();
|
||||
g2d.moveTo(i.x, i.y);
|
||||
g2d.lineTo(j.x, j.y);
|
||||
var k = j.x + (random() * 2 - 0.25) * f,
|
||||
n = line(j.y)
|
||||
g2d.lineTo(k, n)
|
||||
g2d.closePath()
|
||||
r -= pi / -50
|
||||
n = line(j.y);
|
||||
g2d.lineTo(k, n);
|
||||
g2d.closePath();
|
||||
r -= pi / -50;
|
||||
g2d.fillStyle =
|
||||
'#' +
|
||||
"#" +
|
||||
(
|
||||
((cos(r) * 127 + 128) << 16) |
|
||||
((cos(r + pi / 3) * 127 + 128) << 8) |
|
||||
(cos(r + (pi / 3) * 2) * 127 + 128)
|
||||
).toString(16)
|
||||
g2d.fill()
|
||||
q[0] = q[1]
|
||||
q[1] = { x: k, y: n }
|
||||
).toString(16);
|
||||
g2d.fill();
|
||||
q[0] = q[1];
|
||||
q[1] = {
|
||||
x: k,
|
||||
y: n
|
||||
};
|
||||
}
|
||||
function line (p) {
|
||||
t = p + (random() * 2 - 1.1) * f
|
||||
return t > height || t < 0 ? line(p) : t
|
||||
|
||||
function line(p) {
|
||||
t = p + (random() * 2 - 1.1) * f;
|
||||
return t > height || t < 0 ? line(p) : t;
|
||||
}
|
||||
if (config.c !== 'false') {
|
||||
document.onclick = redraw
|
||||
document.ontouchstart = redraw
|
||||
if (config.c !== "false") {
|
||||
document.onclick = redraw;
|
||||
document.ontouchstart = redraw;
|
||||
}
|
||||
redraw()
|
||||
})()
|
||||
redraw();
|
||||
})();
|
||||
|
||||
@ -48,10 +48,10 @@ function throttle (func, wait, options) {
|
||||
return throttled
|
||||
}
|
||||
|
||||
function sidebarPaddingR() {
|
||||
let innerWidth = window.innerWidth
|
||||
let clientWidth = document.body.clientWidth
|
||||
let paddingRight = innerWidth - clientWidth
|
||||
function sidebarPaddingR () {
|
||||
var innerWidth = window.innerWidth
|
||||
var clientWidth = document.body.clientWidth
|
||||
var paddingRight = innerWidth - clientWidth
|
||||
if (innerWidth !== clientWidth) {
|
||||
$('body').css('padding-right', paddingRight)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user