mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-09 06:41:18 +00:00
Add support for root destination markdown routing in toMarkdownDestination
This commit is contained in:
@@ -81,6 +81,11 @@ describe('toMarkdownDestination', () => {
|
||||
expect(toMarkdownDestination('/docs/new-page/?a=1#b')).toBe('/docs/new-page.md?a=1#b');
|
||||
});
|
||||
|
||||
it('points the site root to its markdown route', () => {
|
||||
expect(toMarkdownDestination('/')).toBe('/.md');
|
||||
expect(toMarkdownDestination('/?a=1#b')).toBe('/.md?a=1#b');
|
||||
});
|
||||
|
||||
it('leaves markdown paths and external URLs untouched', () => {
|
||||
expect(toMarkdownDestination('/docs/new-page.md')).toBe('/docs/new-page.md');
|
||||
expect(toMarkdownDestination('https://example.com/page')).toBe('https://example.com/page');
|
||||
|
||||
@@ -99,11 +99,12 @@ export function toMarkdownDestination(destination: string): string {
|
||||
|
||||
const url = new URL(destination, 'https://gitbook.invalid');
|
||||
const pathname = url.pathname.replace(/\/+$/, '');
|
||||
if (!pathname || pathname.endsWith('.md')) {
|
||||
if (pathname.endsWith('.md')) {
|
||||
return destination;
|
||||
}
|
||||
|
||||
return `${pathname}.md${url.search}${url.hash}`;
|
||||
// A root destination trims to an empty pathname; its markdown route is `/.md`.
|
||||
return `${pathname || '/'}.md${url.search}${url.hash}`;
|
||||
}
|
||||
|
||||
function markdownRedirect(location: string, permanent: boolean) {
|
||||
|
||||
Reference in New Issue
Block a user