Skip to content

Commit

Permalink
Merge pull request #86 from duckduckgo/configurable-region
Browse files Browse the repository at this point in the history
Make region configurable
  • Loading branch information
muodov authored Aug 30, 2024
2 parents 90b90f7 + d2906a1 commit 4770f4d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module.exports = {
categoryPagesPath: './docs/categories/',
hostPath: '/tracker-radar-wiki',
appendTrackerRadarRevisions: [], // in addition to all Git tags, checkout these tracker-radar revisions
region: 'US',
};
5 changes: 2 additions & 3 deletions scripts/generateHistoricalData.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const getListOfJSONPathsFromFolder = require('./helpers/getListOfJSONPathsFromFo

const TRACKER_RADAR_DOMAINS_PATH = path.join(config.trackerRadarRepoPath, '/domains/');
const TRACKER_RADAR_ENTITIES_PATH = path.join(config.trackerRadarRepoPath, '/entities/');
const REGION = 'US';

const domainMap = new Map();
const entityMap = new Map();
Expand Down Expand Up @@ -135,8 +134,8 @@ async function main() {
await git.raw('checkout', tag, '--force');

let domainPath = TRACKER_RADAR_DOMAINS_PATH;
if (fs.existsSync(path.join(domainPath, REGION))) {
domainPath = path.join(domainPath, REGION);
if (fs.existsSync(path.join(domainPath, config.region))) {
domainPath = path.join(domainPath, config.region);
}

const domainFiles = getListOfJSONPathsFromFolder(domainPath);
Expand Down
14 changes: 8 additions & 6 deletions scripts/generateIndexPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ const lastTagInfo = {

let TRACKER_RADAR_DOMAINS_PATH = path.join(config.trackerRadarRepoPath, '/domains/');
const TRACKER_RADAR_ENTITIES_PATH = path.join(config.trackerRadarRepoPath, '/entities/');
const REGION = 'US';

// Backwards compatibility for regions updates
if (fs.existsSync(path.join(TRACKER_RADAR_DOMAINS_PATH, REGION))) {
TRACKER_RADAR_DOMAINS_PATH = path.join(TRACKER_RADAR_DOMAINS_PATH, REGION);
if (fs.existsSync(path.join(TRACKER_RADAR_DOMAINS_PATH, config.region))) {
TRACKER_RADAR_DOMAINS_PATH = path.join(TRACKER_RADAR_DOMAINS_PATH, config.region);
}

const domainFiles = getListOfJSONPathsFromFolder(TRACKER_RADAR_DOMAINS_PATH);
Expand Down Expand Up @@ -89,7 +88,8 @@ const renderData = {
categories: Array.from(categories.values()),
lastTagInfo,
historicDataString,
hostPath: config.hostPath
hostPath: config.hostPath,
region: config.region,
};

try {
Expand All @@ -106,7 +106,8 @@ fs.writeFileSync(path.join(config.basePagesPath, 'index.html'), output);
const top100RenderData = {
domains: domains.slice(0, 100),
entities: entities.slice(0, 100),
hostPath: config.hostPath
hostPath: config.hostPath,
region: config.region,
};

const top100Output = mustache.render(getTemplate('top100'), top100RenderData, getTemplate);
Expand All @@ -122,7 +123,8 @@ const apiHistoryRenderData = {
.map(item => ({api: item.api, entries: item.entries, lastValue: item.entries[item.entries.length - 1].value}))
.sort((a, b) => b.lastValue - a.lastValue),
apiHistoryString,
hostPath: config.hostPath
hostPath: config.hostPath,
region: config.region,
};

const apiHistoryOutput = mustache.render(getTemplate('apiHistory'), apiHistoryRenderData, getTemplate);
Expand Down
5 changes: 2 additions & 3 deletions scripts/generateSearchIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ const getListOfJSONPathsFromFolder = require('./helpers/getListOfJSONPathsFromFo

let TRACKER_RADAR_DOMAINS_PATH = path.join(config.trackerRadarRepoPath, '/domains/');
const TRACKER_RADAR_ENTITIES_PATH = path.join(config.trackerRadarRepoPath, '/entities/');
const REGION = 'US';

// Backwards compatibility for regions updates
if (fs.existsSync(path.join(TRACKER_RADAR_DOMAINS_PATH, REGION))) {
TRACKER_RADAR_DOMAINS_PATH = path.join(TRACKER_RADAR_DOMAINS_PATH, REGION);
if (fs.existsSync(path.join(TRACKER_RADAR_DOMAINS_PATH, config.region))) {
TRACKER_RADAR_DOMAINS_PATH = path.join(TRACKER_RADAR_DOMAINS_PATH, config.region);
}

const domainFiles = getListOfJSONPathsFromFolder(TRACKER_RADAR_DOMAINS_PATH);
Expand Down
9 changes: 6 additions & 3 deletions scripts/generateSubpages.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ const escapeEntityName = require('./helpers/escapeEntityName');

let TRACKER_RADAR_DOMAINS_PATH = path.join(config.trackerRadarRepoPath, '/domains/');
const TRACKER_RADAR_ENTITIES_PATH = path.join(config.trackerRadarRepoPath, '/entities/');
const REGION = 'US';

// Backwards compatibility for regions updates
if (fs.existsSync(path.join(TRACKER_RADAR_DOMAINS_PATH, REGION))) {
TRACKER_RADAR_DOMAINS_PATH = path.join(TRACKER_RADAR_DOMAINS_PATH, REGION);
if (fs.existsSync(path.join(TRACKER_RADAR_DOMAINS_PATH, config.region))) {
TRACKER_RADAR_DOMAINS_PATH = path.join(TRACKER_RADAR_DOMAINS_PATH, config.region);
}

const fingerprintTexts = [
Expand Down Expand Up @@ -140,6 +139,8 @@ domainFiles.forEach(({file, resolvedPath}) => {
sites: res.sites
};
}).sort((a, b) => b.sites - a.sites);

data.region = config.region;

const output = mustache.render(getTemplate('domain'), data, getTemplate);

Expand Down Expand Up @@ -203,6 +204,7 @@ entityFiles.forEach(({file, resolvedPath}) => {
}

data.hostPath = config.hostPath;
data.region = config.region;

const output = mustache.render(getTemplate('entity'), data, getTemplate);

Expand Down Expand Up @@ -238,6 +240,7 @@ Array.from(categories.values()).forEach(data => {
}

data.hostPath = config.hostPath;
data.region = config.region;

const output = mustache.render(getTemplate('category'), data, getTemplate);

Expand Down
3 changes: 1 addition & 2 deletions scripts/helpers/getListOfJSONPathsFromFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ module.exports = function getListOfJSONPathsFromFolder(folderPath) {
return true;
}

console.trace('Skipping path', resolvedPath, stat);
process.exit(1);
console.log('Skipping path', resolvedPath, stat);
return false;
})
// map file names to full paths
Expand Down

0 comments on commit 4770f4d

Please sign in to comment.