Skip to content

Commit

Permalink
fix: doc sidebar when cleanUrls is enabled (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 authored Jan 2, 2024
1 parent 6ac3d36 commit e1619c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/smooth-pugs-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rspress/theme-default': patch
'@rspress/shared': patch
---

fix: sidebar disappeared in cleanUrl mode
12 changes: 7 additions & 5 deletions packages/shared/src/runtime-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,16 @@ export function replaceLang(
default: string;
},
base = '',
cleanUrls = false,
) {
let url = removeBase(rawUrl, base);
// rspress.dev/builder + switch to en -> rspress.dev/builder/en/index.html
if (!url) {
url = '/index.html';
url = cleanUrls ? '/index' : '/index.html';
}

if (url.endsWith('/')) {
url += 'index.html';
url += cleanUrls ? '/index' : '/index.html';
}

let versionPart = '';
Expand All @@ -159,7 +160,7 @@ export function replaceLang(
purePathPart = parts.join('/') || '';

if ((versionPart || langPart) && !purePathPart) {
purePathPart = 'index.html';
purePathPart = cleanUrls ? 'index' : 'index.html';
}

return withBase(
Expand All @@ -178,11 +179,12 @@ export function replaceVersion(
default: string;
},
base = '',
cleanUrls = false,
) {
let url = removeBase(rawUrl, base);
// rspress.dev/builder + switch to en -> rspress.dev/builder/en/index.html
if (!url) {
url = '/index.html';
url = cleanUrls ? '/index' : '/index.html';
}
let versionPart = '';

Expand All @@ -200,7 +202,7 @@ export function replaceVersion(
let restPart = parts.join('/') || '';

if (versionPart && !restPart) {
restPart = 'index.html';
restPart = cleanUrls ? 'index' : 'index.html';
}

return withBase(
Expand Down
4 changes: 4 additions & 0 deletions packages/theme-default/src/components/Nav/menuDataHooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function useTranslationMenuData() {
const localeLanguages = Object.values(
siteData.locales || siteData.themeConfig.locales || {},
);
const cleanUrls = siteData.route?.cleanUrls || false;
const hasMultiLanguage = localeLanguages.length > 1;
const { lang: currentLang } = page;
const { base } = siteData;
Expand Down Expand Up @@ -39,6 +40,7 @@ export function useTranslationMenuData() {
default: defaultVersion,
},
base,
cleanUrls,
),
})),
activeValue: localeLanguages.find(item => currentLang === item.lang)
Expand All @@ -52,6 +54,7 @@ export function useVersionMenuData() {
const { siteData } = usePageData();
const currentVersion = useVersion();
const { pathname } = useLocation();
const cleanUrls = siteData.route?.cleanUrls || false;
const defaultVersion = siteData.multiVersion.default || '';
const versions = siteData.multiVersion.versions || [];
const { base } = siteData;
Expand All @@ -66,6 +69,7 @@ export function useVersionMenuData() {
default: defaultVersion,
},
base,
cleanUrls,
),
})),
text: currentVersion,
Expand Down

0 comments on commit e1619c7

Please sign in to comment.