🏷️ 2.3.0發佈

This commit is contained in:
Jerry
2020-04-26 23:29:38 +08:00
Unverified
parent 796b8e6df4
commit 0d56db50e4
16 changed files with 127 additions and 87 deletions

View File

@@ -6,7 +6,10 @@
'use strict'
hexo.extend.helper.register('aside_categories', function (categories, options) {
if (!options && (!categories || !Object.prototype.hasOwnProperty.call(categories, 'length'))) {
if (
!options &&
(!categories || !Object.prototype.hasOwnProperty.call(categories, 'length'))
) {
options = categories
categories = this.site.categories
}
@@ -14,23 +17,28 @@ hexo.extend.helper.register('aside_categories', function (categories, options) {
if (!categories || !categories.length) return ''
options = options || {}
const { config } = this
const showCount = Object.prototype.hasOwnProperty.call(options, 'show_count') ? options.show_count : true
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 prepareQuery = (parent) => {
const query = {}
if (parent) {
query.parent = parent
} else {
query.parent = {
$exists: false
$exists: false,
}
}
return categories.find(query).sort(orderby, order).filter(cat => cat.length)
return categories
.find(query)
.sort(orderby, order)
.filter((cat) => cat.length)
}
const hierarchicalList = (t, level, parent) => {
@@ -46,20 +54,22 @@ hexo.extend.helper.register('aside_categories', function (categories, options) {
t = childList[1]
}
result += '<li class="aside-category-list-item">'
result += '<li class="card-category-list-item">'
result += `<a class="aside-category-list-link" href="${this.url_for(cat.path)}">`
result += `<span class="aside-category-list-name">${cat.name}</span>`
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="aside-category-list-count">${cat.length}</span>`
result += `<span class="card-category-list-count">${cat.length}</span>`
}
result += '</a>'
result += '</li>'
if (child) {
result += `<ul class="aside-category-list child">${child}</ul>`
result += `<ul class="card-category-list child">${child}</ul>`
}
}
})
@@ -73,14 +83,14 @@ hexo.extend.helper.register('aside_categories', function (categories, options) {
var moreButton = function () {
var moreHtml = ''
if (categories.length <= limit) return ''
moreHtml += '<li class="aside-category-list-item is-center">'
moreHtml += `<a class="aside-category-list-item-more" href="${categoryDir}" >`
moreHtml += buttonLabel
moreHtml += '</a></li>'
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="aside-category-list">
return `<ul class="card-category-list">
${list[0]}
${moreButton()}
</ul>`