@@ -4,20 +4,100 @@ const cheerio = require('cheerio');
4
4
module . exports = async ( ctx ) => {
5
5
const response = await got ( {
6
6
method : 'get' ,
7
+ // sudo apachectl start 本地服务器
8
+ // web根目录在:/Library/WebServer/Documents
9
+ // url: 'http://localhost/beta.html',
10
+ // url: 'http://localhost/Released.html',
7
11
url : 'https://www.sketch.com/beta/' ,
8
12
} ) ;
9
13
const data = response . data ;
10
14
const $ = cheerio . load ( data ) ;
11
- const titledata = $ ( '.update-details h4' )
15
+ // 判断是否已发布
16
+ const releaseString = $ ( '.wrapper' )
12
17
. first ( )
13
- . html ( ) ;
14
- // const versiondata=Number(titledata.substr(-2));
15
- const content = $ ( '.update-details' ) . html ( ) ;
18
+ . find ( 'h1' )
19
+ . text ( )
20
+ . substr ( - 8 ) ;
21
+ // console.log(releaseString);
22
+ let isrelease = 0 ;
23
+ if ( releaseString === 'released' ) {
24
+ isrelease = 1 ;
25
+ } else {
26
+ isrelease = 0 ;
27
+ }
28
+ // console.log(isrelease);
16
29
17
- ctx . state . data = {
18
- title : titledata ,
19
- link : response . url ,
20
- description : content ,
21
- allowEmpty : true ,
22
- } ;
30
+ const list = $ ( '.wrapper' ) . first ( ) ;
31
+ // sketch update 提供的时间 年月反了.要重新调整
32
+ const pubday = list
33
+ . find ( '.heading-caption time' )
34
+ . attr ( 'datetime' )
35
+ . substr ( 0 , 2 ) ;
36
+ const pubmonth = list
37
+ . find ( '.heading-caption time' )
38
+ . attr ( 'datetime' )
39
+ . substr ( 3 , 2 ) ;
40
+ const pubyear = list
41
+ . find ( '.heading-caption time' )
42
+ . attr ( 'datetime' )
43
+ . substr ( - 4 ) ;
44
+ const pubdateString = pubmonth + `-` + pubday + `-` + pubyear ;
45
+
46
+ if ( isrelease === 1 ) {
47
+ // console.log("已经发布到正式版 ");
48
+ ctx . state . data = {
49
+ title : `Sketch Beta` ,
50
+ link : response . url ,
51
+ description : 'Sketch is a design toolkit built to help you create your best work — from your earliest ideas, through to final artwork.' ,
52
+ image : 'https://cdn.sketchapp.com/assets/components/block-buy/logo.png' ,
53
+
54
+ item :
55
+ list &&
56
+ list
57
+ . map ( ( index , item ) => {
58
+ item = $ ( item ) ;
59
+ return {
60
+ title : `${ item
61
+ . find ( 'h1' )
62
+ . first ( )
63
+ . text ( ) } `,
64
+ description : `${ item . html ( ) } ` ,
65
+ link : `https://www.sketch.com/updates/` ,
66
+ pubDate : new Date ( pubdateString ) . toLocaleDateString ( ) ,
67
+ } ;
68
+ } )
69
+ . get ( ) ,
70
+ } ;
71
+ } else {
72
+ // console.log("Beta版本发布 ");
73
+ const content = $ ( '.update-details' ) . html ( ) ;
74
+ ctx . state . data = {
75
+ title : `Sketch Beta` ,
76
+ link : response . url ,
77
+ description : 'Sketch is a design toolkit built to help you create your best work — from your earliest ideas, through to final artwork.' ,
78
+ image : 'https://cdn.sketchapp.com/assets/components/block-buy/logo.png' ,
79
+
80
+ item :
81
+ list &&
82
+ list
83
+ . map ( ( index , item ) => {
84
+ item = $ ( item ) ;
85
+ return {
86
+ title : `${ item
87
+ . find ( 'h1' )
88
+ . first ( )
89
+ . text ( ) }
90
+ - ${ item
91
+ . find ( 'small.heading-caption' )
92
+ . first ( )
93
+ . text ( )
94
+ . substr ( 16 , 2 ) } `,
95
+ description : content ,
96
+ link : `https://www.sketch.com/beta/` ,
97
+ pubDate : new Date ( pubdateString ) . toLocaleDateString ( ) ,
98
+ } ;
99
+ } )
100
+ . get ( ) ,
101
+ } ;
102
+ }
23
103
} ;
0 commit comments