mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:30:53 +08:00
feat: gallery 標籤外掛增加 json 獲取
feat: 本地搜索,點擊文章內容也會跳轉到相應頁面 feat: 添加 docsearch feat: 標籤頁支持配置 orderby 和 order 參數 feat: card_tags 可配置 orderby 和 order 參數 fix: 修復本地搜索,輸入 ?d 報錯的 bug closed #1192 fix: 修復 waline 在 pjax 模式下 css 沒有加載的 bug fix: 修復 artalk 最新評論無法加載 closed #1191 fix: 修復 card_author 和 card_announcement 設為 false 後,aside 卡片沒有間距的 bug closed #1174 improvement: getCSS 重構
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
* galleryGroup and gallery
|
||||
* {% galleryGroup [name] [descr] [url] [img] %}
|
||||
* {% gallery [lazyload],[rowHeight],[limit] %}
|
||||
* {% gallery url,[url],[lazyload],[rowHeight],[limit] %}
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
@@ -12,28 +13,42 @@ const urlFor = require('hexo-util').url_for.bind(hexo)
|
||||
function gallery (args, content) {
|
||||
const { data, languages } = hexo.theme.i18n
|
||||
args = args.join(' ').split(',')
|
||||
const rowHeight = args[1] || 220
|
||||
const limit = args[2] || 10
|
||||
const lazyload = args[0] === 'true'
|
||||
const regex = /!\[(.*?)\]\(([^\s]*)\s*(?:["'](.*?)["']?)?\s*\)/g
|
||||
const lazyloadClass = lazyload ? 'lazyload' : ''
|
||||
let m
|
||||
const arr = []
|
||||
while ((m = regex.exec(content)) !== null) {
|
||||
if (m.index === regex.lastIndex) {
|
||||
regex.lastIndex++
|
||||
let rowHeight, limit, lazyload, type, dataStr
|
||||
|
||||
// url,[link],[lazyload],[rowHeight],[limit]
|
||||
if (args[0] === 'url') {
|
||||
dataStr = args[1]
|
||||
lazyload = args[2] === 'true'
|
||||
rowHeight = args[3] || 220
|
||||
limit = args[4] || 10
|
||||
type = ' url'
|
||||
} else {
|
||||
rowHeight = args[1] || 220
|
||||
limit = args[2] || 10
|
||||
lazyload = args[0] === 'true'
|
||||
type = ' data'
|
||||
const regex = /!\[(.*?)\]\(([^\s]*)\s*(?:["'](.*?)["']?)?\s*\)/g
|
||||
let m
|
||||
const arr = []
|
||||
while ((m = regex.exec(content)) !== null) {
|
||||
if (m.index === regex.lastIndex) {
|
||||
regex.lastIndex++
|
||||
}
|
||||
arr.push({
|
||||
url: m[2],
|
||||
alt: m[1],
|
||||
title: m[3]
|
||||
})
|
||||
}
|
||||
|
||||
arr.push({
|
||||
url: m[2],
|
||||
alt: m[1],
|
||||
title: m[3]
|
||||
})
|
||||
dataStr = JSON.stringify(arr)
|
||||
}
|
||||
|
||||
const lazyloadClass = lazyload ? 'lazyload' : ''
|
||||
|
||||
return `<div class="gallery">
|
||||
<div class="fj-gallery ${lazyloadClass}" data-rowHeight="${rowHeight}" data-limit="${limit}">
|
||||
<span class="gallery-data">${JSON.stringify(arr)}</span>
|
||||
<div class="fj-gallery ${lazyloadClass + type}" data-rowHeight="${rowHeight}" data-limit="${limit}">
|
||||
<span class="gallery-data">${dataStr}</span>
|
||||
</div>
|
||||
<button class="gallery-load-more"><span>${data[languages[0]].load_more}</span><i class="fa-solid fa-arrow-down"></i></button>
|
||||
</div>`
|
||||
|
||||
Reference in New Issue
Block a user