mirror of
https://github.com/factbook/factbook.json.git
synced 2026-07-01 19:49:37 +02:00
Alternate index and code comments
This commit is contained in:
parent
2d44771eb7
commit
b3c41c782b
2 changed files with 1092 additions and 2 deletions
|
|
@ -1,9 +1,12 @@
|
|||
const fs = require('fs');
|
||||
|
||||
const exclude = ['almanac.md', 'readme.md', 'summary.md', 'buildindex.js', 'package.json', 'meta', '.git', 'countryindex.json'];
|
||||
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 = {
|
||||
|
|
@ -16,8 +19,18 @@ const readFile = (dir, file) => {
|
|||
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);
|
||||
|
|
@ -27,9 +40,12 @@ const readDir = (dir) => {
|
|||
}
|
||||
};
|
||||
|
||||
// Read the directories in the root folder
|
||||
const continents = fs.readdirSync('./');
|
||||
continents.forEach((continent) => {
|
||||
readDir(continent);
|
||||
});
|
||||
|
||||
fs.writeFileSync('countryIndex.json', JSON.stringify(countryIndex, null, 2));
|
||||
// Create output files
|
||||
fs.writeFileSync('countryIndex.json', JSON.stringify(countryIndex, null, 2));
|
||||
fs.writeFileSync('alternateCountryIndex.json', JSON.stringify([alternateIndex], null, 2));
|
||||
Loading…
Add table
Add a link
Reference in a new issue