This commit is contained in:
Martin 2017-05-12 07:02:08 +00:00 committed by GitHub
commit 1f561fd697
3 changed files with 2432 additions and 0 deletions

1074
alternateCountryIndex.json Normal file

File diff suppressed because it is too large Load diff

51
buildIndex.js Normal file
View 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

File diff suppressed because it is too large Load diff