This commit is contained in:
Rizky 2024-03-10 18:36:06 +07:00
parent 5da491fda6
commit bd36ea0156
4 changed files with 54 additions and 34 deletions

File diff suppressed because one or more lines are too long

View File

@ -18,6 +18,7 @@ export const ViGlobal = {
mode: "old" as "old" | "vsc",
},
},
site_url: null as unknown as URL,
script: {
init_local_effect: undefined as undefined | Record<string, boolean>,
},

View File

@ -46,6 +46,24 @@ export const Vi: FC<{
vi.entry = entry;
vi.on_preload = on_preload;
w.siteurl = (pathname: string) => {
if (vi.site.api_url) {
if (!vi.site_url) {
vi.site_url = new URL(vi.site.api_url);
}
}
if (vi.site_url) {
const u = vi.site_url;
let path = pathname;
if (!path.startsWith("/")) {
path = "/" + path;
}
return `${u.protocol}//${u.hostname}${path}`;
}
return pathname;
};
w.isMobile = mode === "mobile";
w.isDesktop = mode === "desktop";
w.preload = (_urls: string | string[]) => {

View File

@ -14,6 +14,7 @@ export const baseTypings = `
const isLayout: boolean;
const isMobile: boolean;
const isDesktop: boolean;
const siteurl: (path:string) => string;
const preload: (urls: string | string[]) => ReactNode;
const apiHeaders: Record<string, any>;
const navigate: (url: string) => void;