Skip to content

Commit 1f95bc7

Browse files
authored
Revert "[Docs partial load] Handle on default paths (#440)" (#443)
This reverts commit 3eb69a5.
1 parent 5c20267 commit 1f95bc7

File tree

1 file changed

+0
-42
lines changed

1 file changed

+0
-42
lines changed

kit/src/routes/+layout.svelte

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,11 @@
11

22
<script lang="ts">
33
import { base } from "$app/paths";
4-
import { beforeNavigate, goto, onNavigate } from '$app/navigation';
54
import type { RawChapter } from "./endpoints/toc/+server";
65
import "../app.css";
76
87
export let data;
98
export let toc: RawChapter[] = data.toc ?? [];
10-
11-
const library = import.meta.env.DOCS_LIBRARY || 'transformers';
12-
const version = import.meta.env.DOCS_VERSION || 'main';
13-
const lang = import.meta.env.DOCS_LANGUAGE || 'en';
14-
15-
const redirectedPaths: Record<string, string> = {}
16-
17-
beforeNavigate(async ({ to, cancel }) => {
18-
const pathname = to?.url.pathname ?? "";
19-
const search = to?.url.search ?? "";
20-
const hash = to?.url.hash ?? "";
21-
const path = pathname + search + hash;
22-
if(/^\/(docs|learn)/.test(path)){
23-
const params = path.slice(1).split("/");
24-
const _docType = params.shift();
25-
const _library = params.shift();
26-
const isCourse = _docType === "learn";
27-
const versionRegex = isCourse ? /^(?:pr_\d+)$/ : /^(?:(master|main)|v[\d.]+(rc\d+)?|pr_\d+)$/;
28-
const _version = versionRegex.test(params[0]) ? params.shift() : undefined;
29-
const _lang = /^[a-z]{2}(-[A-Z]{2})?$/.test(params[0]) ? params.shift() : undefined;
30-
const newChapterId = params.join("/");
31-
32-
if (library === _library && (!_version || !_lang)){
33-
cancel();
34-
const redirectedPath = `/docs/${library}/${version}/${lang}/${newChapterId}`;
35-
redirectedPaths[redirectedPath] = path;
36-
await goto(redirectedPath);
37-
return false;
38-
}
39-
}
40-
});
41-
42-
onNavigate(({ to }) => {
43-
const pathname = to?.url.pathname ?? "";
44-
const search = to?.url.search ?? "";
45-
const hash = to?.url.hash ?? "";
46-
const path = pathname + search + hash;
47-
if(redirectedPaths[path]){
48-
history.replaceState({}, "", redirectedPaths[path])
49-
}
50-
});
519
</script>
5210

5311
{#if !import.meta.env.DEV}

0 commit comments

Comments
 (0)