File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
apps/svelte.dev/src/routes/docs/[...path] Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 22 import { Text } from ' @sveltejs/site-kit/components' ;
33 import { legacy_details } from ' @sveltejs/site-kit/actions' ;
44 import { setupDocsHovers } from ' @sveltejs/site-kit/docs' ;
5+ import { onMount } from ' svelte' ;
56 import OnThisPage from ' ./OnThisPage.svelte' ;
67 import Breadcrumbs from ' ./Breadcrumbs.svelte' ;
8+ import { goto } from ' $app/navigation' ;
9+ import { page } from ' $app/stores' ;
710 import PageControls from ' $lib/components/PageControls.svelte' ;
811
912 let { data } = $props ();
1720 const link = ' docs/' + data .document .file .split (' /' ).slice (2 ).join (' /' );
1821 return ` https://github.com/sveltejs/${name }/edit/main/documentation/${link } ` ;
1922 });
23+
24+ // make hash case-insensitive
25+ // hash was lowercase in v4 docs and varying case in v5 docs
26+ function get_url_to_redirect_to() {
27+ const hash = $page .url .hash .replace (/ ^ #/ i , ' ' );
28+ if (! hash ) return ;
29+
30+ const elements = document .querySelectorAll (' *[id]' );
31+ // if there's an exact match, use that. no need to redirect
32+ for (const el of elements ) {
33+ if (el .id === hash ) {
34+ return ;
35+ }
36+ }
37+ for (const el of elements ) {
38+ if (el .id .toLocaleLowerCase () === hash .toLocaleLowerCase ()) {
39+ const url = $page .url ;
40+ url .hash = el .id ;
41+ return url ;
42+ }
43+ }
44+ }
45+
46+ onMount (() => {
47+ const redirect = get_url_to_redirect_to ();
48+ if (redirect ) {
49+ goto (redirect , { replaceState: true });
50+ }
51+ });
2052 </script >
2153
2254<svelte:head >
You can’t perform that action at this time.
0 commit comments