From c35193e8a97220e0cd754f68710603a17bab5a70 Mon Sep 17 00:00:00 2001 From: Guanzhou Song <26541184+GuanzhouSong@users.noreply.github.com> Date: Fri, 6 Nov 2026 09:32:15 -0500 Subject: [PATCH 1/2] Render one nav for Next.js and Jekyll pages, with dropdowns The blog and announcement pages kept a hand-copied nav that had drifted (no AI or Samples, a different Download label). Both now read blogs/_data/nav.json. Samples, the VS Code extension and Agent-Kit fold under Build, Announcements and Blogs under News. Signed-off-by: Guanzhou Song <26541184+GuanzhouSong@users.noreply.github.com> --- app/components/Navbar.tsx | 285 +++++++++++++++++++++++----------- blogs/_config.yml | 4 +- blogs/_data/nav.json | 30 ++++ blogs/_includes/nav-icon.html | 11 ++ blogs/_includes/nav-link.html | 12 ++ blogs/_layouts/default.html | 90 ++++++----- blogs/assets/blog.css | 129 ++++++++++++++- tests/blogSections.test.ts | 37 ++++- 8 files changed, 462 insertions(+), 136 deletions(-) create mode 100644 blogs/_data/nav.json create mode 100644 blogs/_includes/nav-icon.html create mode 100644 blogs/_includes/nav-link.html diff --git a/app/components/Navbar.tsx b/app/components/Navbar.tsx index c1bd42b..adda0c8 100644 --- a/app/components/Navbar.tsx +++ b/app/components/Navbar.tsx @@ -1,54 +1,73 @@ "use client"; -import { useState } from "react"; +import { useEffect, useRef, useState, type ReactNode } from "react"; import Image from "next/image"; import Link from "next/link"; -import { documentdbDiscordUrl } from "../services/externalLinks"; +// The Jekyll layout renders the same file, so the blog and announcement pages show this nav too +import nav from "../../blogs/_data/nav.json"; import { withBasePath } from "../services/sitePath"; -type NavItem = { - label: string; - href: string; - kind: "link" | "anchor"; - newTab?: boolean; - icon?: "github" | "discord"; -}; - -const navItems: NavItem[] = [ - { label: "Home", href: "/", kind: "link" }, - { - label: "GitHub", - href: "https://github.com/documentdb/documentdb", - kind: "anchor", - newTab: true, - icon: "github", - }, - { - label: "Discord", - href: documentdbDiscordUrl, - kind: "anchor", - newTab: true, - icon: "discord", - }, - { label: "Docs", href: "/docs", kind: "link" }, - { label: "AI", href: "/ai", kind: "link" }, - { label: "Install & Download", href: "/packages", kind: "link" }, - { - label: "Agent-Kit", - href: "https://github.com/Azure/documentdb-agent-kit", - kind: "anchor", - newTab: true, - }, - { label: "K8s Operator", href: "/kubernetes-operator", kind: "link" }, - { label: "Announcements", href: withBasePath("/announcements/"), kind: "anchor" }, - { label: "Blogs", href: withBasePath("/blogs/"), kind: "anchor" }, - { label: "Samples", href: "/samples", kind: "link" }, -]; - -function NavIcon({ name }: { name: NonNullable }) { +type NavLink = { label: string; href: string; section?: string }; +type NavGroup = { label: string; items: NavLink[] }; +type NavIconLink = NavLink & { icon: string }; + +const links: (NavLink | NavGroup)[] = nav.links; +const iconLinks: NavIconLink[] = nav.icons; + +const desktopLinkClass = + "flex items-center gap-1 font-medium text-gray-300 transition-colors duration-200 hover:text-blue-400 focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-blue-400"; +const dropdownLinkClass = + "flex items-center justify-between gap-3 rounded-md px-3 py-2 text-sm font-medium text-gray-300 transition-colors duration-200 hover:bg-neutral-800 hover:text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-400"; +const mobileLinkClass = + "flex items-center gap-3 rounded-md px-3 py-2.5 text-sm font-medium text-gray-300 transition-colors duration-200 hover:bg-neutral-800 hover:text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-400"; + +function isExternal(href: string) { + return /^https?:\/\//.test(href); +} + +function groupId(label: string) { + return `nav-${label.toLowerCase()}`; +} + +function NavAnchor({ + link, + className, + onClick, + children, +}: { + link: NavLink; + className: string; + onClick?: () => void; + children: ReactNode; +}) { + if (isExternal(link.href)) { + return ( + + {children} + + ); + } + + // Jekyll builds these sections, so they are not Next.js routes + if (link.section) { + return ( + + {children} + + ); + } + + return ( + + {children} + + ); +} + +function BrandIcon({ name }: { name: string }) { if (name === "github") { return ( - + {item.label} - - ); - - if (item.kind === "link") { + if (name === "discord") { return ( - - {content} - + ); } + return null; +} + +function ExternalIcon() { return ( - - {content} - + ); } export default function Navbar() { const [isMenuOpen, setIsMenuOpen] = useState(false); + const [openGroup, setOpenGroup] = useState(null); + const desktopNav = useRef(null); const closeMenu = () => setIsMenuOpen(false); + const closeGroup = () => setOpenGroup(null); + + useEffect(() => { + if (!openGroup) return; + // Safari never focuses a clicked button, so blur alone cannot close the panel + const closeOnOutsidePointer = (event: PointerEvent) => { + if (!desktopNav.current?.contains(event.target as Node)) setOpenGroup(null); + }; + const closeOnEscape = (event: KeyboardEvent) => { + if (event.key !== "Escape") return; + setOpenGroup(null); + document.getElementById(`${groupId(openGroup)}-button`)?.focus(); + }; + document.addEventListener("pointerdown", closeOnOutsidePointer); + document.addEventListener("keydown", closeOnEscape); + return () => { + document.removeEventListener("pointerdown", closeOnOutsidePointer); + document.removeEventListener("keydown", closeOnEscape); + }; + }, [openGroup]); return (