mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-11-28 18:28:04 -08:00
35 lines
953 B
JavaScript
35 lines
953 B
JavaScript
// Data loader utility for fetching JSON data with cache-busting
|
|
|
|
// Load data with version-based cache busting
|
|
const loadData = async (dataType, version = '') => {
|
|
try {
|
|
// relative, so it also works when the site is hosted under a subpath
|
|
const url = `data/${dataType}.json${version ? `?_=${version}` : ''}`;
|
|
const response = await fetch(url);
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to load ${dataType}: ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
return data;
|
|
} catch (error) {
|
|
console.error(`Error loading ${dataType}:`, error);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
// start off loading the data
|
|
const version = typeof OVERRIDES !== 'undefined' && OVERRIDES.VERSION ? OVERRIDES.VERSION : '';
|
|
|
|
const TravelCities = loadData('travelcities', version);
|
|
const RegionalCities = loadData('regionalcities', version);
|
|
const StationInfo = loadData('stations', version);
|
|
|
|
export {
|
|
TravelCities,
|
|
RegionalCities,
|
|
StationInfo,
|
|
};
|