Skip to content

Commit e62ffee

Browse files
committed
1 parent b37f8da commit e62ffee

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

scripts/get-software.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const crypto = require('crypto');
12
const fs = require('fs');
23
const path = require('path');
34
const axios = require('axios');
@@ -22,6 +23,13 @@ const absoluteUrl = (url, repo) => {
2223
}
2324
};
2425

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+
2533
const addSlug = (software) => ({ ...software, slug: software.id });
2634
const addAliases = (software) => {
2735
const aliases = [normalizeRepoUrl(software.url), ...software.aliases.map(a => normalizeRepoUrl(a))];
@@ -58,7 +66,7 @@ function toElasticSearchBulkFile(software, filename) {
5866
software
5967
.map(software => addSlug(software))
6068
.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)) } })
6270
.forEach(s => {
6371
const metadata = {
6472
'index': {
@@ -90,18 +98,18 @@ async function run() {
9098
.map(software => addAliases(addSlug(software)))
9199
.map(software => addSlug(software))
92100
.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)) } }));
94102

95103
data.forEach(software => {
96-
Object.keys(software.publiccode.description).forEach(lang => {
104+
Object.keys(software.publiccode.description).forEach((lang) => {
97105
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+
});
100108
});
101109

102110
// Remove the "url" key as it's used by Jekyll to hold the generated page's URL
103111
// 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);
105113

106114
fs.writeFileSync('_data/crawler/software.yml', yaml.dump(jekyll));
107115
}

0 commit comments

Comments
 (0)