|
3 | 3 | <Common :sidebar="false" :isComment="false"> |
4 | 4 | <ul class="timeline-wrapper"> |
5 | 5 | <li class="desc">Yesterday Once More!</li> |
6 | | - <li v-for="(item, index) in formatPagesArr" :key="index"> |
| 6 | + <li v-for="(item, index) in $recoPostsForTimeline" :key="index"> |
7 | 7 | <h3 class="year">{{item.year}}</h3> |
8 | 8 | <ul class="year-wrapper"> |
9 | 9 | <li v-for="(subItem, subIndex) in item.data" :key="subIndex"> |
10 | | - <span class="date">{{dateFormat(subItem.frontmatter.date)}}</span> |
| 10 | + <span class="date">{{subItem.frontmatter.date | dateFormat}}</span> |
11 | 11 | <span class="title" @click="go(subItem.path)">{{subItem.title}}</span> |
12 | 12 | </li> |
13 | 13 | </ul> |
|
20 | 20 |
|
21 | 21 | <script> |
22 | 22 | import Common from '@theme/components/Common.vue' |
23 | | -import mixin from '@theme/mixins/index.js' |
24 | | -import { filterPostData, sortPostData } from '@theme/helpers/postData' |
25 | 23 |
|
26 | 24 | export default { |
27 | | - mixins: [mixin], |
28 | 25 | name: 'TimeLine', |
29 | 26 | components: { Common }, |
30 | | - data () { |
31 | | - return { |
32 | | - pages: [], |
33 | | - tags: [], |
34 | | - currentTag: '', |
35 | | - currentPage: 1, |
36 | | - formatPages: {}, |
37 | | - formatPagesArr: [] |
38 | | - } |
39 | | - }, |
40 | | - props: { |
41 | | - tag: { |
42 | | - type: String, |
43 | | - default: '' |
44 | | - } |
45 | | - }, |
46 | | - computed: { |
47 | | - trueCurrentTag () { |
48 | | - return this.currentTag |
49 | | - } |
50 | | - }, |
51 | | - created () { |
52 | | - this.getPages() |
53 | | - }, |
54 | | - methods: { |
55 | | - // 根据分类获取页面数据 |
56 | | - getPages (tag) { |
57 | | - let pages = this.$site.pages |
58 | | - // 时间轴不进行制定处理 |
59 | | - pages = filterPostData(pages, true) |
60 | | - // reverse()是为了按时间最近排序排序 |
61 | | - this.pages = pages.length == 0 ? [] : pages |
62 | | - for (let i = 0, length = pages.length; i < length; i++) { |
63 | | - const page = pages[i] |
64 | | - const pageDateYear = this.dateFormat(page.frontmatter.date, 'year') |
65 | | - if (this.formatPages[pageDateYear]) this.formatPages[pageDateYear].push(page) |
66 | | - else { |
67 | | - this.formatPages[pageDateYear] = [page] |
68 | | - } |
69 | | - } |
70 | | -
|
71 | | - for (const key in this.formatPages) { |
72 | | - const data = this.formatPages[key] |
73 | | - sortPostData(data) |
74 | | - this.formatPagesArr.unshift({ |
75 | | - year: key, |
76 | | - data |
77 | | - }) |
78 | | - } |
79 | | - }, |
80 | | - renderTime (date) { |
81 | | - var dateee = new Date(date).toJSON() |
82 | | - return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').replace(/-/g, '/') |
83 | | - }, |
84 | | - // 时间格式化 |
| 27 | + filters: { |
85 | 28 | dateFormat (date, type) { |
86 | | - date = this.renderTime(date) |
| 29 | + function renderTime (date) { |
| 30 | + const dateee = new Date(date).toJSON() |
| 31 | + return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').replace(/-/g, '/') |
| 32 | + } |
| 33 | + date = renderTime(date) |
87 | 34 | const dateObj = new Date(date) |
88 | | - const year = dateObj.getFullYear() |
89 | 35 | const mon = dateObj.getMonth() + 1 |
90 | 36 | const day = dateObj.getDate() |
91 | | - if (type == 'year') return year |
92 | | - else return `${mon}-${day}` |
93 | | - }, |
94 | | - // 跳转 |
| 37 | + return `${mon}-${day}` |
| 38 | + } |
| 39 | + }, |
| 40 | + methods: { |
95 | 41 | go (url) { |
96 | 42 | this.$router.push({ path: url }) |
97 | 43 | } |
98 | 44 | } |
99 | 45 | } |
100 | 46 | </script> |
101 | 47 |
|
| 48 | +<style src="../styles/theme.styl" lang="stylus"></style> |
| 49 | + |
102 | 50 | <style lang="stylus" scoped> |
103 | 51 | @require '../styles/wrapper.styl' |
104 | 52 |
|
|
0 commit comments