Skip to content

Commit 81f9edf

Browse files
committed
Prepare colors in source file
1 parent 96eeb18 commit 81f9edf

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

map/prepare.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require('fs');
2+
const crypto = require('crypto');
23

34
const data = fs.readFileSync('../stac/catalog.json', 'utf8');
45
const json = JSON.parse(data);
@@ -52,3 +53,13 @@ Promise.allSettled(promises)
5253
fs.writeFileSync('sources.js', `export default ${JSON.stringify(results, null, 2)}`);
5354
})
5455
.catch(console.error);
56+
57+
function strToColor(str) {
58+
return '#' + crypto.createHash('md5').update(str).digest('hex').substring(0, 6);
59+
}
60+
const hcat = fs.readFileSync('../code/hcat/HCAT3.csv', 'utf8');
61+
const hcatMapping = hcat.split('\n').slice(1).map((line) => {
62+
const [name, code] = line.split(',');
63+
return { name, code, color: strToColor(code || "") };
64+
});
65+
fs.writeFileSync('crop/codes.js', `export const hcat = ${JSON.stringify(hcatMapping, null, 2)}`);

0 commit comments

Comments
 (0)