mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui-next: inject route map
This commit is contained in:
3 files changed
+6
-1
No files matched your search
@@ -724,6 +724,7 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
|
|||||||
}
|
}
|
||||||
this.registry[name] = HandlerClass;
|
this.registry[name] = HandlerClass;
|
||||||
this.registrationCount[name]++;
|
this.registrationCount[name]++;
|
||||||
|
this.routeMap[routeName] = path as string;
|
||||||
|
|
||||||
const Checker = (args) => {
|
const Checker = (args) => {
|
||||||
let perm: bigint;
|
let perm: bigint;
|
||||||
@@ -776,6 +777,7 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
|
|||||||
this.ctx.effect(() => () => {
|
this.ctx.effect(() => () => {
|
||||||
this.registrationCount[name]--;
|
this.registrationCount[name]--;
|
||||||
if (!this.registrationCount[name]) delete this.registry[name];
|
if (!this.registrationCount[name]) delete this.registry[name];
|
||||||
|
delete this.routeMap[routeName];
|
||||||
dispose();
|
dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import c2k from 'koa2-connect/ts';
|
|||||||
import { createServer, type Plugin } from 'vite';
|
import { createServer, type Plugin } from 'vite';
|
||||||
import { serializer } from '@hydrooj/framework';
|
import { serializer } from '@hydrooj/framework';
|
||||||
import { Context } from 'hydrooj';
|
import { Context } from 'hydrooj';
|
||||||
|
import type { PageData } from './src/context/pageData';
|
||||||
|
|
||||||
const INJECT_MARKER = '<!-- __HYDRO_INJECTION__DO_NOT_REMOVE_THIS__ -->';
|
const INJECT_MARKER = '<!-- __HYDRO_INJECTION__DO_NOT_REMOVE_THIS__ -->';
|
||||||
const buildInject = (str: string) => `<script id="__HYDRO_INJECTION__" type="application/json">${str}</script>`;
|
const buildInject = (str: string) => `<script id="__HYDRO_INJECTION__" type="application/json">${str}</script>`;
|
||||||
@@ -81,11 +82,12 @@ export async function apply(ctx: Context) {
|
|||||||
asFallback: true,
|
asFallback: true,
|
||||||
priority: 100,
|
priority: 100,
|
||||||
async render(name, args, context) {
|
async render(name, args, context) {
|
||||||
const data = {
|
const data: PageData = {
|
||||||
HYDRO_INJECTED: true,
|
HYDRO_INJECTED: true,
|
||||||
name,
|
name,
|
||||||
args,
|
args,
|
||||||
url: context.handler.context.req.url,
|
url: context.handler.context.req.url,
|
||||||
|
routeMap: ctx.server.routeMap,
|
||||||
};
|
};
|
||||||
const serialized = JSON.stringify(data, serializer(false, context.handler));
|
const serialized = JSON.stringify(data, serializer(false, context.handler));
|
||||||
const htmlToRender = html.replace(INJECT_MARKER, buildInject(serialized));
|
const htmlToRender = html.replace(INJECT_MARKER, buildInject(serialized));
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export interface PageData {
|
|||||||
name: string;
|
name: string;
|
||||||
args: Record<string, any>;
|
args: Record<string, any>;
|
||||||
url: string;
|
url: string;
|
||||||
|
routeMap: Record<string, string>;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user