hexo-theme-butterfly/scripts/tag/button.js
Jerry 597f0d2019 fix: 修復開啟anchor後,瀏覽器上一頁/下一頁 跳轉會404的bug (文章頁的url hash 在pjax下變成 undefined)
fix: 修復開啟anchor後,文章頁跳轉回主頁,主頁網址的hash添加上文章頁最後一個標題的 bug
improvement: 優化 button tags 標簽外掛
2021-04-23 18:06:51 +08:00

29 lines
731 B
JavaScript

/**
* 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 ? `<i class="${icon}"></i>` : ''}${text.length ? `<span>${text}</span>` : ''}</a>`
}
hexo.extend.tag.register('btn', btn, { ends: false })