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

A bug on image source with baseurl #2235

Closed
juljany opened this issue Aug 20, 2023 · 0 comments · Fixed by #2242
Closed

A bug on image source with baseurl #2235

juljany opened this issue Aug 20, 2023 · 0 comments · Fixed by #2242
Assignees
Labels
bug Something isn't working

Comments

@juljany
Copy link

juljany commented Aug 20, 2023

Environment

Nuxi 3.6.5 11:44:45 AM
11:44:45 AM
RootDir: /Blog/BlogProject 11:44:45 AM
Nuxt project info: 11:44:45 AM


  • Operating System: Linux
  • Node Version: v20.3.0
  • Nuxt Version: 3.6.5
  • Nitro Version: 2.5.2
  • Package Manager: npm@9.6.7
  • Builder: vite
  • User Config: devtools, modules, content, app
  • Runtime Modules: @nuxt/content@2.7.2
  • Build Modules: -

Reproduction

This issue is very obvious.

  1. Add baseurl in either of the following two ways
    in package.json
    "generate": "NUXT_APP_BASE_URL=/blog/ nuxt generate",
    or in nuxt.config.ts
    app:{
    baseURL:"/blog/"
    }

  2. Add an image url in a markdown file

![xx](/blog-images/image-name.png)
  1. Copy src/runtime/components/Prose/ProseImg.vue (commit id: d2e2fba, lastest when typing) to components/content/ProseImg.vue and write line 28~33 to the following.

Just added some prints.

const refinedSrc = computed(() => {
    if (props.src?.startsWith('/') && !props.src.startsWith('//')) {
        console.log("xxxxxx", withBase(props.src, useRuntimeConfig().app.baseURL), useRuntimeConfig().app.baseURL)
        return withBase(props.src, useRuntimeConfig().app.baseURL)
    }
    console.log("yyyyyy", withBase(props.src, useRuntimeConfig().app.baseURL), useRuntimeConfig().app.baseURL)
    return props.src
})

Describe the bug

If when baseurl is "/blog/", it prints
xxxxxx /blog-images/image-name.png /blog/

When baseurl is "/xblog/", it prints
xxxxxx /xblog/blog-images/image-name.png /xblog/

That is if the image url startswith getoffrightslash(baseurl), the baseurl won't be prefixed before the imageurl. This is a bug of function withBase(), which is from package ufo.

Additional context

No response

Logs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants