1
+ const crypto = require ( 'crypto' ) ;
1
2
const fs = require ( 'fs' ) ;
2
3
const path = require ( 'path' ) ;
3
4
const axios = require ( 'axios' ) ;
@@ -22,6 +23,13 @@ const absoluteUrl = (url, repo) => {
22
23
}
23
24
} ;
24
25
26
+ const assetsImage = ( url ) => {
27
+ const hash = crypto . createHash ( 'sha1' ) . update ( url , 'utf8' ) . digest ( 'hex' ) ;
28
+ const ext = path . extname ( url ) ;
29
+
30
+ return `${ hash . slice ( 0 , 2 ) } /${ hash . slice ( 2 ) } ${ ext } ` ;
31
+ } ;
32
+
25
33
const addSlug = ( software ) => ( { ...software , slug : software . id } ) ;
26
34
const addAliases = ( software ) => {
27
35
const aliases = [ normalizeRepoUrl ( software . url ) , ...software . aliases . map ( a => normalizeRepoUrl ( a ) ) ] ;
@@ -58,7 +66,7 @@ function toElasticSearchBulkFile(software, filename) {
58
66
software
59
67
. map ( software => addSlug ( software ) )
60
68
. map ( software => addPubliccodeDict ( software ) )
61
- . map ( software => ( { ...software , publiccode : { ...software . publiccode , logo : absoluteUrl ( software . publiccode . logo , software . url ) } } ) )
69
+ . map ( software => ( { ...software , publiccode : { ...software . publiccode , logo : assetsImage ( absoluteUrl ( software . publiccode . logo , software . url ) ) } } )
62
70
. forEach ( s => {
63
71
const metadata = {
64
72
'index' : {
@@ -90,18 +98,18 @@ async function run() {
90
98
. map ( software => addAliases ( addSlug ( software ) ) )
91
99
. map ( software => addSlug ( software ) )
92
100
. map ( software => addPubliccodeDict ( software ) )
93
- . map ( software => ( { ...software , publiccode : { ...software . publiccode , logo : absoluteUrl ( software . publiccode . logo , software . url ) } } ) ) ;
101
+ . map ( software => ( { ...software , publiccode : { ...software . publiccode , logo : assetsImage ( absoluteUrl ( software . publiccode . logo , software . url ) ) } } ) ) ;
94
102
95
103
data . forEach ( software => {
96
- Object . keys ( software . publiccode . description ) . forEach ( lang => {
104
+ Object . keys ( software . publiccode . description ) . forEach ( ( lang ) => {
97
105
const desc = software . publiccode . description [ lang ] ;
98
- software . publiccode . description [ lang ] . screenshots = desc . screenshots ?. map ( ss => absoluteUrl ( ss , software . url ) ) ;
99
- } )
106
+ software . publiccode . description [ lang ] . screenshots = desc . screenshots ?. map ( ( ss ) => assetsImage ( absoluteUrl ( ss , software . url ) ) ) ;
107
+ } ) ;
100
108
} ) ;
101
109
102
110
// Remove the "url" key as it's used by Jekyll to hold the generated page's URL
103
111
// and Searchyll uses it to compare against when the ignore: options are set in _config.yml.
104
- const jekyll = data . map ( ( { url, ...rest } ) => rest )
112
+ const jekyll = data . map ( ( { url, ...rest } ) => rest ) ;
105
113
106
114
fs . writeFileSync ( '_data/crawler/software.yml' , yaml . dump ( jekyll ) ) ;
107
115
}
0 commit comments