Skip to content

Commit 9da4be9

Browse files
committed
fix: consider basePath when generating presenter URLs
1 parent fa85375 commit 9da4be9

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

packages/client/logic/slides.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export function getSlidePath(
2020
if (typeof route === 'number' || typeof route === 'string')
2121
route = getSlide(route)!
2222
const no = route.meta.slide?.frontmatter.routeAlias ?? route.no
23-
return exporting ? `/export/${no}` : presenter ? `/presenter/${no}` : `/${no}`
23+
const basePath = import.meta.env.BASE_URL.replace(/\/$/, '') ?? ''
24+
const path = exporting ? `/export/${no}` : presenter ? `/presenter/${no}` : `/${no}`
25+
return `${basePath}${path}`
2426
}
2527

2628
export function useIsSlideActive() {

test/utils.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { ResolvedFontOptions, SlideInfo } from '@slidev/types'
1+
import type { ResolvedFontOptions, SlideInfo, SlideRoute } from '@slidev/types'
22
import { relative, resolve } from 'node:path'
33
import { slash } from '@antfu/utils'
4+
import { getSlidePath } from '@slidev/client/logic/slides'
45
import MarkdownIt from 'markdown-it'
56
import { describe, expect, it } from 'vitest'
67
import YAML from 'yaml'
@@ -145,4 +146,28 @@ describe('utils', () => {
145146
"
146147
`)
147148
})
149+
150+
it('getSlidePath with base path', () => {
151+
const originalBaseUrl = import.meta.env.BASE_URL
152+
153+
import.meta.env.BASE_URL = '/my_monorepo/my_prez/'
154+
155+
const mockRoute: SlideRoute = {
156+
no: 2,
157+
meta: {
158+
slide: {
159+
frontmatter: {},
160+
},
161+
},
162+
}
163+
164+
expect(getSlidePath(mockRoute, false, false)).toBe('/my_monorepo/my_prez/2')
165+
expect(getSlidePath(mockRoute, true, false)).toBe('/my_monorepo/my_prez/presenter/2')
166+
expect(getSlidePath(mockRoute, false, true)).toBe('/my_monorepo/my_prez/export/2')
167+
168+
import.meta.env.BASE_URL = '/'
169+
expect(getSlidePath(mockRoute, false, false)).toBe('/2')
170+
171+
import.meta.env.BASE_URL = originalBaseUrl
172+
})
148173
})

0 commit comments

Comments
 (0)