Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to allow setting base when starting a slide deck with slidev #2005

Closed
branaway opened this issue Jan 11, 2025 · 5 comments · Fixed by #2028
Closed

to allow setting base when starting a slide deck with slidev #2005

branaway opened this issue Jan 11, 2025 · 5 comments · Fixed by #2028
Labels
enhancement New feature or request planned

Comments

@branaway
Copy link

Is your feature request related to a problem? Please describe.

slidev slides.html does not take a base parameter, like the build does. Sometimes I need an extra path segment for easier routing behind a proxy.

Describe the solution you'd like
A clear and concise description of what you want to happen.

take a base parameter like the build command does.

@branaway branaway added the enhancement New feature or request label Jan 11, 2025
@jmuchovej
Copy link

so, poking around the @slidev/client – it seems that the issue is that base isn't getting prepended to the __ENTRY__ value in @slidev/client/index.html. i'm not entirely sure how to modify the code in @slidev/cli/setups/indexHtml.ts to get this to work though.

export default function setupIndexHtml({ mode, entry, clientRoot, userRoot, roots, data }: Omit<ResolvedSlidevOptions, 'utils'>): string {
let main = readFileSync(join(clientRoot, 'index.html'), 'utf-8')
let head = ''
let body = ''
const { info, author, keywords } = data.headmatter
head += [
`<meta name="slidev:version" content="${version}">`,
mode === 'dev' && `<meta charset="slidev:entry" content="${slash(entry)}">`,
`<link rel="icon" href="${data.config.favicon}">`,
`<title>${getSlideTitle(data)}</title>`,
info && `<meta name="description" content=${toAttrValue(info)}>`,
author && `<meta name="author" content=${toAttrValue(author)}>`,
keywords && `<meta name="keywords" content=${toAttrValue(Array.isArray(keywords) ? keywords.join(', ') : keywords)}>`,
].filter(Boolean).join('\n')
for (const root of roots) {
const path = join(root, 'index.html')
if (!existsSync(path))
continue
const index = readFileSync(path, 'utf-8')
if (root === userRoot && index.includes('<!DOCTYPE')) {
console.error(yellow(`[Slidev] Ignored provided index.html with doctype declaration. (${white(path)})`))
console.error(yellow('This file may be generated by Slidev, please remove it from your project.'))
continue
}
head += `\n${(index.match(/<head>([\s\S]*?)<\/head>/i)?.[1] || '').trim()}`
body += `\n${(index.match(/<body>([\s\S]*?)<\/body>/i)?.[1] || '').trim()}`
}
if (data.features.tweet)
body += '\n<script async src="https://platform.twitter.com/widgets.js"></script>'
if (data.config.fonts.webfonts.length && data.config.fonts.provider !== 'none')
head += `\n<link rel="stylesheet" href="${generateGoogleFontsUrl(data.config.fonts)}" type="text/css">`
if (data.headmatter.lang)
main = main.replace('<html lang="en">', `<html lang="${data.headmatter.lang}">`)
main = main
.replace('__ENTRY__', toAtFS(join(clientRoot, 'main.ts')))
.replace('<!-- head -->', head)
.replace('<!-- body -->', body)
return main
}

@branaway
Copy link
Author

There are lots of places in the code that assumes the whole app runs on root instead of one a url path. It requires reworking in multiple places including external plugins, as far as I can see.

@jmuchovej
Copy link

jmuchovej commented Feb 5, 2025

@kermanx (thanks for submitting this PR! 🙏)

idk if this meets what @branaway intended; but something i was hoping to achieve was actually... consider the following slide headmatter:

citations:
  bibliography: /references.bib
  template:
    bibliography: /apa7.csl
    inTextCitation: /apa7.csl
    inTextReference: /apa7-intext.csl

without a base URL these work flawlessly (as do all <img src="/path/to/image.png" />); however, once a base URL is set, the headmatter breaks down. this could actually be an issue with Vite, but i'm not certain.

@kermanx
Copy link
Member

kermanx commented Feb 6, 2025

without a base URL these work flawlessly (as do all <img src="/path/to/image.png" />); however, once a base URL is set, the headmatter breaks down. this could actually be an issue with Vite, but i'm not certain.

Opened #2055 to track this problem.

@branaway
Copy link
Author

branaway commented Feb 7, 2025

@kermanx (thanks for submitting this PR! 🙏)

idk if this meets what @branaway intended; but something i was hoping to achieve was actually... consider the following slide headmatter:

citations:
bibliography: /references.bib
template:
bibliography: /apa7.csl
inTextCitation: /apa7.csl
inTextReference: /apa7-intext.csl
without a base URL these work flawlessly (as do all <img src="/path/to/image.png" />); however, once a base URL is set, the headmatter breaks down. this could actually be an issue with Vite, but i'm not certain.

will relative path work for you? something like:

citations:
  bibliography: ./references.bib

I haven't tested out the base path implementation yet, but my quick glance to the code changes has left me with an impression that there might be some corner cases that are not been covered. One of them is the navigation sync module to sync front end state back the server, introduced in one of the last couple of releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request planned
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants