@@ -13,15 +13,15 @@ const findDownload = acquire => {
13
13
const result = { } ;
14
14
15
15
if ( download ) {
16
- result . download = download . href ;
16
+ result . download = download . href ;
17
17
}
18
18
19
19
return result ;
20
20
} ;
21
21
22
22
const findImage = images => {
23
23
const result = { } ;
24
- if ( images && images . length ) {
24
+ if ( images && images . length ) {
25
25
const image = images . pop ( ) ;
26
26
const imageUrl = image . href ;
27
27
@@ -34,25 +34,25 @@ const findImage = images => {
34
34
return result ;
35
35
} ;
36
36
37
- var rewritten = publications
37
+ const rewritten = publications
38
38
. map ( publication => {
39
39
const image = findImage ( publication . images ) ;
40
40
const download = findDownload ( publication . acquire ) ;
41
41
// id is a url, and the actual number is the last part of it:
42
42
const idParts = publication . metadata . id . split ( '/' ) ;
43
43
const id = Number ( idParts [ idParts . length - 2 ] ) ;
44
44
return Object . assign ( { } ,
45
- download , image , omit ( publication . metadata , '\ @type' , 'summary' , 'category' , 'rating' ) ,
45
+ download , image , omit ( publication . metadata , '@type' , 'summary' , 'category' , 'rating' ) ,
46
46
{
47
47
id,
48
48
summary : sanitizeHtml ( publication . metadata . summary ) ,
49
- rating : parseInt ( publication . metadata . rating . ratingValue ) ,
49
+ rating : parseInt ( publication . metadata . rating . ratingValue , 10 ) ,
50
50
// Randomly select books as own:
51
51
isOwn : Math . random ( ) > 0.993
52
52
}
53
53
) ;
54
54
} )
55
- . filter ( publication => publication . download ) ;
55
+ . filter ( publication => publication . download )
56
+ . sort ( ( a , b ) => b . rating - a . rating ) ;
56
57
57
- rewritten . sort ( function ( a , b ) { return b . rating - a . rating ; } ) ;
58
58
process . stdout . write ( JSON . stringify ( rewritten ) ) ;
0 commit comments