Skip to content

Commit 8a0d5f1

Browse files
committed
bump version to 0.42.0 and update routing logic
1 parent d910296 commit 8a0d5f1

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

k8s/config/nginx-default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ server {
2121
location / {
2222
root /usr/share/nginx/html;
2323
index index.html index.htm;
24-
try_files $uri /index.html;
24+
try_files $uri $uri/ /index.html;
2525
}
2626

2727
error_page 500 502 503 504 /50x.html;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@clidey/dory",
33
"private": false,
4-
"version": "0.41.0",
4+
"version": "0.42.0",
55
"type": "module",
66
"description": "A CLI tool for building and previewing documentation sites",
77
"keywords": [

src/components/hooks.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,29 @@ import { useEffect, useState } from 'preact/hooks';
22
import { useLocation } from 'wouter-preact';
33

44
/**
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.
616
*/
717
export const usePathname = () => {
818
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;
1028
};
1129

1230
/**

src/mdx/mdx.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useRef } from 'preact/hooks';
22
import { lazy, Suspense } from 'preact/compat';
3-
import { usePathname } from 'wouter-preact/use-browser-location';
3+
import { usePathname } from '../components/hooks';
44
import { completeFrontMatter } from '../components/store';
55
import { Loading } from '../components/loading';
66

src/ui/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import classNames from 'classnames';
22
import { useEffect, useMemo, useState } from 'preact/hooks';
33
import { Link } from 'wouter-preact';
4-
import { usePathname } from 'wouter-preact/use-browser-location';
4+
import { usePathname } from '../components/hooks';
55
import docsConfig from '../../docs/dory.json' with { type: 'json' };
66
import type { DoryConfig } from '../types/config';
77
import { MobileSearch, Search } from '../components/search';

src/ui/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { ComponentChildren } from 'preact';
22
import { useCallback, useEffect, useMemo, useState } from 'preact/hooks';
3-
import { useLocation } from 'wouter-preact';
43
import { Navigation } from '../components/navigation';
54
import { ALL_NAVIGATION, ALL_OPENAPI, completeFrontMatter, loadMDXFrontMatterForPath, loadAllMDXFrontMatter, ALL_PAGES, pathFromFilename, preloadFrontmatter, ALL_ASYNCAPI } from '../components/store';
5+
import { usePathname } from '../components/hooks';
66
import { OpenAPI } from '../mdx/open-api';
77
import { AsyncAPI } from '../mdx/async-api';
88
import { Header } from './header';
@@ -26,7 +26,7 @@ const prompt = (pathname: string) => `Please read and analyze the content from t
2626

2727
export default function Layout({ children }: LayoutProps) {
2828
const [loading, setLoading] = useState(true);
29-
const [pathname] = useLocation();
29+
const pathname = usePathname();
3030
const { showNotification } = useNotification();
3131
const isEmbedded = useIsEmbedded();
3232

0 commit comments

Comments
 (0)