2019-12-04 23:45:40 +08:00
|
|
|
import { filterPosts, sortPostsByStickyAndDate, sortPostsByDate } from '../helpers/postData'
|
2019-12-04 13:59:02 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
computed: {
|
|
|
|
$recoPosts () {
|
|
|
|
const {
|
|
|
|
$categories: { list: articles }
|
|
|
|
} = this
|
|
|
|
|
|
|
|
let posts = articles.reduce((allData, currnetData) => {
|
|
|
|
return [...allData, ...currnetData.pages]
|
|
|
|
}, [])
|
|
|
|
|
2019-12-04 23:45:40 +08:00
|
|
|
posts = filterPosts(posts)
|
|
|
|
sortPostsByStickyAndDate(posts)
|
2019-12-04 13:59:02 +08:00
|
|
|
|
|
|
|
return posts
|
2019-12-04 23:45:40 +08:00
|
|
|
},
|
|
|
|
$recoPostsForTimeline () {
|
|
|
|
let pages = this.$recoPosts
|
|
|
|
const formatPages = {}
|
|
|
|
const formatPagesArr = []
|
|
|
|
pages = filterPosts(pages, true)
|
|
|
|
this.pages = pages.length == 0 ? [] : pages
|
|
|
|
for (let i = 0, length = pages.length; i < length; i++) {
|
|
|
|
const page = pages[i]
|
|
|
|
const pageDateYear = dateFormat(page.frontmatter.date, 'year')
|
|
|
|
if (formatPages[pageDateYear]) formatPages[pageDateYear].push(page)
|
|
|
|
else {
|
|
|
|
formatPages[pageDateYear] = [page]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const key in formatPages) {
|
|
|
|
const data = formatPages[key]
|
|
|
|
sortPostsByDate(data)
|
|
|
|
formatPagesArr.unshift({
|
|
|
|
year: key,
|
|
|
|
data
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return formatPagesArr
|
2019-12-04 13:59:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-04 23:45:40 +08:00
|
|
|
|
|
|
|
function renderTime (date) {
|
|
|
|
var dateee = new Date(date).toJSON()
|
|
|
|
return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').replace(/-/g, '/')
|
|
|
|
}
|
|
|
|
function dateFormat (date, type) {
|
|
|
|
date = renderTime(date)
|
|
|
|
const dateObj = new Date(date)
|
|
|
|
const year = dateObj.getFullYear()
|
|
|
|
const mon = dateObj.getMonth() + 1
|
|
|
|
const day = dateObj.getDate()
|
|
|
|
if (type == 'year') return year
|
|
|
|
else return `${mon}-${day}`
|
|
|
|
}
|