diff --git a/layout/404.pug b/layout/404.pug
index 4dc3c92..73d6f37 100644
--- a/layout/404.pug
+++ b/layout/404.pug
@@ -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
diff --git a/layout/includes/header/post-info.pug b/layout/includes/header/post-info.pug
index 9f7a011..3964283 100644
--- a/layout/includes/header/post-info.pug
+++ b/layout/includes/header/post-info.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') + ':'
diff --git a/scripts/events/404.js b/scripts/events/404.js
index e091744..c37daae 100644
--- a/scripts/events/404.js
+++ b/scripts/events/404.js
@@ -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']
}
-});
\ No newline at end of file
+})
diff --git a/scripts/events/replace-config.js b/scripts/events/replace-config.js
index 7d7612d..77b7786 100644
--- a/scripts/events/replace-config.js
+++ b/scripts/events/replace-config.js
@@ -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) {
@@ -9,4 +11,4 @@ hexo.on('generateBefore', function () {
data && data.butterfly && (hexo.theme.config = data.butterfly)
}
hexo.theme.config.rootConfig = rootConfig
-})
\ No newline at end of file
+})
diff --git a/scripts/filters/hide-post.js b/scripts/filters/hide-post.js
index 7ce8f84..94703b4 100644
--- a/scripts/filters/hide-post.js
+++ b/scripts/filters/hide-post.js
@@ -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)
+ )
+ })
)
- }));
- });
- });
-});
\ No newline at end of file
+ })
+ })
+})
diff --git a/scripts/filters/post-lazyload.js b/scripts/filters/post-lazyload.js
index c0a6624..c1cab31 100644
--- a/scripts/filters/post-lazyload.js
+++ b/scripts/filters/post-lazyload.js
@@ -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(//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(
+ /
/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);
\ No newline at end of file
+hexo.extend.filter.register('after_post_render', processPost)
diff --git a/scripts/filters/random-cover.js b/scripts/filters/random-cover.js
index f660df1..5806921 100644
--- a/scripts/filters/random-cover.js
+++ b/scripts/filters/random-cover.js
@@ -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
+ }
+}
diff --git a/scripts/helpers/list-archives.js b/scripts/helpers/list-archives.js
index 534d4fe..9ad40e4 100644
--- a/scripts/helpers/list-archives.js
+++ b/scripts/helpers/list-archives.js
@@ -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 += `