Core: Support calling getPage(slugs) with URI encoded slugs

This commit is contained in:
Fuma Nama
2025-11-21 20:42:34 +08:00
parent 42ad84c247
commit 2e0172050b
2 changed files with 15 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-core': patch
---
[Loader API] Support calling `loader().getPage(slugs)` with URI encoded slugs
+10 -2
View File
@@ -119,7 +119,7 @@ export interface LoaderOutput<Config extends LoaderConfig> {
}[];
/**
* Get page with slugs
* Get page with slugs, the slugs can also be URI encoded.
*
* @param language - If empty, the default language will be used
*/
@@ -373,8 +373,16 @@ function createOutput(
return list;
},
// the slugs plugin generates encoded slugs by default.
// we can assume page slugs are always URI encoded.
getPage(slugs = [], language = defaultLanguage) {
return walker.pages.get(`${language}.${slugs.join('/')}`);
// 1. `slugs` is already decoded
let page = walker.pages.get(`${language}.${slugs.join('/')}`);
if (page) return page;
// 1. `slugs` is URI encoded
page = walker.pages.get(`${language}.${slugs.map(decodeURI).join('/')}`);
if (page) return page;
},
getNodeMeta(node, language = defaultLanguage) {
const ref = node.$ref?.metaFile;