@@ -5,59 +5,10 @@ export default {
55 const index = Math . floor ( Math . random ( ) * tagColorArr . length )
66 return tagColorArr [ index ]
77 } ,
8- _filterPostData ( posts , isTimeline ) {
9- posts = posts . filter ( item => {
10- const { title, frontmatter : { home, date, publish } } = item
11- return isTimeline === true
12- ? ! ( home == true || title == undefined || date === undefined || publish === false )
13- : ! ( home == true || title == undefined || publish === false )
14- } )
15- return posts
16- } ,
17- _sortPostData ( posts ) {
18- posts . sort ( ( a , b ) => {
19- const aSticky = a . frontmatter . sticky
20- const bSticky = b . frontmatter . sticky
21- if ( aSticky && bSticky ) {
22- return aSticky == bSticky ? this . _compareTime ( a , b ) : ( aSticky - bSticky )
23- } else if ( aSticky && ! bSticky ) {
24- return - 1
25- } else if ( ! aSticky && bSticky ) {
26- return 1
27- }
28- return this . _compareTime ( a , b )
29- } )
30- } ,
318 // 获取时间的数字类型
329 _getTimeNum ( date ) {
3310 return parseInt ( new Date ( date . frontmatter . date ) . getTime ( ) )
3411 } ,
35- // 比对时间
36- _compareTime ( a , b ) {
37- return this . _getTimeNum ( b ) - this . _getTimeNum ( a )
38- } ,
39- // 获取博客数据
40- _getPostData ( ) {
41- return new Promise ( resolve => {
42- if ( ! this . $themeConfig . posts ) {
43- const {
44- $categories : { list : articles } ,
45- _filterPostData,
46- _sortPostData
47- } = this
48-
49- let posts = articles . reduce ( ( allData , currnetData ) => {
50- return [ ...allData , ...currnetData . pages ]
51- } , [ ] )
52-
53- posts = _filterPostData ( posts )
54- _sortPostData ( posts )
55-
56- this . $themeConfig . posts = posts
57- resolve ( posts )
58- }
59- } )
60- } ,
6112 // 获取当前页码
6213 _getStoragePage ( ) {
6314 const path = window . location . pathname
@@ -76,4 +27,4 @@ export default {
7627 sessionStorage . setItem ( 'currentPage' , JSON . stringify ( { page, path } ) )
7728 }
7829 }
79- }
30+ }
0 commit comments