Skip to content

Commit dc1d76e

Browse files
author
reco_luan
committed
fix: fix filtering of article data
1 parent 1ce2c29 commit dc1d76e

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

components/Home.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<h1 v-if="data.isShowTitleInHome !== false">{{ data.heroText || $title || '午后南杂' }}</h1>
1111

12-
<p class="description">{{ data.tagline || $description || 'Welcome to your vuePress-theme-reco site' }}</p>
12+
<p class="description">{{ $description || 'Welcome to your vuePress-theme-reco site' }}</p>
1313
<p class="huawei" v-if="$themeConfig.huawei === true">
1414
<i class="iconfont reco-huawei" style="color: #fc2d38"></i>
1515
&nbsp;&nbsp;&nbsp;华为,为中华而为之!

components/HomeBlog.vue

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<div class="home-blog" :class="recoShow?'reco-show': 'reco-hide'">
33
<div class="hero" :style="{background: `url(${$frontmatter.bgImage ? $withBase($frontmatter.bgImage) : require('../images/home-bg.jpg')}) center/cover no-repeat`, ...bgImageStyle}">
4-
<h1>{{ data.heroText || $title || '午后南杂' }}</h1>
4+
<h1>{{ homeFrontmatter.heroText || $title || '午后南杂' }}</h1>
55

6-
<p class="description">{{ data.tagline || $description || 'Welcome to your vuePress-theme-reco site' }}</p>
6+
<p class="description">{{ $description || 'Welcome to your vuePress-theme-reco site' }}</p>
77
<p class="huawei" v-if="$themeConfig.huawei === true"><i class="iconfont reco-huawei" style="color: #fc2d38"></i>&nbsp;&nbsp;&nbsp;华为,为中华而为之!</p>
88
</div>
99

@@ -72,47 +72,54 @@ export default {
7272
computed: {
7373
// 时间降序后的博客列表
7474
posts () {
75-
let posts = this.$site.pages
76-
posts = this._filterPostData(posts)
77-
this._sortPostData(posts)
75+
const {
76+
$site: { pages },
77+
_filterPostData,
78+
_sortPostData
79+
} = this
80+
81+
let posts = pages
82+
posts = _filterPostData(posts)
83+
_sortPostData(posts)
84+
7885
return posts
7986
},
80-
8187
// 分类信息
8288
getPagesLength () {
83-
let num = 0
84-
this.$categories.list.map(v => {
85-
num += v.pages.length
86-
})
87-
return num
89+
return this.posts.length
8890
},
89-
data () {
91+
homeFrontmatter () {
9092
return this.$frontmatter
9193
},
92-
9394
actionLink () {
95+
const {
96+
actionLink: link,
97+
actionText: text
98+
} = this.homeFrontmatter
99+
94100
return {
95-
link: this.data.actionLink,
96-
text: this.data.actionText
101+
link,
102+
text
97103
}
98104
},
99-
100105
heroImageStyle () {
101-
return this.data.heroImageStyle || {
106+
return this.homeFrontmatter.heroImageStyle || {
102107
maxHeight: '200px',
103108
margin: '6rem auto 1.5rem'
104109
}
105110
},
106-
107111
bgImageStyle () {
108-
const bgImageStyle = {
112+
const initBgImageStyle = {
109113
height: '350px',
110114
textAlign: 'center',
111115
overflow: 'hidden'
112116
}
113-
return this.data.bgImageStyle ? { ...bgImageStyle, ...this.data.bgImageStyle } : bgImageStyle
114-
},
117+
const {
118+
bgImageStyle
119+
} = this.homeFrontmatter
115120
121+
return bgImageStyle ? { ...initBgImageStyle, ...bgImageStyle } : initBgImageStyle
122+
},
116123
heroHeight () {
117124
return document.querySelector('.hero').clientHeight
118125
}
@@ -142,10 +149,6 @@ export default {
142149
const base = this.$site.base
143150
window.location.href = `${base}tag/?tag=${currentTag}`
144151
},
145-
// 获取时间的数字类型
146-
_getTimeNum (data) {
147-
return parseInt(new Date(data.frontmatter.date).getTime())
148-
},
149152
_setPage (page) {
150153
this.currentPage = page
151154
this.$page.currentPage = page

layouts/TimeLines.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default {
107107
.timeline-wrapper
108108
box-sizing border-box
109109
max-width: 740px;
110-
margin: 4rem auto;
110+
margin: 8rem auto 4rem;
111111
position relative
112112
list-style none
113113
&::after {

mixins/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ export default {
88
},
99
_filterPostData (posts, isTimeline) {
1010
posts = posts.filter(item => {
11-
const { home, date, publish } = item.frontmatter
11+
const { title, frontmatter: { home, date, publish }} = item
1212
return isTimeline === true
13-
? !(home == true || date === undefined || publish === false)
14-
: !(home == true || publish === false)
13+
? !(home == true || title == undefined || date === undefined || publish === false)
14+
: !(home == true || title == undefined || publish === false)
1515
})
1616
return posts
1717
},

0 commit comments

Comments
 (0)