mirror of
https://github.com/factbook/factbook.json.git
synced 2026-07-01 19:49:37 +02:00
Merge b3c41c782b into 1c4de10e5c
This commit is contained in:
commit
1f561fd697
3 changed files with 2432 additions and 0 deletions
1074
alternateCountryIndex.json
Normal file
1074
alternateCountryIndex.json
Normal file
File diff suppressed because it is too large
Load diff
51
buildIndex.js
Normal file
51
buildIndex.js
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const exclude = ['almanac.md', 'readme.md', 'summary.md', 'buildindex.js',
|
||||||
|
'package.json', 'meta', '.git', 'countryindex.json', 'alternatecountryindex.json'];
|
||||||
|
|
||||||
|
const countryIndex = [];
|
||||||
|
const alternateIndex = {};
|
||||||
|
|
||||||
|
// Read files in sub directories and extract country information
|
||||||
|
const readFile = (dir, file) => {
|
||||||
|
const country = JSON.parse(fs.readFileSync(`${dir}/${file}`).toString());
|
||||||
|
const currentCountry = {
|
||||||
|
directory: dir,
|
||||||
|
filename: file
|
||||||
|
};
|
||||||
|
|
||||||
|
currentCountry.country = (country.Government['Country name'] &&
|
||||||
|
country.Government['Country name']['conventional short form']) ?
|
||||||
|
country.Government['Country name']['conventional short form'].text : '';
|
||||||
|
|
||||||
|
countryIndex.push(currentCountry);
|
||||||
|
|
||||||
|
if (!alternateIndex[dir]) {
|
||||||
|
alternateIndex[dir] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
alternateIndex[dir].push({
|
||||||
|
filename: file,
|
||||||
|
country: currentCountry.country
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Find files in sub directories
|
||||||
|
const readDir = (dir) => {
|
||||||
|
if (!exclude.includes(dir.toLowerCase())) {
|
||||||
|
const continent = fs.readdirSync(dir);
|
||||||
|
continent.forEach((country) => {
|
||||||
|
readFile(dir, country);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Read the directories in the root folder
|
||||||
|
const continents = fs.readdirSync('./');
|
||||||
|
continents.forEach((continent) => {
|
||||||
|
readDir(continent);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create output files
|
||||||
|
fs.writeFileSync('countryIndex.json', JSON.stringify(countryIndex, null, 2));
|
||||||
|
fs.writeFileSync('alternateCountryIndex.json', JSON.stringify([alternateIndex], 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