mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-08-08 11:38:42 +08:00
update
This commit is contained in:
@@ -17,12 +17,11 @@ hexo.extend.helper.register('getArchiveLength', function () {
|
||||
const m = date.month() + 1
|
||||
const d = date.date()
|
||||
|
||||
if (yearly) {
|
||||
const keyYear = `${y}`
|
||||
map.set(keyYear, (map.get(keyYear) || 0) + 1)
|
||||
}
|
||||
// Always track year so year archive pages can be counted
|
||||
const keyYear = `${y}`
|
||||
map.set(keyYear, (map.get(keyYear) || 0) + 1)
|
||||
|
||||
if (monthly) {
|
||||
if (monthly || daily) {
|
||||
const keyMonth = `${y}-${m}`
|
||||
map.set(keyMonth, (map.get(keyMonth) || 0) + 1)
|
||||
}
|
||||
@@ -37,8 +36,8 @@ hexo.extend.helper.register('getArchiveLength', function () {
|
||||
|
||||
// Determine the appropriate key to fetch based on current page context
|
||||
let key
|
||||
if (yearly && year) key = `${year}`
|
||||
if (monthly && month) key = `${year}-${month}`
|
||||
if (yearly || monthly || daily) key = `${year}`
|
||||
if ((monthly || daily) && month) key = `${year}-${month}`
|
||||
if (daily && day) key = `${year}-${month}-${day}`
|
||||
|
||||
// Return the count for the current period or default to the total posts
|
||||
|
||||
+11
-12
@@ -11,6 +11,8 @@ const colorPattern = /^(#|rgb|rgba|hsl|hsla)/i
|
||||
const simpleFilePattern = /\.(png|jpg|jpeg|gif|bmp|webp|svg|tiff)$/i
|
||||
const archiveRegex = /\/archives\//
|
||||
|
||||
const { version: themeVersion } = require('../../package.json')
|
||||
|
||||
hexo.extend.helper.register('truncate', truncateContent)
|
||||
|
||||
hexo.extend.helper.register('postDesc', data => {
|
||||
@@ -58,8 +60,6 @@ hexo.extend.helper.register('cloudTags', function (options = {}) {
|
||||
|
||||
const userColors = normalizeColors(custom_colors)
|
||||
|
||||
const resolveColorClass = (idx) => `tag-color-${idx % userColors.length}`
|
||||
|
||||
const generateStyle = (size, unit, page, color) => {
|
||||
const colorStyle = page === 'tags' ? `background-color: ${color};` : `color: ${color};`
|
||||
return `font-size: ${parseFloat(size.toFixed(2))}${unit}; ${colorStyle}`
|
||||
@@ -70,10 +70,9 @@ hexo.extend.helper.register('cloudTags', function (options = {}) {
|
||||
const size = minfontsize + ((maxfontsize - minfontsize) * ratio)
|
||||
|
||||
if (userColors && userColors.length) {
|
||||
const colorClass = resolveColorClass(idx)
|
||||
const color = userColors[idx % userColors.length]
|
||||
const style = generateStyle(size, unit, page, color)
|
||||
return `<a href="${env.url_for(tag.path)}" class="tag-cloud-item ${colorClass}" style="${style}">${tag.name}</a>`
|
||||
return `<a href="${env.url_for(tag.path)}" class="tag-cloud-item" style="${style}">${tag.name}</a>`
|
||||
}
|
||||
|
||||
const color = getRandomColor()
|
||||
@@ -105,13 +104,13 @@ hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) {
|
||||
if (!menu) return defaultTitle
|
||||
|
||||
const loop = m => {
|
||||
for (const key in m) {
|
||||
if (typeof m[key] === 'object') {
|
||||
const result = loop(m[key])
|
||||
for (const [key, value] of Object.entries(m)) {
|
||||
if (value && typeof value === 'object') {
|
||||
const result = loop(value)
|
||||
if (result) return result
|
||||
}
|
||||
|
||||
if (archiveRegex.test(m[key])) {
|
||||
if (typeof value === 'string' && archiveRegex.test(value)) {
|
||||
return key
|
||||
}
|
||||
}
|
||||
@@ -154,9 +153,10 @@ hexo.extend.helper.register('shuoshuoFN', (data, page) => {
|
||||
|
||||
// This is a hack method, because hexo treats time as UTC time
|
||||
// so you need to manually convert the time zone
|
||||
const timezone = hexo.config.timezone
|
||||
processedData.forEach(item => {
|
||||
const utcDate = moment.utc(item.date).format('YYYY-MM-DD HH:mm:ss')
|
||||
item.date = moment.tz(utcDate, hexo.config.timezone).format('YYYY-MM-DD HH:mm:ss')
|
||||
const parsed = moment.utc(item.date)
|
||||
item.date = moment.tz(parsed.format('YYYY-MM-DD HH:mm:ss'), timezone).format('YYYY-MM-DD HH:mm:ss')
|
||||
// markdown
|
||||
item.content = hexo.render.renderSync({ text: item.content, engine: 'markdown' })
|
||||
})
|
||||
@@ -179,8 +179,7 @@ hexo.extend.helper.register('getPageType', (page, isHome) => {
|
||||
})
|
||||
|
||||
hexo.extend.helper.register('getVersion', () => {
|
||||
const { version } = require('../../package.json')
|
||||
return { hexo: hexo.version, theme: version }
|
||||
return { hexo: hexo.version, theme: themeVersion }
|
||||
})
|
||||
|
||||
hexo.extend.helper.register('safeJSON', data => {
|
||||
|
||||
@@ -23,7 +23,6 @@ hexo.extend.helper.register('related_posts', function (currentPost) {
|
||||
if (relatedPosts.has(post.path)) {
|
||||
relatedPosts.get(post.path).weight += 1
|
||||
} else {
|
||||
const getPostDesc = post.postDesc || postDesc(post, hexo)
|
||||
relatedPosts.set(post.path, {
|
||||
title: post.title,
|
||||
path: post.path,
|
||||
@@ -32,7 +31,7 @@ hexo.extend.helper.register('related_posts', function (currentPost) {
|
||||
weight: 1,
|
||||
updated: post.updated,
|
||||
created: post.date,
|
||||
postDesc: getPostDesc,
|
||||
post,
|
||||
random: Math.random()
|
||||
})
|
||||
}
|
||||
@@ -61,12 +60,15 @@ hexo.extend.helper.register('related_posts', function (currentPost) {
|
||||
result += `<div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>${headlineLang}</span></div>`
|
||||
result += '<div class="relatedPosts-list">'
|
||||
|
||||
for (let i = 0; i < Math.min(relatedPostsList.length, limitNum); i++) {
|
||||
let { cover, title, path, cover_type, created, updated, postDesc } = relatedPostsList[i]
|
||||
const max = Math.min(relatedPostsList.length, limitNum)
|
||||
for (let i = 0; i < max; i++) {
|
||||
const item = relatedPostsList[i]
|
||||
let { cover, title, path, cover_type, created, updated, post } = item
|
||||
const { escape_html, url_for, date } = this
|
||||
cover = cover || 'var(--default-bg-color)'
|
||||
title = escape_html(title)
|
||||
const className = postDesc ? 'pagination-related' : 'pagination-related no-desc'
|
||||
const desc = post.postDesc || postDesc(post, hexo)
|
||||
const className = desc ? 'pagination-related' : 'pagination-related no-desc'
|
||||
result += `<a class="${className}" href="${url_for(path)}" title="${title}">`
|
||||
if (cover_type === 'img') {
|
||||
result += `<img class="cover" src="${url_for(cover)}" alt="cover">`
|
||||
@@ -80,8 +82,8 @@ hexo.extend.helper.register('related_posts', function (currentPost) {
|
||||
}
|
||||
result += `<div class="info-item-2">${title}</div></div>`
|
||||
|
||||
if (postDesc) {
|
||||
result += `<div class="info-2"><div class="info-item-1">${postDesc}</div></div>`
|
||||
if (desc) {
|
||||
result += `<div class="info-2"><div class="info-item-1">${desc}</div></div>`
|
||||
}
|
||||
result += '</div></a>'
|
||||
}
|
||||
|
||||
@@ -7,15 +7,16 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
const urlFor = require('hexo-util').url_for.bind(hexo)
|
||||
const { url_for, escapeHTML } = require('hexo-util')
|
||||
const urlFor = url_for.bind(hexo)
|
||||
|
||||
const btn = args => {
|
||||
const [url = '', text = '', icon = '', option = ''] = args.join(' ').split(',').map(arg => arg.trim())
|
||||
|
||||
const iconHTML = icon ? `<i class="${icon}"></i>` : ''
|
||||
const textHTML = text ? `<span>${text}</span>` : ''
|
||||
const iconHTML = icon ? `<i class="${escapeHTML(icon)}"></i>` : ''
|
||||
const textHTML = text ? `<span>${escapeHTML(text)}</span>` : ''
|
||||
|
||||
return `<a class="btn-beautify ${option}" href="${urlFor(url)}" title="${text}">${iconHTML}${textHTML}</a>`
|
||||
return `<a class="btn-beautify ${escapeHTML(option)}" href="${urlFor(url)}" title="${escapeHTML(text)}">${iconHTML}${textHTML}</a>`
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('btn', btn, { ends: false })
|
||||
|
||||
@@ -4,24 +4,25 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
const urlFor = require('hexo-util').url_for.bind(hexo)
|
||||
const { url_for, escapeHTML } = require('hexo-util')
|
||||
const urlFor = url_for.bind(hexo)
|
||||
|
||||
const flinkFn = (args, content) => {
|
||||
const data = hexo.render.renderSync({ text: content, engine: 'yaml' })
|
||||
let result = ''
|
||||
|
||||
data.forEach(item => {
|
||||
const className = item.class_name ? `<div class="flink-name">${item.class_name}</div>` : ''
|
||||
const classDesc = item.class_desc ? `<div class="flink-desc">${item.class_desc}</div>` : ''
|
||||
const className = item.class_name ? `<div class="flink-name">${escapeHTML(item.class_name)}</div>` : ''
|
||||
const classDesc = item.class_desc ? `<div class="flink-desc">${escapeHTML(item.class_desc)}</div>` : ''
|
||||
|
||||
const listResult = item.link_list.map(link => `
|
||||
<div class="flink-list-item">
|
||||
<a href="${link.link}" title="${link.name}" target="_blank">
|
||||
<a href="${escapeHTML(link.link)}" title="${escapeHTML(link.name)}" target="_blank">
|
||||
<div class="flink-item-icon">
|
||||
<img class="no-lightbox" src="${link.avatar}" onerror='this.onerror=null;this.src="${urlFor(hexo.theme.config.error_img.flink)}"' alt="${link.name}" />
|
||||
<img class="no-lightbox" src="${escapeHTML(link.avatar)}" onerror='this.onerror=null;this.src="${urlFor(hexo.theme.config.error_img.flink)}"' alt="${escapeHTML(link.name)}" />
|
||||
</div>
|
||||
<div class="flink-item-name">${link.name}</div>
|
||||
<div class="flink-item-desc" title="${link.descr}">${link.descr}</div>
|
||||
<div class="flink-item-name">${escapeHTML(link.name)}</div>
|
||||
<div class="flink-item-desc" title="${escapeHTML(link.descr)}">${escapeHTML(link.descr)}</div>
|
||||
</a>
|
||||
</div>`).join('')
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ const parseGalleryArgs = args => {
|
||||
const parseImageContent = content => {
|
||||
const images = []
|
||||
let match
|
||||
IMAGE_REGEX.lastIndex = 0
|
||||
|
||||
while ((match = IMAGE_REGEX.exec(content)) !== null) {
|
||||
images.push({
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
const parseArgs = args => args.join(' ').split(',')
|
||||
const parseArgs = args => args.join(' ').split(',').map(s => s.trim())
|
||||
|
||||
const generateStyle = (bg, color) => {
|
||||
let style = 'style="'
|
||||
|
||||
+3
-13
@@ -5,20 +5,10 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
const { escapeHTML } = require('hexo-util')
|
||||
|
||||
const score = (args, content) => {
|
||||
// Escape HTML tags and some special characters, including curly braces
|
||||
const escapeHtmlTags = s => {
|
||||
const lookup = {
|
||||
'&': '&',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'{': '{',
|
||||
'}': '}'
|
||||
}
|
||||
return s.replace(/[&"'<>{}]/g, c => lookup[c])
|
||||
}
|
||||
const escapeHtmlTags = s => escapeHTML(s).replace(/[{}]/g, c => c === '{' ? '{' : '}')
|
||||
|
||||
const trimmed = content.trim()
|
||||
// Split content using six dashes as a delimiter
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
const urlFor = require('hexo-util').url_for.bind(hexo)
|
||||
const groups = {}
|
||||
|
||||
hexo.extend.filter.register('before_generate', () => {
|
||||
Object.keys(groups).forEach(k => delete groups[k])
|
||||
})
|
||||
|
||||
hexo.extend.filter.register('before_post_render', data => {
|
||||
if (!hexo.theme.config.series.enable) return data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user