File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @alauda/doom " : patch
3+ ---
4+
5+ fix: remove unnecessary lang part in external site link
Original file line number Diff line number Diff line change 1- import { NoSSR , useLang } from '@rspress/core/runtime'
1+ import { NoSSR , useLang , usePageData } from '@rspress/core/runtime'
22import {
33 addTrailingSlash ,
44 isExternalUrl ,
@@ -31,6 +31,8 @@ const ExternalSiteLink_ = ({
3131} : ExternalSiteLinkProps ) => {
3232 const isPrint = useIsPrint ( )
3333
34+ const { siteData } = usePageData ( )
35+
3436 const site = useMemo (
3537 ( ) => virtual . sites ?. find ( ( s ) => s . name === name ) ,
3638 [ name ] ,
@@ -52,7 +54,7 @@ const ExternalSiteLink_ = ({
5254
5355 let { url, hash } = parseUrl ( href )
5456
55- const extname = url . split ( '.' ) . pop ( )
57+ const extname = url . split ( '.' ) . at ( - 1 )
5658
5759 if ( extname ) {
5860 if ( DEFAULT_PAGE_EXTENSIONS . includes ( `.${ extname } ` ) ) {
@@ -70,7 +72,7 @@ const ExternalSiteLink_ = ({
7072 ( isUnversioned ( virtual . version )
7173 ? site . base
7274 : addTrailingSlash ( site . base + site . version ) ) +
73- ( lang ? addTrailingSlash ( lang ) : '' ) +
75+ ( lang && lang !== siteData . lang ? addTrailingSlash ( lang ) : '' ) +
7476 ( hash ? `${ url } #${ hash } ` : url )
7577 }
7678 target = "_blank"
You can’t perform that action at this time.
0 commit comments