mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 18:40:53 +08:00
🐛 修復POST-META關閉閲讀分鐘和訪問量後,評論量前有分割線的bug
🐛 修復canvas_ribbon透明度變為1再變回預設值bug 🐛 修復當default_cover沒設置時,會出現無圖片的bug 🎨 部分js調整
This commit is contained in:
@@ -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')
|
||||
|
||||
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 = ''
|
||||
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'))
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user