@@ -3,6 +3,15 @@ import { rules } from "../../../src/utils/rules.ts"
33import { readable , writable } from "svelte/store"
44// eslint-disable-next-line node/no-missing-import -- ignore
55import { page } from "$app/stores"
6+ // eslint-disable-next-line node/no-missing-import -- ignore
7+ import { base as baseUrl } from "$app/paths"
8+
9+ export function stripBaseUrl ( path ) {
10+ if ( path . startsWith ( baseUrl ) ) {
11+ return path . slice ( baseUrl . length )
12+ }
13+ return path
14+ }
615
716const svelteRules = rules . filter ( ( rule ) => ! rule . meta . deprecated )
817
@@ -53,10 +62,13 @@ const SIDE_MENU = {
5362}
5463
5564export function isActive ( path , $page ) {
56- return markdownPath ( $page . path ) === markdownPath ( path )
65+ return markdownPath ( $page . url . pathname ) === markdownPath ( path )
5766}
5867
5968export function markdownPath ( path ) {
69+ // eslint-disable-next-line no-param-reassign -- ignore
70+ path = stripBaseUrl ( path )
71+
6072 let normalized = path === "/" ? "README" : path . replace ( / ^ \/ | \/ $ / g, "" )
6173 return `${ normalized } .md`
6274}
@@ -84,8 +96,9 @@ export const menuItems = readable([], function start(set) {
8496function generateMenu ( $page , toc ) {
8597 const result = [ ]
8698 const [ , menus ] =
87- Object . entries ( SIDE_MENU ) . find ( ( [ k ] ) => $page . path . startsWith ( k ) ) ||
88- SIDE_MENU [ "/" ]
99+ Object . entries ( SIDE_MENU ) . find ( ( [ k ] ) =>
100+ stripBaseUrl ( $page . url . pathname ) . startsWith ( k ) ,
101+ ) || SIDE_MENU [ "/" ]
89102 for ( const { path, title, children } of menus ) {
90103 const active = isActive ( path , $page )
91104 if ( active ) {
0 commit comments