@clidey/dory 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clidey/dory",
3
3
  "private": false,
4
- "version": "0.41.0",
4
+ "version": "0.42.0",
5
5
  "type": "module",
6
6
  "description": "A CLI tool for building and previewing documentation sites",
7
7
  "keywords": [
@@ -2,11 +2,29 @@ import { useEffect, useState } from 'preact/hooks';
2
2
  import { useLocation } from 'wouter-preact';
3
3
 
4
4
  /**
5
- * Custom hook to get the current pathname
5
+ * Strips trailing slash from a pathname (except root "/").
6
+ */
7
+ function normalizePathname(pathname: string): string {
8
+ if (pathname !== '/' && pathname.endsWith('/')) {
9
+ return pathname.slice(0, -1);
10
+ }
11
+ return pathname;
12
+ }
13
+
14
+ /**
15
+ * Custom hook to get the current pathname, normalized to strip trailing slashes.
6
16
  */
7
17
  export const usePathname = () => {
8
18
  const [pathname] = useLocation();
9
- return pathname;
19
+ const normalized = normalizePathname(pathname);
20
+
21
+ useEffect(() => {
22
+ if (pathname !== normalized) {
23
+ window.history.replaceState(null, '', normalized + window.location.search + window.location.hash);
24
+ }
25
+ }, [pathname, normalized]);
26
+
27
+ return normalized;
10
28
  };
11
29
 
12
30
  /**
package/src/mdx/mdx.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useRef } from 'preact/hooks';
2
2
  import { lazy, Suspense } from 'preact/compat';
3
- import { usePathname } from 'wouter-preact/use-browser-location';
3
+ import { usePathname } from '../components/hooks';
4
4
  import { completeFrontMatter } from '../components/store';
5
5
  import { Loading } from '../components/loading';
6
6
 
package/src/ui/header.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import classNames from 'classnames';
2
2
  import { useEffect, useMemo, useState } from 'preact/hooks';
3
3
  import { Link } from 'wouter-preact';
4
- import { usePathname } from 'wouter-preact/use-browser-location';
4
+ import { usePathname } from '../components/hooks';
5
5
  import docsConfig from '../../docs/dory.json' with { type: 'json' };
6
6
  import type { DoryConfig } from '../types/config';
7
7
  import { MobileSearch, Search } from '../components/search';
package/src/ui/layout.tsx CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { ComponentChildren } from 'preact';
2
2
  import { useCallback, useEffect, useMemo, useState } from 'preact/hooks';
3
- import { useLocation } from 'wouter-preact';
4
3
  import { Navigation } from '../components/navigation';
5
4
  import { ALL_NAVIGATION, ALL_OPENAPI, completeFrontMatter, loadMDXFrontMatterForPath, loadAllMDXFrontMatter, ALL_PAGES, pathFromFilename, preloadFrontmatter, ALL_ASYNCAPI } from '../components/store';
5
+ import { usePathname } from '../components/hooks';
6
6
  import { OpenAPI } from '../mdx/open-api';
7
7
  import { AsyncAPI } from '../mdx/async-api';
8
8
  import { Header } from './header';
@@ -26,7 +26,7 @@ const prompt = (pathname: string) => `Please read and analyze the content from t
26
26
 
27
27
  export default function Layout({ children }: LayoutProps) {
28
28
  const [loading, setLoading] = useState(true);
29
- const [pathname] = useLocation();
29
+ const pathname = usePathname();
30
30
  const { showNotification } = useNotification();
31
31
  const isEmbedded = useIsEmbedded();
32
32