🏷️ 更新至3.0.0-RC-1 close #189, close #192, close #223, close #224, close #229, close 232, close #240

This commit is contained in:
Jerry
2020-06-16 18:37:22 +08:00
Unverified
parent 0ad2c01fc9
commit aa8c509b96
93 changed files with 2109 additions and 1648 deletions

View File

@@ -6,9 +6,7 @@
'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
@@ -25,47 +23,48 @@ hexo.extend.helper.register('aside_categories', function (categories, options) {
const order = options.order || 1
const categoryDir = this.url_for(config.category_dir)
const limit = options.limit === 0 ? categories.length : options.limit
const isExpand = options.expand !== 'none'
const expandClass = isExpand && options.expand === true ? 'card-category-list-icon expand' : 'card-category-list-icon'
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)
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) => {
const hierarchicalList = (t, level, parent, topparent = true) => {
let result = ''
var isTopParent = topparent
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)
var childList = hierarchicalList(t, level + 1, cat._id, false)
child = childList[0]
t = childList[1]
}
result += '<li class="card-category-list-item">'
var parentClass = isExpand && isTopParent && child ? 'parent' : ''
result += `<li class="card-category-list-item ${parentClass}">`
result += `<a class="card-category-list-link" href="${this.url_for(cat.path)}">`
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>`
}
if (isExpand && isTopParent && child) {
result += `<i class="fas fa-caret-left ${expandClass}"></i>`
}
result += '</a>'
result += '</li>'
if (child) {
@@ -85,7 +84,7 @@ hexo.extend.helper.register('aside_categories', function (categories, options) {
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>`
<span>${buttonLabel}</span><i class="fas fa-angle-right"></i></a></li>`
return moreHtml
}