Files
open.neuroinf.jp/src/siteData.ts
T
orrisroot e93014bcea feat: migrate from Create React App to Vite
Rebuild the site on the stack the other converted sites share: Vite 8,
React 19, TypeScript 7, react-router 8, Biome and sanitize.css, with the
site data moved out of the bundle into static-contents/.

- base the database and pico code on the other converted sites,
  keeping this site's layout, pages and item fields
- read file timestamps as Unix seconds in the file and license views
- serve all module data from modules/, redirecting the old download and
  /database/file URLs
- keep form controls on white
- track page views with GA4
2026-09-14 17:38:48 +09:00

29 lines
1.1 KiB
TypeScript

import ky from 'ky';
import Config from './config';
import type { IndexesData } from './database/lib/IndexUtil';
import type { PicoConfigData } from './pico/lib/PicoUtils';
/**
* Data converted from the original XOOPS modules. It is served with the rest of
* static-contents/ rather than bundled, so it is fetched once at start up and
* handed to the singletons before the app renders.
*/
export interface SiteData {
tree: IndexesData;
pico: PicoConfigData[];
}
// ky hands the URL to fetch()/Request, which rejects bare relative paths.
const resolve = (path: string): string => new URL(Config.BASE_URL + path, window.location.href).toString();
export const loadSiteData = async (): Promise<SiteData> => {
const [tree, pico] = await Promise.all([
ky.get(resolve('/modules/xoonips/tree.json')).json<IndexesData>(),
// Each pico module keeps its own index next to its pages.
Promise.all(
Config.PICO_MODULES.map((name) => ky.get(resolve(`/modules/${name}/config.json`)).json<PicoConfigData>())
),
]);
return { tree, pico };
};