Skip to content

Commit 766d18b

Browse files
author
reco_luan
committed
fix: filtering duplicate data
1 parent 46ca784 commit 766d18b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

example/docs/views/other/guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: vuepress-theme-reco
33
date: 2019-04-09
44
categories:
55
- other
6+
- test
67
keys:
78
- '123'
89
---

helpers/postData.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { compareDate } from '@theme/helpers/utils'
22

33
// 过滤博客数据
44
export function filterPosts (posts, isTimeline) {
5-
posts = posts.filter(item => {
5+
posts = posts.filter((item, index) => {
66
const { title, frontmatter: { home, date, publish }} = item
7-
return isTimeline === true
8-
? !(home == true || title == undefined || date === undefined || publish === false)
9-
: !(home == true || title == undefined || publish === false)
7+
// 过滤多个分类时产生的重复数据
8+
if (posts.indexOf(item) !== index) {
9+
return false
10+
} else {
11+
return isTimeline === true
12+
? !(home == true || title == undefined || date === undefined || publish === false)
13+
: !(home == true || title == undefined || publish === false)
14+
}
1015
})
1116
return posts
1217
}

0 commit comments

Comments
 (0)