Skip to content

Commit 803b6a4

Browse files
authored
fix: edit links for api and advanced pages (#842)
1 parent 24dd72e commit 803b6a4

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/components/layout.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const Layout = (props: {
2222
const { currentLanguage } =
2323
language && language.currentLanguage ? language : { currentLanguage: "en" }
2424
const lightMode = state?.setting?.lightMode
25+
const currentVersion = state?.setting?.version
2526
const [show, setShow] = React.useState(false)
2627
const scrollHandler = () => {
2728
if (window.scrollY > 75) {
@@ -30,7 +31,11 @@ const Layout = (props: {
3031
setShow(false)
3132
}
3233
}
33-
const editLink = getEditLink(currentLanguage, props.location?.pathname)
34+
const editLink = getEditLink(
35+
currentVersion,
36+
currentLanguage,
37+
props.location?.pathname
38+
)
3439

3540
React.useEffect(() => {
3641
window.addEventListener("scroll", scrollHandler)

src/components/logic/getEditLink.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
const preFix =
2-
"https://github.com/react-hook-form/documentation/edit/master/src/data/"
2+
"https://github.com/react-hook-form/documentation/edit/v6-v5/src/data/"
33

44
export const getEditLink = (
5+
currentVersion: number,
56
currentLanguage: string,
67
pathname: string
78
): string => {
89
if (!pathname) return ""
910

11+
let versionTag = ""
12+
if (currentVersion === 6) {
13+
versionTag = "V6/"
14+
} else if (currentVersion === 5) {
15+
versionTag = "V5/"
16+
}
17+
1018
if (pathname === "/" || pathname === "") {
1119
return preFix + "home.tsx"
1220
} else if (pathname.includes("get-started")) {
1321
return `${preFix}${currentLanguage}/getStarted.tsx`
1422
} else if (pathname.includes("api")) {
15-
return `${preFix}${currentLanguage}/api.tsx`
23+
return `${preFix}${versionTag}${currentLanguage}/api.tsx`
1624
} else if (pathname.includes("ts")) {
1725
return `${preFix}ts.tsx`
1826
} else if (pathname.includes("advanced-usage")) {
19-
return `${preFix}${currentLanguage}/advanced.tsx`
27+
const tag = currentVersion < 7 && currentLanguage === "en" ? "V6/" : ""
28+
return `${preFix}${tag}${currentLanguage}/advanced.tsx`
2029
} else if (pathname.includes("faqs")) {
2130
return `${preFix}${currentLanguage}/faq.tsx`
2231
} else if (pathname.includes("dev-tools")) {

0 commit comments

Comments
 (0)