From 9b2d3e0349327ffe4a51cb2ce3426eeaf4529fcf Mon Sep 17 00:00:00 2001 From: Ken Kunz Date: Wed, 27 Nov 2024 17:13:05 -0600 Subject: [PATCH 1/6] add strategyMicrosite boolean config option --- src/lib/config.ts | 8 ++++++++ src/lib/trade-executor/schemas/configuration.ts | 1 + 2 files changed, 9 insertions(+) diff --git a/src/lib/config.ts b/src/lib/config.ts index e58c42b24..9208b9144 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -121,6 +121,14 @@ export const strategyConfig = config((jsonStr: string) => { } }, 'STRATEGIES'); +/** + * If a configured strategy includes a truthy `microsite` value, set strategyMicrosite + * to the strategy's ID (otherwise undefined) + */ +export const strategyMicrosite = ((strategies: any[]) => { + return strategies.find((s) => s.microsite)?.id; +})(strategyConfig) as string | undefined; + /** * Load WalletConnect projectId and warn if not available. */ diff --git a/src/lib/trade-executor/schemas/configuration.ts b/src/lib/trade-executor/schemas/configuration.ts index 9a62ea8d6..cb8111f55 100644 --- a/src/lib/trade-executor/schemas/configuration.ts +++ b/src/lib/trade-executor/schemas/configuration.ts @@ -9,6 +9,7 @@ export const strategyConfigurationSchema = z.object({ new_version_id: z.string().optional(), hiddenPositions: primaryKey.array().default([]), frontpage: z.boolean().default(false), + microsite: z.boolean().default(false), depositOnEnzyme: z.boolean().default(false) }); export type StrategyConfiguration = z.infer; From f681c6cd123c1139974572fb5155ae6866695d5e Mon Sep 17 00:00:00 2001 From: Ken Kunz Date: Wed, 27 Nov 2024 17:18:41 -0600 Subject: [PATCH 2/6] always use dark mode on strategy microsite --- src/hooks.server.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 81ee5b1ea..1b6f5a267 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -2,7 +2,7 @@ import type { Handle, HandleServerError } from '@sveltejs/kit'; import { sequence } from '@sveltejs/kit/hooks'; import * as Sentry from '@sentry/sveltekit'; import { env } from '$env/dynamic/private'; -import { backendUrl, backendInternalUrl, sentryDsn, siteMode, version } from '$lib/config'; +import { backendUrl, backendInternalUrl, sentryDsn, siteMode, strategyMicrosite, version } from '$lib/config'; import { countryCodeSchema } from '$lib/helpers/geo'; import { parseDate } from '$lib/helpers/date'; @@ -47,15 +47,22 @@ export const handleError = Sentry.handleErrorWithSentry((async ({ error }) => { }) as HandleServerError); const handleColorMode: Handle = async ({ event, resolve }) => { - const colorMode = event.cookies.get('color-mode') || 'system'; - - // update the cookie (in case not set and to update expiration) - event.cookies.set('color-mode', colorMode, { - httpOnly: false, - secure: false, - path: '/', - maxAge: ONE_YEAR - }); + let colorMode: string; + + if (strategyMicrosite) { + // ignore cookie value and set to 'dark' for custom strategy site + colorMode = 'dark'; + } else { + // check and update cookie value and expiration + colorMode = event.cookies.get('color-mode') || 'system'; + + event.cookies.set('color-mode', colorMode, { + httpOnly: false, + secure: false, + path: '/', + maxAge: ONE_YEAR + }); + } return resolve(event, { transformPageChunk({ html }) { From 3195aacb5b40a4413a82ff0aaf0c414741dbadc5 Mon Sep 17 00:00:00 2001 From: Ken Kunz Date: Wed, 27 Nov 2024 18:35:22 -0600 Subject: [PATCH 3/6] restict strategy microsite routes --- src/routes/+layout.server.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index 5eeb6653b..24cc628d1 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -1,5 +1,24 @@ -// Make admin, ipCountry and announcementDismissedAt available to all layouts/pages -export async function load({ locals }) { +import { strategyMicrosite } from '$lib/config'; +import { error, redirect } from '@sveltejs/kit'; + +export async function load({ locals, route }) { + // restrict routes on custom strategy site + if (strategyMicrosite) { + restrictMicrositeRoutes(route.id!, strategyMicrosite); + } + + // Make admin, ipCountry and announcementDismissedAt available to all layouts/pages const { admin, ipCountry, announcementDismissedAt } = locals; return { admin, ipCountry, announcementDismissedAt }; } + +function restrictMicrositeRoutes(routeId: string, strategyId: string) { + // redirect home page to strategy page + if (routeId === '/') redirect(302, `/strategies/${strategyId}`); + + // return 404 for all pages other than strategies, glossary and diagnostics + const segments = routeId.split('/').slice(1); + if (!['strategies', 'glossary', 'diagnostics'].includes(segments[0])) { + error(404, 'Not found'); + } +} From 50caf298b1caf3d6bf001bc42fb2ff5f9171c7b4 Mon Sep 17 00:00:00 2001 From: Ken Kunz Date: Wed, 27 Nov 2024 18:46:27 -0600 Subject: [PATCH 4/6] hide top-nav for strategy microsite --- src/routes/+layout.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index ea86e1f09..e1086a88e 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,7 +2,7 @@ Root layout --> -
@@ -65,7 +59,7 @@ https://search.google.com/structured-data/testing-tool {label} {/if} - + {/each} diff --git a/src/routes/strategies/[strategy]/+layout.svelte b/src/routes/strategies/[strategy]/+layout.svelte index 2864e8e4f..07f539cea 100644 --- a/src/routes/strategies/[strategy]/+layout.svelte +++ b/src/routes/strategies/[strategy]/+layout.svelte @@ -1,4 +1,5 @@ - +{#if !strategyMicrosite} + +{/if} {#if $page.data.skipSideNav} + {#if strategyMicrosite} + + {/if} {:else} -
+
@@ -95,6 +101,14 @@ display: grid; gap: var(--space-md); + &.microsite { + margin-top: 1.5rem; + + @media (--viewport-xs) { + margin-top: 1rem; + } + } + :global(.badge) { font-size: clamp(11px, 0.45em, 16px); margin-inline: 0.25em; From adfa506022bc9e62008300ab6dfa7e22f40cf266 Mon Sep 17 00:00:00 2001 From: Ken Kunz Date: Mon, 2 Dec 2024 05:51:46 -0600 Subject: [PATCH 6/6] link strategy icon back to overview ("home") --- src/routes/strategies/[strategy]/+layout.svelte | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/routes/strategies/[strategy]/+layout.svelte b/src/routes/strategies/[strategy]/+layout.svelte index 07f539cea..d2750bc52 100644 --- a/src/routes/strategies/[strategy]/+layout.svelte +++ b/src/routes/strategies/[strategy]/+layout.svelte @@ -42,7 +42,15 @@ {:else}
- + + {#if strategyMicrosite && !isOverviewPage} + + + + {:else} + + {/if} +
{strategy.name} @@ -107,6 +115,10 @@ @media (--viewport-xs) { margin-top: 1rem; } + + a { + width: 100%; + } } :global(.badge) {