forked from cnguu/vuepress-theme-yur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
YurBanner.vue
147 lines (144 loc) · 5.05 KB
/
YurBanner.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<template>
<div id="yur-banner">
<div class="banner-page">
<div class="img-wrapper">
<a-skeleton active :loading="loading">
<img :src="banner" :alt="title">
</a-skeleton>
</div>
<div class="text-wrapper">
<div class="title-line-wrapper">
<div class="title-line"></div>
</div>
<h1>{{ title }}</h1>
<p>
<span class="subtitle">{{ subtitle }}</span>
</p>
<div v-if="bannerButtons.length" class="banner-btn-group">
<router-link v-for="item in bannerButtons" :to="item.link">
<a-button :type="item.type">{{item.text}}</a-button>
</router-link>
</div>
</div>
</div>
<div class="page-1">
<div class="page">
<h2>
<span>最近更新</span>
</h2>
<a-row v-if="updatedPosts.length">
<a-col v-for="post in updatedPosts"
:key="post.path"
:xs="24"
:md="8"
>
<router-link :to="post.path">
<div class="banner">
<a-skeleton active :loading="loading">
<img :src="$withBase(post.frontmatter.banner)" :alt="post.title">
</a-skeleton>
</div>
<h3>
<span>{{ post.title }}</span>
</h3>
</router-link>
</a-col>
</a-row>
</div>
</div>
<div class="page-2">
<div class="page">
<YurTagCloud :is-home="true"/>
</div>
</div>
</div>
</template>
<script>
import {init} from 'ityped';
import YurTagCloud from '@theme/components/YurTagCloud';
import {getTimeOut} from '../util';
export default {
components: {YurTagCloud},
props: {},
data() {
return {
loading: true,
title: '凉风有信',
description: '责难无以成事',
subtitle: '责难无以成事',
banner: require('../media/images/banner.png'),
bannerButtons: [
{text: '阅读文章', link: '/posts/?page=1&pageSize=12', type: 'primary'},
{text: '了解主人', link: '/about', type: 'default'},
],
ityped: null,
updatedPosts: [],
};
},
beforeCreate() {
},
created() {
this.initConfig();
setTimeout(() => {
this.$store.dispatch('changeSetting', {
key: 'curtain',
value: false,
});
document.getElementsByTagName('body')[0].style.overflow = 'unset';
}, getTimeOut(this.$store.state.settings.consoleTime));
},
beforeMount() {
},
mounted() {
if (this.ityped) {
this.subtitle = '';
init('span.subtitle', Object.assign({}, {
strings: [this.description],
}, this.ityped));
}
this.loading = false;
},
beforeUpdate() {
},
updated() {
},
beforeDestroy() {
},
destroyed() {
},
watch: {},
computed: {},
methods: {
initConfig() {
const {title, description} = this.$site;
const {banner, bannerButtons, ityped} = this.$themeConfig;
if (title) {
this.title = title;
}
if (description) {
this.description = description;
}
if (banner) {
this.banner = this.$withBase(banner);
}
if (bannerButtons) {
this.bannerButtons = bannerButtons;
}
if (ityped) {
this.ityped = ityped;
}
this.updatedPosts = Array.from(this.$posts);
if (this.updatedPosts.length) {
this.updatedPosts.sort((a, b) => {
let a_update_date = a.frontmatter.hasOwnProperty('update_date') ? new Date(a.frontmatter.update_date).getTime() : 0;
let b_update_date = b.frontmatter.hasOwnProperty('update_date') ? new Date(b.frontmatter.update_date).getTime() : 0;
return b_update_date - a_update_date;
});
this.updatedPosts = this.updatedPosts.slice(0, 3);
}
},
},
};
</script>
<style lang="less" scoped>
</style>