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