Started documenting code
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { type RegularTagNode, type TextNode } from "@melvdouc/xml-parser";
|
||||
import { AsyncRoute } from "$fresh/src/server/types.ts";
|
||||
|
||||
export interface State {
|
||||
isAuthenticated: boolean;
|
||||
session: CasContent;
|
||||
}
|
||||
|
||||
export interface AppProperties {
|
||||
name: string;
|
||||
@@ -48,3 +54,6 @@ export interface LoginJWT {
|
||||
}
|
||||
|
||||
export type EmptyObject = Record<string | number | symbol, never>;
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export type Route = AsyncRoute<any, State>;
|
||||
+14
-4
@@ -1,12 +1,22 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
import { Route, State } from "$root/defaults/interfaces.ts";
|
||||
import { ComponentChildren } from "preact";
|
||||
|
||||
export default function makeIndex(basePath: string) {
|
||||
/**
|
||||
* Generates index file based on `Index` fresh partial to avoid code duplication.
|
||||
* @param basePath The base path of the module, should be `import.meta.url!`.
|
||||
* @returns The `Index` fresh partial that will be displayed by default.
|
||||
*
|
||||
* @example
|
||||
* import makeIndex from "$root/defaults/makeIndex.ts";
|
||||
* export default makeIndex(import.meta.dirname!);
|
||||
*/
|
||||
export default function makeIndex(basePath: string): Route {
|
||||
return async function Index(
|
||||
request: Request,
|
||||
context: FreshContext<State>,
|
||||
) {
|
||||
const index = (await import(`${basePath}/partials/index.tsx`)).Index;
|
||||
): Promise<ComponentChildren | Response> {
|
||||
const index: Route = (await import(`${basePath}/partials/index.tsx`)).Index;
|
||||
return index(request, context);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { JSX } from "preact";
|
||||
import { Partial } from "$fresh/runtime.ts";
|
||||
import { FreshContext, RouteConfig } from "$fresh/server.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
import { Route, State } from "$root/defaults/interfaces.ts";
|
||||
|
||||
/**
|
||||
* Gets the `RouteConfig` config object for partial pages.
|
||||
* @returns The partials config object.
|
||||
*/
|
||||
export function getPartialsConfig(): RouteConfig {
|
||||
return {
|
||||
skipAppWrapper: true,
|
||||
@@ -10,12 +14,21 @@ export function getPartialsConfig(): RouteConfig {
|
||||
};
|
||||
}
|
||||
|
||||
export function makePartials(
|
||||
page: (
|
||||
request: Request,
|
||||
context: FreshContext<State>,
|
||||
) => Promise<JSX.Element>,
|
||||
) {
|
||||
/**
|
||||
* Partialize the given page for optimized rendering.
|
||||
* @param page The partial `Route` object to partialize.
|
||||
* @returns The partialized version of `page`.
|
||||
* @example
|
||||
* // Page defintion...
|
||||
* async function Page(_request: Request, context: FreshContext<State>) {
|
||||
* return <h2>My super page!</h2>;
|
||||
* }
|
||||
*
|
||||
* // Partial code that should be at each file's end.
|
||||
* export const config = getPartialsConfig();
|
||||
* export default makePartials(Page);
|
||||
*/
|
||||
export function makePartials(page: Route) {
|
||||
return async function WrappedElements(
|
||||
request: Request,
|
||||
context: FreshContext<State>,
|
||||
|
||||
Reference in New Issue
Block a user