Compare commits

..

91 Commits
5.3.2 ... 5.3.0

3 changed files with 19 additions and 44 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "hexo-theme-butterfly", "name": "hexo-theme-butterfly",
"version": "5.3.2", "version": "5.3.0",
"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": {

View File

@@ -5,31 +5,23 @@
'use strict' 'use strict'
hexo.extend.generator.register('post', locals => { hexo.extend.generator.register('post', locals => {
const previousIndexes = [] const recentCovers = []
const randomCoverFn = () => {
const getRandomCover = defaultCover => { const { cover: { default_cover: defaultCover } } = hexo.theme.config
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
const coverCount = defaultCover.length let num
if (coverCount === 1) {
return defaultCover[0]
}
const maxPreviousIndexes = coverCount === 2 ? 1 : (coverCount === 3 ? 2 : 3)
let index
do { do {
index = Math.floor(Math.random() * coverCount) num = Math.floor(Math.random() * defaultCoverLen)
} while (previousIndexes.includes(index) && previousIndexes.length < coverCount) } while (recentCovers.includes(num))
previousIndexes.push(index) recentCovers.push(num)
if (previousIndexes.length > maxPreviousIndexes) { if (recentCovers.length > limit) recentCovers.shift()
previousIndexes.shift()
}
return defaultCover[index] return defaultCover[num]
} }
const handleImg = data => { 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 // 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)) { if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) data.top_img = `${data.path}${topImg}`
data.top_img = `${data.path}${topImg}` if (coverVal && coverVal.indexOf('/') === -1 && imgTestReg.test(coverVal)) data.cover = `${data.path}${coverVal}`
}
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 { cover: { default_cover: defaultCover } } = hexo.theme.config const randomCover = randomCoverFn()
const randomCover = getRandomCover(defaultCover)
data.cover = randomCover data.cover = randomCover
coverVal = randomCover // update coverVal coverVal = randomCover // update coverVal
} }
@@ -63,16 +50,7 @@ hexo.extend.generator.register('post', locals => {
return data return data
} }
// https://github.com/hexojs/hexo/blob/master/lib%2Fplugins%2Fgenerator%2Fpost.ts return locals.posts.sort('date').map(post => {
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',

View File

@@ -12,10 +12,11 @@
width: 100% !important width: 100% !important
.pagination-related .pagination-related
width: 50%
height: 150px height: 150px
+minWidth768() +maxWidth768()
flex: 1 width: 100%
.info-1 .info-1
.info-item-2 .info-item-2
@@ -30,10 +31,6 @@
margin-top: 40px margin-top: 40px
width: 100% width: 100%
addBorderRadius() addBorderRadius()
display: flex
+maxWidth768()
flex-direction: column
.layout .layout
.pagination .pagination