Skip to content

Commit

Permalink
fix: change the way to get all posts
Browse files Browse the repository at this point in the history
Data is composed of data from each category.
  • Loading branch information
reco_luan committed Nov 18, 2019
1 parent 2f505aa commit b3bd1dd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
23 changes: 23 additions & 0 deletions components/Common.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ import Sidebar from '@theme/components/Sidebar.vue'
import { resolveSidebarItems } from '../util'
import Password from '@theme/components/Password'
import { setTimeout } from 'timers'
import mixin from '@theme/mixins/index.js'
export default {
mixins: [mixin],
components: { Sidebar, Navbar, Password },
props: {
Expand Down Expand Up @@ -167,6 +169,10 @@ export default {
}
},
created () {
this.getPostData()
},
mounted () {
this.$router.afterEach(() => {
this.isSidebarOpen = false
Expand Down Expand Up @@ -227,6 +233,23 @@ export default {
this.firstLoad = false
if (sessionStorage.getItem('firstLoad') == undefined) sessionStorage.setItem('firstLoad', false)
}, time)
},
getPostData () {
if (!this.$themeConfig.posts) {
const {
$categories: { list: articles },
_filterPostData,
_sortPostData
} = this
let posts = articles.reduce((allData, currnetData) => {
return [...allData, ...currnetData.pages]
}, [])
posts = _filterPostData(posts)
_sortPostData(posts)
this.$themeConfig.posts = posts
}
}
},
Expand Down
24 changes: 3 additions & 21 deletions components/HomeBlog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
<div class="blog-list">
<!-- 博客列表 -->
<note-abstract
:data="posts"
:data="$themeConfig.posts"
:hideAccessNumber="true"
:currentPage="currentPage"></note-abstract>
<!-- 分页 -->
<pagation
class="pagation"
:total="posts.length"
:total="$themeConfig.posts.length"
:currentPage="currentPage"
@getCurrentPage="getCurrentPage" />
</div>
Expand All @@ -26,7 +26,7 @@
<h3 class="name" v-if="$themeConfig.author || $site.title">{{ $themeConfig.author || $site.title }}</h3>
<div class="num">
<div>
<h3>{{getPagesLength}}</h3>
<h3>{{$themeConfig.posts.length}}</h3>
<h6>文章</h6>
</div>
<div>
Expand Down Expand Up @@ -73,24 +73,6 @@ export default {
}
},
computed: {
// 时间降序后的博客列表
posts () {
const {
$site: { pages },
_filterPostData,
_sortPostData
} = this
let posts = pages
posts = _filterPostData(posts)
_sortPostData(posts)
return posts
},
// 分类信息
getPagesLength () {
return this.posts.length
},
actionLink () {
const {
actionLink: link,
Expand Down
8 changes: 4 additions & 4 deletions components/TagList.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="tags">
<span
v-for="(item, index) in $tags.list"
v-for="(item, index) in tags"
:key="index"
:class="{'active': item.name == currentTag}"
:style="{ 'backgroundColor': _tagColor() }"
Expand All @@ -20,9 +20,9 @@ export default {
default: ''
}
},
data () {
return {
tags: []
computed: {
tags () {
return [{ name: '全部' }, ...this.$tags.list]
}
},
methods: {
Expand Down
2 changes: 1 addition & 1 deletion layouts/Tags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default {
if (currentTag !== '全部') {
posts = this.$tags.map[currentTag].pages
} else {
posts = this.$site.pages
posts = this.$themeConfig.posts
}
posts = this._filterPostData(posts)
Expand Down

0 comments on commit b3bd1dd

Please sign in to comment.