From 298a40723093fab1b4081d359c39fd164502a58b Mon Sep 17 00:00:00 2001 From: gabrielMatosBoubee Date: Wed, 25 Sep 2024 17:47:52 -0300 Subject: [PATCH 1/4] feat: priorization pages --- website/loaders/pages.ts | 42 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/website/loaders/pages.ts b/website/loaders/pages.ts index 23465c2ef..5ef611071 100644 --- a/website/loaders/pages.ts +++ b/website/loaders/pages.ts @@ -1,3 +1,4 @@ +import { SiteRoute } from "../../admin/widgets.ts"; import { Route } from "../flags/audience.ts"; import { AppContext } from "../mod.ts"; import Page from "../pages/Page.tsx"; @@ -19,7 +20,7 @@ async function getAllPages(ctx: AppContext): Promise { continue; } routes.push({ - pathTemplate, + pathTemplate: pathTemplate, handler: { value: { __resolveType: "website/handlers/fresh.ts", @@ -33,12 +34,29 @@ async function getAllPages(ctx: AppContext): Promise { return routes; } + +export interface ExternalProps { + /** + * @title Prioritize External Routes + * @description If there is the same route on the deco and externally, as in proxies, the EXTERNAL route will be used. You can also test with the parameter "rdc=true" + */ + preferRoutes?: boolean; + /** + * @description Deco routes that will ignore the previous rule. If the same route exists on the deco and externally, the DECO route will be used + */ + exceptionRoutes?: SiteRoute[]; +} + +export interface Props { + external?: ExternalProps; +} + /** * @title Pages */ export default async function Pages( - _props: unknown, - _req: Request, + props: Props, + req: Request, ctx: AppContext, ): Promise { const allPages = await ctx.get< @@ -48,5 +66,23 @@ export default async function Pages( __resolveType: "once", }); + if (props?.external?.preferRoutes) { + allPages.map(({ pathTemplate, ...pageProps }: Route) => { + const isException = props.external?.exceptionRoutes?.some((path) => + path === pathTemplate + ); + const url = new URL(pathTemplate, req.url); + const queryString = new URLSearchParams(url.search).toString(); + const separator = queryString ? "&" : ""; + + return ({ + pathTemplate: isException + ? pathTemplate + : `${pathTemplate}?${queryString}${separator}rdc=true`, + ...pageProps, + }); + }); + } + return allPages; } From 5da80de9b8ae172c0bfeee6d9ccd1e5d09acd77c Mon Sep 17 00:00:00 2001 From: gabrielMatosBoubee Date: Wed, 25 Sep 2024 17:51:16 -0300 Subject: [PATCH 2/4] chore: refactor --- website/loaders/pages.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/loaders/pages.ts b/website/loaders/pages.ts index 5ef611071..64cdda975 100644 --- a/website/loaders/pages.ts +++ b/website/loaders/pages.ts @@ -20,7 +20,7 @@ async function getAllPages(ctx: AppContext): Promise { continue; } routes.push({ - pathTemplate: pathTemplate, + pathTemplate, handler: { value: { __resolveType: "website/handlers/fresh.ts", From b296eedeab82afbea29bd44e19b27fb596a73b4c Mon Sep 17 00:00:00 2001 From: gabrielMatosBoubee Date: Wed, 25 Sep 2024 20:04:53 -0300 Subject: [PATCH 3/4] fix: add wildcard --- website/loaders/pages.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/loaders/pages.ts b/website/loaders/pages.ts index 64cdda975..8c0046da9 100644 --- a/website/loaders/pages.ts +++ b/website/loaders/pages.ts @@ -67,7 +67,7 @@ export default async function Pages( }); if (props?.external?.preferRoutes) { - allPages.map(({ pathTemplate, ...pageProps }: Route) => { + return allPages.map(({ pathTemplate, ...pageProps }: Route) => { const isException = props.external?.exceptionRoutes?.some((path) => path === pathTemplate ); @@ -78,7 +78,7 @@ export default async function Pages( return ({ pathTemplate: isException ? pathTemplate - : `${pathTemplate}?${queryString}${separator}rdc=true`, + : `${pathTemplate}?${queryString}${separator}*rdc=true*`, ...pageProps, }); }); From 73dd46705febf692f17e65f026d2c365b09e5bc2 Mon Sep 17 00:00:00 2001 From: gabrielMatosBoubee Date: Thu, 23 Jan 2025 17:11:32 -0300 Subject: [PATCH 4/4] chore: change names --- website/loaders/pages.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/website/loaders/pages.ts b/website/loaders/pages.ts index 8c0046da9..347fff625 100644 --- a/website/loaders/pages.ts +++ b/website/loaders/pages.ts @@ -35,20 +35,16 @@ async function getAllPages(ctx: AppContext): Promise { return routes; } -export interface ExternalProps { +export interface Props { /** - * @title Prioritize External Routes - * @description If there is the same route on the deco and externally, as in proxies, the EXTERNAL route will be used. You can also test with the parameter "rdc=true" + * @title Hide pages in deco + * @description Don't route the client to any deco page. Important: those page are still accessible if you set the "rdc=true" query string. */ - preferRoutes?: boolean; + hidePagesInDeco?: boolean; /** - * @description Deco routes that will ignore the previous rule. If the same route exists on the deco and externally, the DECO route will be used + * @description Deco routes that will ignore the previous rule. If the same route exists on other routes loader, the deco page will be used. */ - exceptionRoutes?: SiteRoute[]; -} - -export interface Props { - external?: ExternalProps; + alwaysVisiblePages?: SiteRoute[]; } /** @@ -66,9 +62,9 @@ export default async function Pages( __resolveType: "once", }); - if (props?.external?.preferRoutes) { + if (props?.hidePagesInDeco) { return allPages.map(({ pathTemplate, ...pageProps }: Route) => { - const isException = props.external?.exceptionRoutes?.some((path) => + const isException = props.alwaysVisiblePages?.some((path) => path === pathTemplate ); const url = new URL(pathTemplate, req.url);