mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:30:53 +08:00
🏷️ 2.3.0發佈
This commit is contained in:
@@ -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) {
|
||||
@@ -9,4 +11,4 @@ hexo.on('generateBefore', function () {
|
||||
data && data.butterfly && (hexo.theme.config = data.butterfly)
|
||||
}
|
||||
hexo.theme.config.rootConfig = rootConfig
|
||||
})
|
||||
})
|
||||
@@ -1,63 +0,0 @@
|
||||
/**
|
||||
* global hexo
|
||||
* from printempw/hexo-hide-posts
|
||||
* modify by Jerry
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var public_generators = [];
|
||||
|
||||
hexo.extend.filter.register('before_generate', function () {
|
||||
this._bindLocals();
|
||||
|
||||
const all_posts = this.locals.get('posts');
|
||||
const hidden_posts = all_posts.find({
|
||||
'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);
|
||||
});
|
||||
|
||||
hexo.extend.filter.register('after_init', function () {
|
||||
|
||||
const original = {};
|
||||
for (const name in hexo.extend.generator.list()) {
|
||||
original[name] = hexo.extend.generator.get(name);
|
||||
}
|
||||
|
||||
hexo.extend.generator.register('post', async function (locals) {
|
||||
const fg = original.post.bind(this);
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
return fg(Object.assign({}, locals, {
|
||||
posts: new locals.posts.constructor(
|
||||
locals.posts.data.concat(locals.hidden_posts.data)
|
||||
)
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
39
scripts/filters/post_lazyload.js
Normal file
39
scripts/filters/post_lazyload.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Butterfly
|
||||
* lazyload
|
||||
* replace src to data-src
|
||||
* add class 'lazyload'
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
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(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
|
||||
}
|
||||
|
||||
hexo.extend.filter.register('after_post_render', processPost)
|
||||
@@ -1,23 +0,0 @@
|
||||
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;
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
34
scripts/filters/random_cover.js
Normal file
34
scripts/filters/random_cover.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Butterfly
|
||||
* ramdom 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
|
||||
}
|
||||
}
|
||||
112
scripts/helpers/aside_archives.js
Normal file
112
scripts/helpers/aside_archives.js
Normal file
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* Butterfly
|
||||
* for aside archives
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
hexo.extend.helper.register('aside_archives', function (options = {}) {
|
||||
const { config } = this
|
||||
const archiveDir = config.archive_dir
|
||||
const { timezone } = config
|
||||
const lang = toMomentLocale(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 compareFunc = type === 'monthly'
|
||||
? (yearA, monthA, yearB, monthB) => yearA === yearB && monthA === monthB
|
||||
: (yearA, monthA, yearB, monthB) => yearA === yearB
|
||||
const limit = options.limit
|
||||
const moreButton = this._p('aside.more_button')
|
||||
let result = ''
|
||||
|
||||
if (!format) {
|
||||
format = type === 'monthly' ? 'MMMM YYYY' : 'YYYY'
|
||||
}
|
||||
|
||||
const posts = this.site.posts.sort('date', order)
|
||||
if (!posts.length) return result
|
||||
|
||||
const data = []
|
||||
let length = 0
|
||||
|
||||
posts.forEach(post => {
|
||||
// Clone the date object to avoid pollution
|
||||
let date = post.date.clone()
|
||||
|
||||
if (timezone) date = date.tz(timezone)
|
||||
|
||||
const year = date.year()
|
||||
const month = date.month() + 1
|
||||
const lastData = data[length - 1]
|
||||
|
||||
if (!lastData || !compareFunc(lastData.year, lastData.month, year, month)) {
|
||||
if (lang) date = date.locale(lang)
|
||||
const name = date.format(format)
|
||||
length = data.push({
|
||||
name,
|
||||
year,
|
||||
month,
|
||||
count: 1
|
||||
})
|
||||
} else {
|
||||
lastData.count++
|
||||
}
|
||||
})
|
||||
|
||||
const link = item => {
|
||||
let url = `${archiveDir}/${item.year}/`
|
||||
|
||||
if (type === 'monthly') {
|
||||
if (item.month < 10) url += '0'
|
||||
url += `${item.month}/`
|
||||
}
|
||||
|
||||
return this.url_for(url)
|
||||
}
|
||||
|
||||
result += '<ul class="card-archive-list">'
|
||||
|
||||
const len = data.length
|
||||
const Judge = limit === 0 ? len : Math.min(len, limit)
|
||||
|
||||
for (let i = 0; i < Judge; i++) {
|
||||
const item = data[i]
|
||||
|
||||
result += '<li class="card-archive-list-item">'
|
||||
|
||||
result += `<a class="card-archive-list-link" href="${link(item)}">`
|
||||
result += '<span class="card-archive-list-date">'
|
||||
result += transform ? transform(item.name) : item.name
|
||||
result += '</span>'
|
||||
|
||||
if (showCount) {
|
||||
result += `<span class="card-archive-list-count">${item.count}</span>`
|
||||
}
|
||||
result += '</a>'
|
||||
result += '</li>'
|
||||
}
|
||||
|
||||
if (len > Judge) {
|
||||
result += '<li class="card-archive-list-item more is-center">'
|
||||
result += `<a class="card-archive-list-link-more" href="${this.url_for(archiveDir)}">
|
||||
<span>${moreButton}</span><i class="fa fa-angle-right" aria-hidden="true"></i></a></li>`
|
||||
}
|
||||
result += '</ul>'
|
||||
return result
|
||||
})
|
||||
|
||||
var toMomentLocale = function (lang) {
|
||||
if (lang === undefined) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
// moment.locale('') equals moment.locale('en')
|
||||
// moment.locale(null) equals moment.locale('en')
|
||||
if (!lang || lang === 'en' || lang === 'default') {
|
||||
return 'en'
|
||||
}
|
||||
return lang.toLowerCase().replace('_', '-')
|
||||
}
|
||||
97
scripts/helpers/aside_categories.js
Normal file
97
scripts/helpers/aside_categories.js
Normal file
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Butterfly
|
||||
* for aside categories
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
hexo.extend.helper.register('aside_categories', function (categories, options) {
|
||||
if (
|
||||
!options &&
|
||||
(!categories || !Object.prototype.hasOwnProperty.call(categories, 'length'))
|
||||
) {
|
||||
options = categories
|
||||
categories = this.site.categories
|
||||
}
|
||||
|
||||
if (!categories || !categories.length) return ''
|
||||
options = options || {}
|
||||
const { config } = this
|
||||
const showCount = Object.prototype.hasOwnProperty.call(options, 'show_count')
|
||||
? options.show_count
|
||||
: true
|
||||
const depth = options.depth ? parseInt(options.depth, 10) : 0
|
||||
const orderby = options.orderby || 'name'
|
||||
const order = options.order || 1
|
||||
const categoryDir = this.url_for(config.category_dir)
|
||||
const limit = options.limit === 0 ? categories.length : options.limit
|
||||
const buttonLabel = this._p('aside.more_button')
|
||||
const prepareQuery = (parent) => {
|
||||
const query = {}
|
||||
if (parent) {
|
||||
query.parent = parent
|
||||
} else {
|
||||
query.parent = {
|
||||
$exists: false,
|
||||
}
|
||||
}
|
||||
return categories
|
||||
.find(query)
|
||||
.sort(orderby, order)
|
||||
.filter((cat) => cat.length)
|
||||
}
|
||||
|
||||
const hierarchicalList = (t, level, parent) => {
|
||||
let result = ''
|
||||
if (t > 0) {
|
||||
prepareQuery(parent).forEach((cat, i) => {
|
||||
if (t > 0) {
|
||||
t = t - 1
|
||||
let child
|
||||
if (!depth || level + 1 < depth) {
|
||||
var childList = hierarchicalList(t, level + 1, cat._id)
|
||||
child = childList[0]
|
||||
t = childList[1]
|
||||
}
|
||||
|
||||
result += '<li class="card-category-list-item">'
|
||||
|
||||
result += `<a class="card-category-list-link" href="${this.url_for(
|
||||
cat.path
|
||||
)}">`
|
||||
result += `<span class="card-category-list-name">${cat.name}</span>`
|
||||
|
||||
if (showCount) {
|
||||
result += `<span class="card-category-list-count">${cat.length}</span>`
|
||||
}
|
||||
|
||||
result += '</a>'
|
||||
result += '</li>'
|
||||
|
||||
if (child) {
|
||||
result += `<ul class="card-category-list child">${child}</ul>`
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return [result, t]
|
||||
}
|
||||
|
||||
const list = hierarchicalList(limit, 0)
|
||||
|
||||
var moreButton = function () {
|
||||
var moreHtml = ''
|
||||
if (categories.length <= limit) return ''
|
||||
moreHtml += '<li class="card-category-list-item more is-center">'
|
||||
moreHtml += `<a class="card-category-list-link-more" href="${categoryDir}">
|
||||
<span>${buttonLabel}</span><i class="fa fa-angle-right" aria-hidden="true"></i></a></li>`
|
||||
|
||||
return moreHtml
|
||||
}
|
||||
|
||||
return `<ul class="card-category-list">
|
||||
${list[0]}
|
||||
${moreButton()}
|
||||
</ul>`
|
||||
})
|
||||
58
scripts/helpers/page.js
Normal file
58
scripts/helpers/page.js
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Butterfly
|
||||
* @example
|
||||
* page_description()
|
||||
* injectHtml(data)
|
||||
* cloudTags(source, minfontsize, maxfontsize, limit)
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const { stripHTML } = require('hexo-util')
|
||||
|
||||
hexo.extend.helper.register('page_description', function () {
|
||||
const { config, page } = this
|
||||
let description = page.description || page.content || page.title || config.description
|
||||
|
||||
if (description) {
|
||||
description = stripHTML(description).substring(0, 200)
|
||||
.trim()
|
||||
.replace(/\n/g, ' ')
|
||||
return description
|
||||
}
|
||||
})
|
||||
|
||||
hexo.extend.helper.register('injectHtml', function (data) {
|
||||
let result = ''
|
||||
if (!data) return ''
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
result += data[i]
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
||||
hexo.extend.helper.register('cloudTags', function (options = {}) {
|
||||
const env = this
|
||||
const source = options.source
|
||||
const minfontsize = options.minfontsize
|
||||
const maxfontsize = options.maxfontsize
|
||||
const limit = options.limit || 8
|
||||
|
||||
let result = ''
|
||||
const tagLimit = limit === 0 ? source.length : limit
|
||||
source.sort('name').limit(tagLimit).forEach(function (tags) {
|
||||
var fontSize = Math.floor(Math.random() * (maxfontsize - minfontsize) + minfontsize) + 'px'
|
||||
var color = 'rgb(' + Math.floor(Math.random() * 201) + ', ' + Math.floor(Math.random() * 201) + ', ' + Math.floor(Math.random() * 201) + ')' // 0,0,0 -> 200,200,200
|
||||
result += `<a href='${env.url_for(tags.path)}' style='font-size:${fontSize}; color:${color}'>${tags.name}</a>`
|
||||
})
|
||||
return result
|
||||
})
|
||||
|
||||
hexo.extend.helper.register('urlNoIndex', function () {
|
||||
const { permalink } = hexo.config
|
||||
let url = this.url.replace(/index\.html$/, '')
|
||||
if (!permalink.endsWith('.html')) {
|
||||
url = url.replace(/\.html$/, '')
|
||||
}
|
||||
return url
|
||||
})
|
||||
@@ -1,90 +0,0 @@
|
||||
hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
||||
var relatedPosts = [];
|
||||
currentPost.tags.forEach(function (tag) {
|
||||
allPosts.forEach(function (post) {
|
||||
if (isTagRelated(tag.name, post.tags)) {
|
||||
var relatedPost = {
|
||||
title: post.title,
|
||||
path: post.path,
|
||||
cover: post.cover,
|
||||
randomcover: post.randomcover,
|
||||
weight: 1,
|
||||
updated: post.updated,
|
||||
created: post.date
|
||||
};
|
||||
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) {
|
||||
return ''
|
||||
};
|
||||
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 = ''
|
||||
|
||||
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_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>'
|
||||
} 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_title">' + relatedPosts[i].title + '</div>';
|
||||
result += '</div></a></div>'
|
||||
};
|
||||
|
||||
result += '</div><div class="clear_both"></div></div>'
|
||||
return result;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function isTagRelated(tagName, TBDtags) {
|
||||
var result = false;
|
||||
TBDtags.forEach(function (tag) {
|
||||
if (tagName == tag.name) {
|
||||
result = true;
|
||||
};
|
||||
})
|
||||
return result;
|
||||
}
|
||||
|
||||
function findItem(arrayToSearch, attr, val) {
|
||||
for (var i = 0; i < arrayToSearch.length; i++) {
|
||||
if (arrayToSearch[i][attr] == val) {
|
||||
return i
|
||||
};
|
||||
};
|
||||
return -1;
|
||||
}
|
||||
|
||||
function compare(attr) {
|
||||
return function (a, b) {
|
||||
var val1 = a[attr];
|
||||
var val2 = b[attr];
|
||||
return val2 - val1;
|
||||
}
|
||||
}
|
||||
126
scripts/helpers/related_post.js
Normal file
126
scripts/helpers/related_post.js
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* Butterfly
|
||||
* Related Posts
|
||||
* According the tag
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
||||
var relatedPosts = []
|
||||
currentPost.tags.forEach(function (tag) {
|
||||
allPosts.forEach(function (post) {
|
||||
if (isTagRelated(tag.name, post.tags)) {
|
||||
var relatedPost = {
|
||||
title: post.title,
|
||||
path: post.path,
|
||||
cover: post.cover,
|
||||
randomcover: post.randomcover,
|
||||
weight: 1,
|
||||
updated: post.updated,
|
||||
created: post.date
|
||||
}
|
||||
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) {
|
||||
return ''
|
||||
}
|
||||
var result = ''
|
||||
const hexoConfig = hexo.theme.config.rootConfig
|
||||
const config = hexo.theme.config
|
||||
|
||||
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>' +
|
||||
' ' +
|
||||
headlineLang +
|
||||
'</span></div>'
|
||||
result += '<div class="relatedPosts_list">'
|
||||
|
||||
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_title">' + relatedPosts[i].title + '</div>'
|
||||
result += '</div></a></div>'
|
||||
}
|
||||
|
||||
result += '</div><div class="clear_both"></div></div>'
|
||||
return result
|
||||
}
|
||||
})
|
||||
|
||||
function isTagRelated (tagName, TBDtags) {
|
||||
var result = false
|
||||
TBDtags.forEach(function (tag) {
|
||||
if (tagName === tag.name) {
|
||||
result = true
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
function findItem (arrayToSearch, attr, val) {
|
||||
for (var i = 0; i < arrayToSearch.length; i++) {
|
||||
if (arrayToSearch[i][attr] === val) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
function compare (attr) {
|
||||
return function (a, b) {
|
||||
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,71 @@
|
||||
|
||||
/**
|
||||
* {% hideInline content,display,bg,color %}
|
||||
* content不能包含當引號,可用 '
|
||||
* Butterfly
|
||||
* @example
|
||||
* hideInline
|
||||
* {% hideInline content,display,bg,color %}
|
||||
* content不能包含當引號,可用 '
|
||||
* hideBlock
|
||||
* {% hideBlock display,bg,color %}
|
||||
* content
|
||||
* {% endhideBlock %}
|
||||
* hideToggle
|
||||
* {% hideToggle display,bg,color %}
|
||||
* content
|
||||
* {% endhideToggle %}
|
||||
*/
|
||||
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}
|
||||
</a><span class="hide-content">${content}</span></span>`
|
||||
var content = args[0]
|
||||
var display = args[1] || 'Click'
|
||||
var bg = args[2] || false
|
||||
var color = args[3] || false
|
||||
var group = 'style="'
|
||||
|
||||
if (bg) group += `background-color: ${bg};`
|
||||
if (color) group += `color: ${color}`
|
||||
group += '"'
|
||||
|
||||
return `<span class="hide-inline"><a class="hide-button button--primary button--animated" ${group}>${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'
|
||||
var display = args[0] || 'Click'
|
||||
var bg = args[1] || false
|
||||
var color = args[2] || false
|
||||
var group = 'style="'
|
||||
|
||||
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>`
|
||||
if (bg) group += `background-color: ${bg};`
|
||||
if (color) group += `color: ${color}`
|
||||
group += '"'
|
||||
|
||||
return `<div class="hide-block"><a class="hide-button button--primary button--animated" ${group}>${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});
|
||||
function hideToggle (args, content) {
|
||||
args = args.join(' ').split(',')
|
||||
var display = args[0]
|
||||
var bg = args[1] || false
|
||||
var color = args[2] || false
|
||||
var group = 'style="'
|
||||
var border = ''
|
||||
|
||||
if (bg) {
|
||||
border = `style="border: 1px solid ${bg}"`
|
||||
group += `background-color: ${bg};`
|
||||
}
|
||||
if (color) group += `color: ${color}`
|
||||
group += '"'
|
||||
|
||||
return `<div class="hide-toggle" ${border}><div class="hide-button toggle-title" ${group}><i class="fa fa-caret-right fa-fw"></i><span>${display}</span></div>
|
||||
<div class="hide-content">${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')}</div></div>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('hideInline', hideInline)
|
||||
hexo.extend.tag.register('hideBlock', hideBlock, { ends: true })
|
||||
hexo.extend.tag.register('hideToggle', hideToggle, { 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 })
|
||||
|
||||
Reference in New Issue
Block a user