Skip to content

Commit c3faf8c

Browse files
recocopliotzsw
authored andcommitted
refactor: update version of @vuepress/plugin-blog
1. The plugin was refactored after the1.0.0-alpha.49, but the theme was not updated. 2. In this update, the plug-in version is updated, and the data acquisition method of category and tag is changed accordingly.
1 parent 8884db8 commit c3faf8c

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

components/HomeBlog.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<h6>文章</h6>
2424
</div>
2525
<div>
26-
<h3>{{$tags.length}}</h3>
26+
<h3>{{$tags.list.length}}</h3>
2727
<h6>标签</h6>
2828
</div>
2929
</div>
@@ -33,7 +33,7 @@
3333
<li class="category-item" v-for="(item, index) in this.$categories.list" :key="index">
3434
<router-link :to="item.path">
3535
<span class="category-name">{{ item.name }}</span>
36-
<span class="post-num">{{ item.posts.length }}</span>
36+
<span class="post-num">{{ item.pages.length }}</span>
3737
</router-link>
3838
</li>
3939
</ul>
@@ -108,7 +108,7 @@ export default {
108108
getPagesLength () {
109109
let num = 0
110110
this.$categories.list.map(v => {
111-
num += v.posts.length
111+
num += v.pages.length
112112
})
113113
return num
114114
},

components/TimeLine.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export default {
8383
const year = dateObj.getFullYear()
8484
const mon = dateObj.getMonth() + 1
8585
const day = dateObj.getDate()
86-
console.log(dateObj)
8786
if (type == 'year') return year
8887
else return `${mon}-${day}`
8988
},

index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,23 @@ module.exports = (options, ctx) => ({
2323
'@vuepress-reco/vuepress-plugin-screenfull',
2424
'@vuepress/active-header-links',
2525
['@vuepress/plugin-blog', {
26-
permalink: '/:regular'
26+
permalink: '/:regular',
27+
frontmatters: [
28+
{
29+
id: 'tags',
30+
keys: ['tags'],
31+
path: '/tag/',
32+
layout: 'Tags',
33+
scopeLayout: 'Tag'
34+
},
35+
{
36+
id: 'categories',
37+
keys: ['categories'],
38+
path: '/categories/',
39+
layout: 'Categories',
40+
scopeLayout: 'Category'
41+
},
42+
],
2743
}],
2844
'@vuepress/search',
2945
'@vuepress/plugin-nprogress',

layouts/Category.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<ul class="category-wrapper">
77
<li
88
class="category-item"
9-
:class="title.trim() == item.name ? 'active': ''"
9+
:class="title == item.name ? 'active': ''"
1010
v-for="(item, index) in this.$categories.list"
1111
:key="index">
1212
<router-link :to="item.path">
1313
<span class="category-name">{{ item.name }}</span>
14-
<span class="post-num">{{ item.posts.length }}</span>
14+
<span class="post-num">{{ item.pages.length }}</span>
1515
</router-link>
1616
</li>
1717
</ul>
@@ -51,7 +51,7 @@ export default {
5151
computed: {
5252
// 时间降序后的博客列表
5353
posts () {
54-
const posts = this.$category.posts
54+
const posts = this.$currentCategories.pages
5555
posts.sort((a, b) => {
5656
return this._getTimeNum(b) - this._getTimeNum(a)
5757
})
@@ -60,7 +60,7 @@ export default {
6060
},
6161
// 标题只显示分类名称
6262
title () {
63-
return this.$frontmatter.title.split('|')[0]
63+
return this.$currentCategories.key
6464
}
6565
},
6666

layouts/Tags.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default {
6161
6262
created () {
6363
if (this.$tags.list.length > 0) {
64+
const currentTag = this.$route.query.tag ? this.$route.query.tag : this.currentTag
6465
const tags = this.$tags.list
6566
tags.map(item => {
6667
const color = this._tagColor()
@@ -69,7 +70,7 @@ export default {
6970
})
7071
this.tags = [{ name: '全部', color: this._tagColor() }, ...tags]
7172
72-
this.getPagesByTags(this.currentTag)
73+
this.getPagesByTags(currentTag)
7374
}
7475
},
7576
@@ -79,10 +80,6 @@ export default {
7980
8081
methods: {
8182
82-
initData (currentTag) {
83-
this.getPagesByTags(currentTag)
84-
},
85-
8683
async tagClick (currentTag) {
8784
await this.getPagesByTags(currentTag)
8885
window.scrollTo(0, 0)
@@ -94,7 +91,7 @@ export default {
9491
9592
let posts = []
9693
if (currentTag !== '全部') {
97-
posts = this.$tags.map[currentTag].posts
94+
posts = this.$tags.map[currentTag].pages
9895
posts.sort((a, b) => {
9996
return this._getTimeNum(b) - this._getTimeNum(a)
10097
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@vuepress-reco/vuepress-plugin-back-to-top": "^1.0.3",
3030
"@vuepress-reco/vuepress-plugin-pagation": "^1.0.3",
3131
"@vuepress-reco/vuepress-plugin-screenfull": "^1.0.0",
32-
"@vuepress/plugin-blog": "1.0.0-alpha.49",
32+
"@vuepress/plugin-blog": "1.3.0",
3333
"leancloud-storage": "3.13.2",
3434
"valine": "1.3.6",
3535
"vue-click-outside": "1.0.7"

0 commit comments

Comments
 (0)