Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/ApiDocs.res
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 : ""

Expand All @@ -138,7 +139,7 @@ module SidebarTree = {

switch hasChildren {
| true =>
let open_ = (location.pathname :> string)->String.includes(fullPath)
let open_ = currentPathname->String.includes(fullPath)

<details
key={node.name}
Expand Down
8 changes: 5 additions & 3 deletions src/layouts/SidebarLayout.res
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ module Sidebar = {
~isOpen: bool,
~toggle: unit => 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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Loading