mirror of
https://github.com/factbook/factbook.json.git
synced 2026-07-04 19:52:10 +02:00
Index of all files
This commit is contained in:
parent
ca94e2fef5
commit
0599225f0b
2 changed files with 1344 additions and 0 deletions
37
buildIndex.js
Normal file
37
buildIndex.js
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const exclude = ['almanac.md', 'readme.md', 'summary.md', 'buildindex.js', 'package.json', 'meta', '.git', 'countryindex.json'];
|
||||||
|
|
||||||
|
const countryIndex = [];
|
||||||
|
|
||||||
|
const readFile = (dir, file) => {
|
||||||
|
const country = JSON.parse(fs.readFileSync(`${dir}/${file}`).toString());
|
||||||
|
const currentCountry = {
|
||||||
|
directory: dir,
|
||||||
|
filename: file
|
||||||
|
};
|
||||||
|
|
||||||
|
if (country.Government['Country name'] && country.Government['Country name']['conventional short form']) {
|
||||||
|
currentCountry.country = country.Government['Country name']['conventional short form'].text;
|
||||||
|
} else {
|
||||||
|
currentCountry.country = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
countryIndex.push(currentCountry);
|
||||||
|
};
|
||||||
|
|
||||||
|
const readDir = (dir) => {
|
||||||
|
if (!exclude.includes(dir.toLowerCase())) {
|
||||||
|
const continent = fs.readdirSync(dir);
|
||||||
|
continent.forEach((country) => {
|
||||||
|
readFile(dir, country);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const continents = fs.readdirSync('./');
|
||||||
|
continents.forEach((continent) => {
|
||||||
|
readDir(continent);
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.writeFileSync('countryIndex.json', JSON.stringify(countryIndex, null, 2));
|
||||||
1307
countryIndex.json
Normal file
1307
countryIndex.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue