mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 19:30:54 +08:00
feat: 不再支持 butterfly.yml 寫法
improvement: 文章頁標題改為h1(seo) improvement: 改用hexo 內置的 injector 插入 inject 的代碼 improvement: canonical 改為hexo提供的函數生成 improvement: 優化手機toc 的特效和按鈕出現的時機 remove: 刪除搜索不必要的配置 remove: 移除豆瓣配置,如需配置,請使用 hexo-butterfly-douban fix: 修復上一個版本導致的搜索按鈕在pjax下無法點擊的bugs close #387 fix: 修復上一個版本更新的toc z-index 過低的bugs
This commit is contained in:
28
scripts/tag/button.js
Normal file
28
scripts/tag/button.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Button
|
||||
* {% btn url text icon option %}
|
||||
* option: color outline center block larger
|
||||
* color : default/blue/pink/red/purple/orange/green
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const urlFor = require('hexo-util').url_for.bind(hexo)
|
||||
|
||||
function btn (args) {
|
||||
args = args.join(' ').split(',')
|
||||
let url = args[0] || ''
|
||||
let text = args[1] || ''
|
||||
let icon = args[2] || ''
|
||||
let option = args[3] || ''
|
||||
|
||||
url = url.trim()
|
||||
text = text.trim()
|
||||
icon = icon.trim()
|
||||
option = option.trim()
|
||||
|
||||
return `<a class="btn-beautify button--animated ${option}" href="${urlFor(url)}"
|
||||
title="${text}">${icon.length > 0 ? `<i class="${icon} fa-fw"></i>` : ''}<span>${text}</span></a>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('btn', btn, { ends: false })
|
||||
34
scripts/tag/gallery.js
Normal file
34
scripts/tag/gallery.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Butterfly
|
||||
* galleryGroup and allery
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const urlFor = 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) {
|
||||
const name = args[0]
|
||||
const desrc = args[1]
|
||||
const url = urlFor(args[2])
|
||||
const img = urlFor(args[3])
|
||||
|
||||
return `
|
||||
<figure class="gallery-group">
|
||||
<img class="gallery-group-img" src='${img}'>
|
||||
<figcaption>
|
||||
<div class="gallery-group-name">${name}</div>
|
||||
<p>${desrc}</p>
|
||||
<a href='${url}'></a>
|
||||
</figcaption>
|
||||
</figure>
|
||||
`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('gallery', gallery, { ends: true })
|
||||
hexo.extend.tag.register('galleryGroup', galleryGroup)
|
||||
71
scripts/tag/hide.js
Normal file
71
scripts/tag/hide.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Butterfly
|
||||
* @example
|
||||
* hideInline
|
||||
* {% hideInline content,display,bg,color %}
|
||||
* content不能包含當引號,可用 '
|
||||
* hideBlock
|
||||
* {% hideBlock display,bg,color %}
|
||||
* content
|
||||
* {% endhideBlock %}
|
||||
* hideToggle
|
||||
* {% hideToggle display,bg,color %}
|
||||
* content
|
||||
* {% endhideToggle %}
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
function hideInline (args) {
|
||||
args = args.join(' ').split(',')
|
||||
const content = args[0]
|
||||
const display = args[1] || 'Click'
|
||||
const bg = args[2] || false
|
||||
const color = args[3] || false
|
||||
let group = 'style="'
|
||||
|
||||
if (bg) group += `background-color: ${bg};`
|
||||
if (color) group += `color: ${color}`
|
||||
group += '"'
|
||||
|
||||
return `<span class="hide-inline"><button type="button" class="hide-button button--animated" ${group}>${display}
|
||||
</button><span class="hide-content">${content}</span></span>`
|
||||
}
|
||||
|
||||
function hideBlock (args, content) {
|
||||
args = args.join(' ').split(',')
|
||||
const display = args[0] || 'Click'
|
||||
const bg = args[1] || false
|
||||
const color = args[2] || false
|
||||
let group = 'style="'
|
||||
|
||||
if (bg) group += `background-color: ${bg};`
|
||||
if (color) group += `color: ${color}`
|
||||
group += '"'
|
||||
|
||||
return `<div class="hide-block"><button type="button" class="hide-button button--animated" ${group}>${display}
|
||||
</button><span class="hide-content">${hexo.render.renderSync({ text: content, engine: 'markdown' })}</span></div>`
|
||||
}
|
||||
|
||||
function hideToggle (args, content) {
|
||||
args = args.join(' ').split(',')
|
||||
const display = args[0]
|
||||
const bg = args[1] || false
|
||||
const color = args[2] || false
|
||||
let group = 'style="'
|
||||
let 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="fas fa-caret-right fa-fw"></i><span>${display}</span></div>
|
||||
<div class="hide-content">${hexo.render.renderSync({ text: content, engine: 'markdown' })}</div></div>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('hideInline', hideInline)
|
||||
hexo.extend.tag.register('hideBlock', hideBlock, { ends: true })
|
||||
hexo.extend.tag.register('hideToggle', hideToggle, { ends: true })
|
||||
15
scripts/tag/mermaid.js
Normal file
15
scripts/tag/mermaid.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Butterfly
|
||||
* mermaid
|
||||
* https://github.com/mermaid-js/mermaid
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const { escapeHTML } = require('hexo-util')
|
||||
|
||||
function mermaid (args, content) {
|
||||
return `<div class="mermaid">${escapeHTML(content)}</div>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('mermaid', mermaid, { ends: true })
|
||||
27
scripts/tag/note.js
Normal file
27
scripts/tag/note.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* note.js
|
||||
* transplant from hexo-theme-next
|
||||
* Modify by Jerry
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
function postNote (args, content) {
|
||||
const styleConfig = hexo.theme.config.note.style
|
||||
const lastArgs = args[args.length - 1]
|
||||
if (!(lastArgs === 'flat' || lastArgs === 'modern' || lastArgs === 'simple' || lastArgs === 'disabled')) {
|
||||
args.push(styleConfig)
|
||||
}
|
||||
|
||||
let icon = ''
|
||||
const iconArray = args[args.length - 2]
|
||||
if (iconArray && iconArray.startsWith('fa')) {
|
||||
icon = `<i class="note-icon ${iconArray}"></i>`
|
||||
args[args.length - 2] = 'icon'
|
||||
}
|
||||
|
||||
return `<div class="note ${args.join(' ')}">${icon + hexo.render.renderSync({ text: content, engine: 'markdown' })}</div>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('note', postNote, { ends: true })
|
||||
hexo.extend.tag.register('subnote', postNote, { ends: true })
|
||||
62
scripts/tag/tabs.js
Normal file
62
scripts/tag/tabs.js
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Tabs
|
||||
* transplant from hexo-theme-next
|
||||
* modify by Jerry
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
function postTabs (args, content) {
|
||||
const tabBlock = /<!--\s*tab (.*?)\s*-->\n([\w\W\s\S]*?)<!--\s*endtab\s*-->/g
|
||||
|
||||
args = args.join(' ').split(',')
|
||||
const tabName = args[0]
|
||||
const tabActive = Number(args[1]) || 0
|
||||
|
||||
const matches = []
|
||||
let match
|
||||
let tabId = 0
|
||||
let tabNav = ''
|
||||
let tabContent = ''
|
||||
|
||||
!tabName && hexo.log.warn('Tabs block must have unique name!')
|
||||
|
||||
while ((match = tabBlock.exec(content)) !== null) {
|
||||
matches.push(match[1])
|
||||
matches.push(match[2])
|
||||
}
|
||||
|
||||
for (let i = 0; i < matches.length; i += 2) {
|
||||
const tabParameters = matches[i].split('@')
|
||||
let postContent = matches[i + 1]
|
||||
let tabCaption = tabParameters[0] || ''
|
||||
let tabIcon = tabParameters[1] || ''
|
||||
let tabHref = ''
|
||||
|
||||
postContent = hexo.render.renderSync({ text: postContent, engine: 'markdown' }).trim()
|
||||
|
||||
tabId += 1
|
||||
tabHref = (tabName + ' ' + tabId).toLowerCase().split(' ').join('-');
|
||||
|
||||
((tabCaption.length === 0) && (tabIcon.length === 0)) && (tabCaption = tabName + ' ' + tabId)
|
||||
|
||||
const isOnlyicon = tabIcon.length > 0 && tabCaption.length === 0 ? ' style="text-align: center;"' : ''
|
||||
const icon = tabIcon.trim()
|
||||
tabIcon.length > 0 && (tabIcon = `<i class="${icon}"${isOnlyicon}></i>`)
|
||||
|
||||
const toTop = '<button type="button" class="tab-to-top"><i class="fas fa-arrow-up"></i></button>'
|
||||
|
||||
const isActive = (tabActive > 0 && tabActive === tabId) || (tabActive === 0 && tabId === 1) ? ' active' : ''
|
||||
tabNav += `<li class="tab${isActive}"><button type="button" data-href="#${tabHref}">${tabIcon + tabCaption.trim()}</button></li>`
|
||||
tabContent += `<div class="tab-item-content${isActive}" id="${tabHref}">${postContent + toTop}</div>`
|
||||
}
|
||||
|
||||
tabNav = `<ul class="nav-tabs">${tabNav}</ul>`
|
||||
tabContent = `<div class="tab-contents">${tabContent}</div>`
|
||||
|
||||
return `<div class="tabs" id="${tabName.toLowerCase().split(' ').join('-')}">${tabNav + tabContent}</div>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('tabs', postTabs, { ends: true })
|
||||
hexo.extend.tag.register('subtabs', postTabs, { ends: true })
|
||||
hexo.extend.tag.register('subsubtabs', postTabs, { ends: true })
|
||||
Reference in New Issue
Block a user