diff --git a/src/components/gitbook/VersionGate.astro b/src/components/gitbook/VersionGate.astro index 5c9e76e45..c6631d6d8 100644 --- a/src/components/gitbook/VersionGate.astro +++ b/src/components/gitbook/VersionGate.astro @@ -1,4 +1,6 @@ --- +import { getServerSystemVersion } from "~/state/nav"; + import Impl from "./VersionGate"; interface Props { @@ -6,9 +8,10 @@ interface Props { } const { default: version } = Astro.props; +const serverSystemVersion = getServerSystemVersion(Astro); --- - + {Astro.slots.has("v1") ? : null} {Astro.slots.has("v2") ? : null} diff --git a/src/components/gitbook/VersionGate.tsx b/src/components/gitbook/VersionGate.tsx index 0bd3fdaf3..05502f6df 100644 --- a/src/components/gitbook/VersionGate.tsx +++ b/src/components/gitbook/VersionGate.tsx @@ -2,9 +2,11 @@ import type React from "react"; import { useServerFallback } from "~/misc/useServerFallback"; import { systemVersionSignal } from "~/state/nav"; +import type { SystemVersion } from "~/type"; interface Props { - default?: "v1" | "v2"; + serverSystemVersion: SystemVersion; + default?: SystemVersion; v1?: React.ReactNode; v2?: React.ReactNode; children?: React.ReactNode; @@ -23,20 +25,22 @@ const isEmptyStaticHtml = (node: React.ReactNode) => { }; export default function VersionGate(props: Props) { - const systemVersion = useServerFallback(systemVersionSignal.value, "all"); + const systemVersion = useServerFallback( + systemVersionSignal.value, + props.serverSystemVersion, + ); const hasV1 = !isEmptyStaticHtml(props.v1); const hasV2 = !isEmptyStaticHtml(props.v2); - const v1Content = - props.default === "v1" ? (hasV1 ? props.v1 : props.children) : props.v1; - const v2Content = - props.default === "v2" ? (hasV2 ? props.v2 : props.children) : props.v2; - return ( <> - {systemVersion !== "v1" && v2Content} - {systemVersion !== "v2" && v1Content} + { + { + v1: props.default === "v1" && !hasV1 ? props.children : props.v1, + v2: props.default === "v2" && !hasV2 ? props.children : props.v2, + }[systemVersion] + } ); } diff --git a/src/layouts/gnb/Dropdown.tsx b/src/layouts/gnb/Dropdown.tsx index 5baa9c579..5cf688993 100644 --- a/src/layouts/gnb/Dropdown.tsx +++ b/src/layouts/gnb/Dropdown.tsx @@ -9,15 +9,24 @@ export interface DropdownProps { children: React.ReactNode; link: string | Record; items: DropdownItem[]; + serverSystemVersion: SystemVersion; } export interface DropdownItem { label: React.ReactNode; link: string; systemVersion?: SystemVersion; } -export default function Dropdown({ children, link, items }: DropdownProps) { +export default function Dropdown({ + children, + link, + items, + serverSystemVersion, +}: DropdownProps) { const showItemsSignal = useSignal(false); - const systemVersion = useServerFallback(systemVersionSignal.value, "all"); + const systemVersion = useServerFallback( + systemVersionSignal.value, + serverSystemVersion, + ); return (
@@ -51,6 +53,7 @@ const t = lang === "ko" ? ko : en;
@@ -64,7 +67,11 @@ const t = lang === "ko" ? ko : en;
- +
new URL(url).pathname.startsWith(path))) return null; - const systemVersion = systemVersionSignal.value; + const systemVersion = useServerFallback( + systemVersionSignal.value, + serverSystemVersion, + ); + return (
-
V1
-
V2
+
V1
+
V2
); } export default VersionSwitch; -function getVersionClass(thisVersion: SystemVersion) { - const systemVersion = useServerFallback(systemVersionSignal.value, "all"); +function getVersionClass( + thisVersion: SystemVersion, + systemVersion: SystemVersion, +) { return `py-4px rounded-[4px] ${ systemVersion === thisVersion ? "bg-orange-500 flex-1 text-white px-12px" diff --git a/src/layouts/sidebar/DocsNavMenu.astro b/src/layouts/sidebar/DocsNavMenu.astro index f1208ac80..027014ad8 100644 --- a/src/layouts/sidebar/DocsNavMenu.astro +++ b/src/layouts/sidebar/DocsNavMenu.astro @@ -1,5 +1,9 @@ --- -import { navOpenStatesSignal, slugSignal } from "~/state/nav"; +import { + getServerSystemVersion, + navOpenStatesSignal, + slugSignal, +} from "~/state/nav"; import { calcNavMenuAncestors, navMenu } from "~/state/server-only/nav"; import type { Lang } from "~/type"; @@ -20,6 +24,8 @@ const navOpenStates = (navOpenStatesSignal.value = Object.fromEntries([ [slug, true], ])); slugSignal.value = slug; + +const serverSystemVersion = getServerSystemVersion(Astro); ---