Adjust filtering to enable filtering by map contents
This commit is contained in:
@@ -6,6 +6,8 @@ const inputDir = './static/mapFiles/yaml';
|
||||
const outputDir = './static/mapFiles/json';
|
||||
const indexFile = './static/map-index.json';
|
||||
|
||||
const noiseRegex = /\s+(single line|junction|jn|junc|jct|gf|north|south|east|west)\.?$/i;
|
||||
|
||||
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
|
||||
|
||||
const mapList = [];
|
||||
@@ -18,12 +20,37 @@ fs.readdirSync(inputDir).forEach((file) => {
|
||||
const fileName = file.replace('.yaml', '.json');
|
||||
fs.writeFileSync(path.join(outputDir, fileName), JSON.stringify(content));
|
||||
|
||||
const contentSet = new Set();
|
||||
|
||||
if (Array.isArray(content.routeDetail)) {
|
||||
content.routeDetail.forEach(item => {
|
||||
if ((item.type === 'junction' || item.type === 'station') && item.name) {
|
||||
let cleanName = item.name;
|
||||
|
||||
// Run the replacement in a loop or twice to catch nested noise
|
||||
// e.g., "Reading West Junction"
|
||||
// Pass 1: "Reading West"
|
||||
// Pass 2: "Reading"
|
||||
let previousName;
|
||||
do {
|
||||
previousName = cleanName;
|
||||
cleanName = cleanName.replace(noiseRegex, '').trim();
|
||||
} while (cleanName !== previousName);
|
||||
|
||||
if (cleanName) {
|
||||
contentSet.add(cleanName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
mapList.push({
|
||||
routeId: content.routeId || null,
|
||||
routeStart: content.routeStart || null,
|
||||
routeEnd: content.routeEnd || null,
|
||||
created: content.created || null,
|
||||
checked: content.checked || null
|
||||
checked: content.checked || null,
|
||||
contents: Array.from(contentSet),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user