File tree Expand file tree Collapse file tree 3 files changed +23
-16
lines changed
Expand file tree Collapse file tree 3 files changed +23
-16
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' fumadocs-core ' : patch
3+ ' fumadocs-ui ' : patch
4+ ---
5+
6+ Improve ` createRelativeLink ` and ` getPageByHref ` for i18n usage
Original file line number Diff line number Diff line change @@ -92,6 +92,8 @@ export interface LoaderOutput<Config extends LoaderConfig> {
9292 getPageByHref : (
9393 href : string ,
9494 options ?: {
95+ language ?: string ;
96+
9597 /**
9698 * resolve relative file paths in `href` from specified dirname, must be a virtual path.
9799 */
@@ -299,30 +301,26 @@ function createOutput(options: LoaderOptions): LoaderOutput<LoaderConfig> {
299301 set pageTree ( v ) {
300302 pageTree = v ;
301303 } ,
302- getPageByHref ( href , { dir = '' } = { } ) {
303- const pages = Array . from ( walker . pages . values ( ) ) ;
304+ getPageByHref ( href , { dir = '' , language } = { } ) {
305+ const pages = this . getPages ( language ) ;
304306 const [ value , hash ] = href . split ( '#' , 2 ) ;
307+ let target ;
305308
306309 if (
307310 value . startsWith ( '.' ) &&
308311 ( value . endsWith ( '.md' ) || value . endsWith ( '.mdx' ) )
309312 ) {
310313 const hrefPath = joinPath ( dir , value ) ;
311- const target = pages . find ( ( item ) => item . file . path === hrefPath ) ;
312-
313- if ( target )
314- return {
315- page : target ,
316- hash,
317- } ;
314+ target = pages . find ( ( item ) => item . file . path === hrefPath ) ;
315+ } else {
316+ target = pages . find ( ( item ) => item . url === value ) ;
318317 }
319318
320- const target = pages . find ( ( item ) => item . url === value ) ;
321- if ( target )
322- return {
323- page : target ,
324- hash,
325- } ;
319+ if ( ! target ) return ;
320+ return {
321+ page : target ,
322+ hash,
323+ } ;
326324 } ,
327325 getPages ( language = options . i18n ?. defaultLanguage ?? '' ) {
328326 const pages : Page [ ] = [ ] ;
Original file line number Diff line number Diff line change @@ -17,7 +17,10 @@ export function createRelativeLink(
1717 return async function RelativeLink ( { href, ...props } ) {
1818 // resolve relative href
1919 if ( href && href . startsWith ( '.' ) ) {
20- const target = source . getPageByHref ( href , { dir : page . file . dirname } ) ;
20+ const target = source . getPageByHref ( href , {
21+ dir : page . file . dirname ,
22+ language : page . locale ,
23+ } ) ;
2124
2225 if ( target ) {
2326 href = target . hash
You can’t perform that action at this time.
0 commit comments