2019-08-31 01:50:57 +08:00
|
|
|
export default {
|
|
|
|
methods: {
|
|
|
|
_tagColor () {
|
|
|
|
// 红、蓝、绿、橙、灰
|
|
|
|
const tagColorArr = ['#e15b64', '#f47e60', '#f8b26a', '#abbd81', '#849b87', '#e15b64', '#f47e60', '#f8b26a', '#f26d6d', '#67cc86', '#fb9b5f', '#3498db']
|
|
|
|
const index = Math.floor(Math.random() * tagColorArr.length)
|
|
|
|
return tagColorArr[index]
|
2019-10-20 21:45:40 +08:00
|
|
|
},
|
2019-10-21 17:12:01 +08:00
|
|
|
_filterPostData (posts, isTimeline) {
|
2019-11-25 22:46:33 +08:00
|
|
|
const stickyArr = []
|
2019-10-20 21:45:40 +08:00
|
|
|
posts = posts.filter(item => {
|
2019-11-25 22:46:33 +08:00
|
|
|
const { title, frontmatter: { home, date, publish, sticky }} = item
|
|
|
|
if (sticky) {
|
|
|
|
stickyArr.unshift(item)
|
|
|
|
return false
|
|
|
|
}
|
2019-10-21 17:12:01 +08:00
|
|
|
return isTimeline === true
|
2019-10-27 20:34:46 +08:00
|
|
|
? !(home == true || title == undefined || date === undefined || publish === false)
|
|
|
|
: !(home == true || title == undefined || publish === false)
|
2019-10-20 21:45:40 +08:00
|
|
|
})
|
2019-11-25 22:46:33 +08:00
|
|
|
return stickyArr.concat(posts)
|
2019-10-20 21:45:40 +08:00
|
|
|
},
|
|
|
|
_sortPostData (posts) {
|
|
|
|
posts.sort((a, b) => {
|
|
|
|
return this._getTimeNum(b) - this._getTimeNum(a)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取时间的数字类型
|
|
|
|
_getTimeNum (date) {
|
|
|
|
return parseInt(new Date(date.frontmatter.date).getTime())
|
2019-11-20 16:47:05 +08:00
|
|
|
},
|
|
|
|
// 获取博客数据
|
|
|
|
_getPostData () {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
if (!this.$themeConfig.posts) {
|
|
|
|
const {
|
|
|
|
$categories: { list: articles },
|
|
|
|
_filterPostData,
|
|
|
|
_sortPostData
|
|
|
|
} = this
|
|
|
|
|
|
|
|
let posts = articles.reduce((allData, currnetData) => {
|
|
|
|
return [...allData, ...currnetData.pages]
|
|
|
|
}, [])
|
2019-11-25 22:46:33 +08:00
|
|
|
|
2019-11-20 16:47:05 +08:00
|
|
|
_sortPostData(posts)
|
2019-11-25 22:46:33 +08:00
|
|
|
posts = _filterPostData(posts)
|
2019-11-20 16:47:05 +08:00
|
|
|
|
|
|
|
this.$themeConfig.posts = posts
|
|
|
|
resolve(posts)
|
|
|
|
}
|
|
|
|
})
|
2019-08-31 01:50:57 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-21 17:12:01 +08:00
|
|
|
}
|