mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-08 12:07:06 +08:00
update
This commit is contained in:
@@ -341,7 +341,7 @@ hexo.extend.filter.register('before_generate', () => {
|
||||
user_id: null,
|
||||
pageSize: 10,
|
||||
order_by: 'social',
|
||||
lang: 'zh_TW'
|
||||
lang: 'en_US'
|
||||
},
|
||||
twikoo: {
|
||||
envId: null,
|
||||
@@ -514,21 +514,17 @@ hexo.extend.filter.register('before_generate', () => {
|
||||
},
|
||||
chartjs: {
|
||||
enable: false,
|
||||
color: {
|
||||
light: "rgba(0, 0, 0, 0.8)",
|
||||
dark: "rgba(255, 255, 255, 0.8)"
|
||||
fontColor: {
|
||||
light: 'rgba(0, 0, 0, 0.8)',
|
||||
dark: 'rgba(255, 255, 255, 0.8)'
|
||||
},
|
||||
borderColor: {
|
||||
light: "rgba(0, 0, 0, 0.1)",
|
||||
dark: "rgba(255, 255, 255, 0.2)"
|
||||
light: 'rgba(0, 0, 0, 0.1)',
|
||||
dark: 'rgba(255, 255, 255, 0.2)'
|
||||
},
|
||||
scale: {
|
||||
ticks: {
|
||||
backdropColor: {
|
||||
light: "transparent",
|
||||
dark: "transparent"
|
||||
}
|
||||
}
|
||||
scale_ticks_backdropColor: {
|
||||
light: 'transparent',
|
||||
dark: 'transparent'
|
||||
}
|
||||
},
|
||||
note: {
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
* Butterfly
|
||||
* chartjs
|
||||
* https://www.chartjs.org/
|
||||
* Author: SeaYJ
|
||||
* {% chartjs [width, abreast, chartId] %}
|
||||
* <!-- chart -->
|
||||
* <!-- endchart -->
|
||||
* <!-- desc -->
|
||||
* <!-- enddesc -->
|
||||
* {% endchartjs %}
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
@@ -10,30 +15,35 @@
|
||||
const { escapeHTML } = require('hexo-util')
|
||||
|
||||
const chartjs = (args, content) => {
|
||||
const chartBlock = /<!--\s*chart\s*-->\n([\w\W\s\S]*?)<!--\s*endchart\s*-->/g
|
||||
const descBlock = /<!--\s*desc\s*-->\n([\w\W\s\S]*?)<!--\s*enddesc\s*-->/g
|
||||
const id = args[0]
|
||||
const descMatches = []
|
||||
let chartConfig
|
||||
let descDOM = ''
|
||||
let match
|
||||
if (!content) return
|
||||
|
||||
!content && hexo.log.warn('chartjs has no content!')
|
||||
const chartRegex = /<!--\s*chart\s*-->\n([\w\W\s\S]*?)<!--\s*endchart\s*-->/
|
||||
const descRegex = /<!--\s*desc\s*-->\n([\w\W\s\S]*?)<!--\s*enddesc\s*-->/
|
||||
const selfConfig = args.join(' ').trim()
|
||||
|
||||
if ((match = chartBlock.exec(content)) !== null) {
|
||||
chartConfig = match[1]
|
||||
}
|
||||
const [width = '', layout = false, chartId = ''] = selfConfig.split(',').map(s => s.trim())
|
||||
|
||||
while ((match = descBlock.exec(content)) !== null) {
|
||||
descMatches.push(match[1])
|
||||
}
|
||||
const chartMatch = content.match(chartRegex)
|
||||
const descMatch = content.match(descRegex)
|
||||
|
||||
for (let i = 0; i < descMatches.length; i++) {
|
||||
let descContent = hexo.render.renderSync({ text: descMatches[i], engine: 'markdown' }).trim()
|
||||
descDOM += (descContent ? `<div class="chatjs-desc-${i}">${descContent}</div>` : '')
|
||||
}
|
||||
if (!chartMatch) {
|
||||
hexo.log.warn('chartjs tag: chart content is required!')
|
||||
return
|
||||
}
|
||||
|
||||
return `<div class="chartjs-wrap" data-chartjs-id="${id}"><pre class="chartjs-src" hidden>${escapeHTML(chartConfig)}</pre>${descDOM}</div>`
|
||||
const chartConfig = chartMatch && chartMatch[1] ? chartMatch[1] : ''
|
||||
const descContent = descMatch && descMatch[1] ? descMatch[1] : ''
|
||||
|
||||
const renderedDesc = descContent ? hexo.render.renderSync({ text: descContent, engine: 'markdown' }).trim() : ''
|
||||
|
||||
const descDOM = renderedDesc ? `<div class="chartjs-desc">${renderedDesc}</div>` : ''
|
||||
const abreastClass = layout ? ' chartjs-abreast' : ''
|
||||
const widthStyle = width ? `data-width="${width}%"` : ''
|
||||
|
||||
return `<div class="chartjs-container${abreastClass}" data-chartjs-id="${chartId}" ${widthStyle}>
|
||||
<pre class="chartjs-src" hidden>${escapeHTML(chartConfig)}</pre>
|
||||
${descDOM}
|
||||
</div>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('chartjs', chartjs, { ends: true })
|
||||
|
||||
Reference in New Issue
Block a user