mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:30:53 +08:00
Compare commits
91 Commits
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hexo-theme-butterfly",
|
||||
"version": "5.3.2",
|
||||
"version": "5.3.0",
|
||||
"description": "A Simple and Card UI Design theme for Hexo",
|
||||
"main": "package.json",
|
||||
"scripts": {
|
||||
|
||||
@@ -5,31 +5,23 @@
|
||||
'use strict'
|
||||
|
||||
hexo.extend.generator.register('post', locals => {
|
||||
const previousIndexes = []
|
||||
|
||||
const getRandomCover = defaultCover => {
|
||||
const recentCovers = []
|
||||
const randomCoverFn = () => {
|
||||
const { cover: { default_cover: defaultCover } } = hexo.theme.config
|
||||
if (!defaultCover) return false
|
||||
if (!Array.isArray(defaultCover)) return defaultCover
|
||||
const defaultCoverLen = defaultCover.length
|
||||
const limit = 3
|
||||
|
||||
const coverCount = defaultCover.length
|
||||
|
||||
if (coverCount === 1) {
|
||||
return defaultCover[0]
|
||||
}
|
||||
|
||||
const maxPreviousIndexes = coverCount === 2 ? 1 : (coverCount === 3 ? 2 : 3)
|
||||
|
||||
let index
|
||||
let num
|
||||
do {
|
||||
index = Math.floor(Math.random() * coverCount)
|
||||
} while (previousIndexes.includes(index) && previousIndexes.length < coverCount)
|
||||
num = Math.floor(Math.random() * defaultCoverLen)
|
||||
} while (recentCovers.includes(num))
|
||||
|
||||
previousIndexes.push(index)
|
||||
if (previousIndexes.length > maxPreviousIndexes) {
|
||||
previousIndexes.shift()
|
||||
}
|
||||
recentCovers.push(num)
|
||||
if (recentCovers.length > limit) recentCovers.shift()
|
||||
|
||||
return defaultCover[index]
|
||||
return defaultCover[num]
|
||||
}
|
||||
|
||||
const handleImg = data => {
|
||||
@@ -38,20 +30,15 @@ hexo.extend.generator.register('post', locals => {
|
||||
|
||||
// Add path to top_img and cover if post_asset_folder is enabled
|
||||
if (hexo.config.post_asset_folder) {
|
||||
if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) {
|
||||
data.top_img = `${data.path}${topImg}`
|
||||
}
|
||||
if (coverVal && coverVal.indexOf('/') === -1 && imgTestReg.test(coverVal)) {
|
||||
data.cover = `${data.path}${coverVal}`
|
||||
}
|
||||
if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) data.top_img = `${data.path}${topImg}`
|
||||
if (coverVal && coverVal.indexOf('/') === -1 && imgTestReg.test(coverVal)) data.cover = `${data.path}${coverVal}`
|
||||
}
|
||||
|
||||
if (coverVal === false) return data
|
||||
|
||||
// If cover is not set, use random cover
|
||||
if (!coverVal) {
|
||||
const { cover: { default_cover: defaultCover } } = hexo.theme.config
|
||||
const randomCover = getRandomCover(defaultCover)
|
||||
const randomCover = randomCoverFn()
|
||||
data.cover = randomCover
|
||||
coverVal = randomCover // update coverVal
|
||||
}
|
||||
@@ -63,16 +50,7 @@ hexo.extend.generator.register('post', locals => {
|
||||
return data
|
||||
}
|
||||
|
||||
// https://github.com/hexojs/hexo/blob/master/lib%2Fplugins%2Fgenerator%2Fpost.ts
|
||||
const posts = locals.posts.sort('date').toArray()
|
||||
const { length } = posts
|
||||
|
||||
return posts.map((post, i) => {
|
||||
if (i) post.prev = posts[i - 1]
|
||||
if (i < length - 1) post.next = posts[i + 1]
|
||||
|
||||
post.__post = true
|
||||
|
||||
return locals.posts.sort('date').map(post => {
|
||||
return {
|
||||
data: handleImg(post),
|
||||
layout: 'post',
|
||||
|
||||
@@ -12,10 +12,11 @@
|
||||
width: 100% !important
|
||||
|
||||
.pagination-related
|
||||
width: 50%
|
||||
height: 150px
|
||||
|
||||
+minWidth768()
|
||||
flex: 1
|
||||
+maxWidth768()
|
||||
width: 100%
|
||||
|
||||
.info-1
|
||||
.info-item-2
|
||||
@@ -30,10 +31,6 @@
|
||||
margin-top: 40px
|
||||
width: 100%
|
||||
addBorderRadius()
|
||||
display: flex
|
||||
|
||||
+maxWidth768()
|
||||
flex-direction: column
|
||||
|
||||
.layout
|
||||
.pagination
|
||||
|
||||
Reference in New Issue
Block a user