hexo-theme-butterfly/scripts/helpers/page.js
Jerry b512eb761d feat: 增加標籤外掛 tag-toggle
 feat: 增加頁面加載動畫preloader close #193
 feat: 適配hexo-generator-indexed插件
 feat: aside subtitle可配置,優先顯示配置內容、沒有的顯示頁面subtitle close #191
 feat: aside card-tags可配置是否顯示顏色
 feat: algolia-search highligh文字加深
 feat: 增加頁面keywords設置 #191
 feat: darkmode和readmode配色微調
🐛 fix: 修復hide-block 配置顏色顯示出錯的bug
🐛 fix: 修正zh-TW部分用語
2020-04-17 19:48:07 +08:00

45 lines
1.3 KiB
JavaScript

/**
* 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 (source, minfontsize, maxfontsize, limit) {
const env = this
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
})