unify single user and multi user behaviour
This commit is contained in:
@@ -161,10 +161,16 @@ export async function loadActivity(
|
||||
/**
|
||||
* Load athlete profile. Athlete data is not stored locally yet, so this is
|
||||
* always a network fetch with a graceful null on failure.
|
||||
*
|
||||
* @param baseUrl Site base URL (used to build the default path)
|
||||
* @param athleteUrl Explicit full URL — use for per-user pages in multi-user mode
|
||||
*/
|
||||
export async function loadAthlete(baseUrl: string): Promise<Record<string, unknown> | null> {
|
||||
export async function loadAthlete(
|
||||
baseUrl: string,
|
||||
athleteUrl?: string,
|
||||
): Promise<Record<string, unknown> | null> {
|
||||
try {
|
||||
return await fetchJSON(`${baseUrl}data/athlete.json`);
|
||||
return await fetchJSON(athleteUrl ?? `${baseUrl}data/athlete.json`);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Build-time helpers for reading the BAS shard manifest.
|
||||
* Only import this in .astro frontmatter — it uses Node.js APIs.
|
||||
*/
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join, resolve } from 'node:path';
|
||||
|
||||
export function findDataDir(): string | null {
|
||||
const candidates = [
|
||||
process.env.BINCIO_DATA_DIR,
|
||||
resolve(process.cwd(), 'public', 'data'),
|
||||
resolve(process.cwd(), '..', 'bincio_data'),
|
||||
].filter(Boolean) as string[];
|
||||
return candidates.find(d => {
|
||||
try { readFileSync(join(d, 'index.json')); return true; } catch { return false; }
|
||||
}) ?? null;
|
||||
}
|
||||
|
||||
export interface ShardHandle {
|
||||
handle: string;
|
||||
/** Shard URL as written in the manifest (relative to data root). */
|
||||
url: string;
|
||||
}
|
||||
|
||||
export function readShardHandles(): ShardHandle[] {
|
||||
try {
|
||||
const dataDir = findDataDir();
|
||||
if (!dataDir) return [];
|
||||
const root = JSON.parse(readFileSync(join(dataDir, 'index.json'), 'utf-8'));
|
||||
const shards: Array<{ handle?: string; url: string }> = root.shards ?? [];
|
||||
return shards
|
||||
.filter(s => !!s.handle)
|
||||
.map(s => ({ handle: s.handle!, url: s.url }));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user