fixing stuff after splitting jsons
This commit is contained in:
@@ -186,17 +186,24 @@ export async function loadTimeseries(
|
||||
): Promise<Timeseries | null> {
|
||||
try {
|
||||
let url: string;
|
||||
// Strip the leading "activities/" from timeseriesUrl so we can append it
|
||||
// to whatever directory the detail JSON lives in.
|
||||
const filename = timeseriesUrl.replace(/^activities\//, '');
|
||||
|
||||
if (timeseriesUrl.startsWith('http')) {
|
||||
url = timeseriesUrl;
|
||||
} else if (detailUrl.startsWith('http')) {
|
||||
// detailUrl is absolute — resolve timeseries relative to its directory
|
||||
// absolute detailUrl (browser shard resolution) → same directory
|
||||
const dir = detailUrl.substring(0, detailUrl.lastIndexOf('/') + 1);
|
||||
// timeseriesUrl is "activities/id.timeseries.json" — strip leading "activities/"
|
||||
// because dir already ends with "activities/"
|
||||
const filename = timeseriesUrl.replace(/^activities\//, '');
|
||||
url = `${dir}${filename}`;
|
||||
} else {
|
||||
url = `${baseUrl}data/${timeseriesUrl}`;
|
||||
// relative detailUrl — may be plain ("activities/{id}.json", single-user)
|
||||
// or prefixed ("dave/_merged/activities/{id}.json", multi-user SSG prop).
|
||||
// In both cases, resolve the timeseries file from the same directory.
|
||||
const dir = detailUrl.includes('/')
|
||||
? detailUrl.substring(0, detailUrl.lastIndexOf('/') + 1)
|
||||
: '';
|
||||
url = `${baseUrl}data/${dir}${filename}`;
|
||||
}
|
||||
return await fetchJSON<Timeseries>(url);
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user