From bef9208d47fc082ca676d8f213e1532cf0fcae91 Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Thu, 26 Feb 2026 17:36:15 +0100 Subject: [PATCH] Fix path normalization in API docs --- src/ApiDocs.res | 9 +++++---- src/layouts/SidebarLayout.res | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ApiDocs.res b/src/ApiDocs.res index fa108d858..b45a9072b 100644 --- a/src/ApiDocs.res +++ b/src/ApiDocs.res @@ -99,14 +99,15 @@ module SidebarTree = { open ReactRouter let location = useLocation() + let currentPathname = (location.pathname :> string)->Url.normalizePath let moduleRoute = `${apiDocsRootPath}/${(location.pathname :> string) ->String.replace(`/docs/manual/api/`, "") ->String.split("/") ->Array.get(0) - ->Option.getOr("stdlib")}` + ->Option.getOr("stdlib")}`->Url.normalizePath - let isCurrentlyAtRoot = (location.pathname :> string) == moduleRoute + let isCurrentlyAtRoot = currentPathname == moduleRoute let summaryClassName = "truncate py-1 md:h-auto tracking-tight text-gray-60 font-medium text-14 rounded-sm hover:bg-gray-20 hover:-ml-2 hover:py-1 hover:pl-2 " let classNameActive = " bg-fire-5 text-red-500 -ml-2 pl-2 font-medium hover:bg-fire-70" @@ -128,7 +129,7 @@ module SidebarTree = { // This is the full path to this module, e.g. "/docs/manual/api/stdlib/array" or "/docs/manual/api/stdlib/int" let fullPath = `${moduleRoute}/${relativePath}`->Url.normalizePath - let isCurrentRoute = fullPath == (location.pathname :> string) + let isCurrentRoute = fullPath == currentPathname let classNameActive = isCurrentRoute ? classNameActive : "" @@ -138,7 +139,7 @@ module SidebarTree = { switch hasChildren { | true => - let open_ = (location.pathname :> string)->String.includes(fullPath) + let open_ = currentPathname->String.includes(fullPath)
unit, ) => { - let isItemActive = (navItem: NavItem.t) => navItem.href === (route :> string) + let currentRoute = (route :> string)->Url.normalizePath + let isItemActive = (navItem: NavItem.t) => navItem.href->Url.normalizePath === currentRoute // the height of the navbars above is fluid across pages, and it's easy to get it wrong // so we calculate it dynamically here @@ -161,7 +162,7 @@ module Sidebar = { : 0 let getActiveToc = (navItem: NavItem.t) => { - if navItem.href === (route :> string) { + if navItem.href->Url.normalizePath === currentRoute { activeToc } else { None @@ -331,8 +332,9 @@ let make = ( let pagination = switch categories { | Some(categories) => let items = categories->Array.flatMap(c => c.items) + let currentPathname = (location.pathname :> string)->Url.normalizePath - switch items->Array.findIndex(item => item.href === (location.pathname :> string)) { + switch items->Array.findIndex(item => item.href->Url.normalizePath === currentPathname) { | -1 => React.null | i => let previous = switch items->Array.get(i - 1) {