Skip to content

Commit 742e212

Browse files
author
reco_luan
committed
feat: add dark mode(part.9)
Adapt to dark theme Optimize data acquisition
1 parent 720c6db commit 742e212

File tree

11 files changed

+139
-111
lines changed

11 files changed

+139
-111
lines changed

components/FriendLink.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ export default {
127127
display: inline-block;
128128
cursor: pointer;
129129
border-radius: $borderRadius
130-
background: #fff;
131130
font-size: 13px;
132131
box-shadow var(--box-shadow)
133132
transition: all .5s
@@ -148,7 +147,7 @@ export default {
148147
.popup-window
149148
position absolute
150149
display flex
151-
background #ffffff
150+
background var(--background-color)
152151
box-shadow var(--box-shadow)
153152
border-radius $borderRadius
154153
box-sizing border-box

components/Home.vue

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export default {
7979
text-align: center;
8080
h1 {
8181
font-size: 2.5rem;
82+
color: var(--text-color);
8283
}
8384
8485
h1, .description, .action {
@@ -88,7 +89,7 @@ export default {
8889
.description {
8990
font-size: 1.6rem;
9091
line-height: 1.3;
91-
color: lighten($textColor, 20%);
92+
color: var(--text-color);
9293
}
9394
9495
.action-button {
@@ -109,7 +110,7 @@ export default {
109110
}
110111
111112
.features {
112-
border-top: 1px solid $borderColor;
113+
border-top: 1px solid var(--border-color);;
113114
padding: 1.2rem 0;
114115
margin-top: 2.5rem;
115116
display: flex;
@@ -124,16 +125,12 @@ export default {
124125
flex-basis: 30%;
125126
max-width: 30%;
126127
transition: all .5s
128+
color: var(--text-color);
127129
h2 {
128130
font-size: 1.6rem;
129131
font-weight: 500;
130132
border-bottom: none;
131133
padding-bottom: 0;
132-
color: lighten($textColor, 10%);
133-
}
134-
135-
p {
136-
color: lighten($textColor, 20%);
137134
}
138135
139136
&:hover {

components/PageInfo.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
<script>
3636
// 引入时间格式化js文件
37-
import { fromatDateTime } from '@theme/util/formatDate.js'
37+
import { formatDate } from '@theme/util'
3838
3939
export default {
4040
// props: ['pageInfo', 'currentTag'],
@@ -77,10 +77,10 @@ export default {
7777
// 判断时分秒是不是 00:00:00 (如果是用户手动输入的00:00:00也会不显示)
7878
if (h > 0 || m > 0 || s > 0) {
7979
// 时分秒有一个> 0 就说明用户输入一个非 00:00:00 的时分秒
80-
return fromatDateTime(value)
80+
return formatDate(value)
8181
} else {
8282
// 用户没有输入或者输入了 00:00:00
83-
return fromatDateTime(value, 'date')
83+
return formatDate(value, 'yyyy-MM-dd')
8484
}
8585
}
8686
},

example/docs/.vuepress/config.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
]
2525
}
2626
],
27-
type: 'blog',
27+
// type: 'blog',
2828
// 博客设置
2929
blogConfig: {
3030
category: {
@@ -70,7 +70,21 @@ module.exports = {
7070
// }
7171
keyPage: {
7272
keys: ['123456']
73-
}
73+
},
74+
friendLink: [
75+
{
76+
title: '午后南杂',
77+
desc: 'Enjoy when you can, and endure when you must.',
78+
email: '1156743527@qq.com',
79+
link: 'https://www.recoluan.com'
80+
},
81+
{
82+
title: 'vuepress-theme-reco',
83+
desc: 'A simple and beautiful vuepress Blog & Doc theme.',
84+
avatar: "https://vuepress-theme-reco.recoluan.com/icon_vuepress_reco.png",
85+
link: 'https://vuepress-theme-reco.recoluan.com'
86+
},
87+
]
7488
},
7589
markdown: {
7690
lineNumbers: true

example/docs/views/other/installUse.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Installation and reference
3-
date: 2019-04-09
3+
date: 2019-04-09 11:11:11
44
categories:
55
- other
66
---

helpers/postData.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { compareTime } from '@theme/util'
1+
import { compareDate } from '@theme/util'
22

33
// 过滤博客数据
4-
export function filterPostData (posts, isTimeline) {
4+
export function filterPosts (posts, isTimeline) {
55
posts = posts.filter(item => {
66
const { title, frontmatter: { home, date, publish }} = item
77
return isTimeline === true
@@ -12,17 +12,23 @@ export function filterPostData (posts, isTimeline) {
1212
}
1313

1414
// 排序博客数据
15-
export function sortPostData (posts) {
16-
posts.sort((a, b) => {
17-
const aSticky = a.frontmatter.sticky
18-
const bSticky = b.frontmatter.sticky
19-
if (aSticky && bSticky) {
20-
return aSticky == bSticky ? compareTime(a, b) : (aSticky - bSticky)
21-
} else if (aSticky && !bSticky) {
15+
export function sortPostsByStickyAndDate (posts) {
16+
posts.sort((prev, next) => {
17+
const prevSticky = prev.frontmatter.sticky
18+
const nextSticky = next.frontmatter.sticky
19+
if (prevSticky && nextSticky) {
20+
return prevSticky == nextSticky ? compareDate(prev, next) : (prevSticky - nextSticky)
21+
} else if (prevSticky && !nextSticky) {
2222
return -1
23-
} else if (!aSticky && bSticky) {
23+
} else if (!prevSticky && nextSticky) {
2424
return 1
2525
}
26-
return compareTime(a, b)
26+
return compareDate(prev, next)
27+
})
28+
}
29+
30+
export function sortPostsByDate (posts) {
31+
posts.sort((prev, next) => {
32+
return compareDate(prev, next)
2733
})
2834
}

layouts/Category.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import Common from '@theme/components/Common.vue'
3838
import NoteAbstract from '@theme/components/NoteAbstract.vue'
3939
import mixin from '@theme/mixins/index.js'
40-
import { sortPostData, filterPostData } from '@theme/helpers/postData'
40+
import { sortPostsByStickyAndDate, filterPosts } from '@theme/helpers/postData'
4141
4242
export default {
4343
mixins: [mixin],
@@ -55,8 +55,8 @@ export default {
5555
// 时间降序后的博客列表
5656
posts () {
5757
let posts = this.$currentCategories.pages
58-
posts = filterPostData(posts)
59-
sortPostData(posts)
58+
posts = filterPosts(posts)
59+
sortPostsByStickyAndDate(posts)
6060
return posts
6161
},
6262
// 标题只显示分类名称

layouts/Tag.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Common from '@theme/components/Common.vue'
2727
import NoteAbstract from '@theme/components/NoteAbstract.vue'
2828
import TagList from '@theme/components/TagList.vue'
2929
import mixin from '@theme/mixins/index.js'
30-
import { sortPostData, filterPostData } from '@theme/helpers/postData'
30+
import { sortPostsByStickyAndDate, filterPosts } from '@theme/helpers/postData'
3131
3232
export default {
3333
mixins: [mixin],
@@ -46,8 +46,8 @@ export default {
4646
// 时间降序后的博客列表
4747
posts () {
4848
let posts = this.$currentTags.pages
49-
posts = filterPostData(posts)
50-
sortPostData(posts)
49+
posts = filterPosts(posts)
50+
sortPostsByStickyAndDate(posts)
5151
return posts
5252
}
5353
},

layouts/TimeLines.vue

Lines changed: 14 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<Common :sidebar="false" :isComment="false">
44
<ul class="timeline-wrapper">
55
<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">
77
<h3 class="year">{{item.year}}</h3>
88
<ul class="year-wrapper">
99
<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>
1111
<span class="title" @click="go(subItem.path)">{{subItem.title}}</span>
1212
</li>
1313
</ul>
@@ -20,85 +20,33 @@
2020

2121
<script>
2222
import Common from '@theme/components/Common.vue'
23-
import mixin from '@theme/mixins/index.js'
24-
import { filterPostData, sortPostData } from '@theme/helpers/postData'
2523
2624
export default {
27-
mixins: [mixin],
2825
name: 'TimeLine',
2926
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: {
8528
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)
8734
const dateObj = new Date(date)
88-
const year = dateObj.getFullYear()
8935
const mon = dateObj.getMonth() + 1
9036
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: {
9541
go (url) {
9642
this.$router.push({ path: url })
9743
}
9844
}
9945
}
10046
</script>
10147

48+
<style src="../styles/theme.styl" lang="stylus"></style>
49+
10250
<style lang="stylus" scoped>
10351
@require '../styles/wrapper.styl'
10452

mixins/posts.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { filterPostData, sortPostData } from '../helpers/postData'
1+
import { filterPosts, sortPostsByStickyAndDate, sortPostsByDate } from '../helpers/postData'
22

33
export default {
44
computed: {
@@ -11,10 +11,50 @@ export default {
1111
return [...allData, ...currnetData.pages]
1212
}, [])
1313

14-
posts = filterPostData(posts)
15-
sortPostData(posts)
14+
posts = filterPosts(posts)
15+
sortPostsByStickyAndDate(posts)
1616

1717
return posts
18+
},
19+
$recoPostsForTimeline () {
20+
let pages = this.$recoPosts
21+
const formatPages = {}
22+
const formatPagesArr = []
23+
pages = filterPosts(pages, true)
24+
this.pages = pages.length == 0 ? [] : pages
25+
for (let i = 0, length = pages.length; i < length; i++) {
26+
const page = pages[i]
27+
const pageDateYear = dateFormat(page.frontmatter.date, 'year')
28+
if (formatPages[pageDateYear]) formatPages[pageDateYear].push(page)
29+
else {
30+
formatPages[pageDateYear] = [page]
31+
}
32+
}
33+
34+
for (const key in formatPages) {
35+
const data = formatPages[key]
36+
sortPostsByDate(data)
37+
formatPagesArr.unshift({
38+
year: key,
39+
data
40+
})
41+
}
42+
43+
return formatPagesArr
1844
}
1945
}
2046
}
47+
48+
function renderTime (date) {
49+
var dateee = new Date(date).toJSON()
50+
return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').replace(/-/g, '/')
51+
}
52+
function dateFormat (date, type) {
53+
date = renderTime(date)
54+
const dateObj = new Date(date)
55+
const year = dateObj.getFullYear()
56+
const mon = dateObj.getMonth() + 1
57+
const day = dateObj.getDate()
58+
if (type == 'year') return year
59+
else return `${mon}-${day}`
60+
}

0 commit comments

Comments
 (0)