Skip to content

URL Becomes // (Double Slash) When Using root Option #5

@ghost

Description

📝 URL Becomes // (Double Slash) When Using root Option

Hi there, I'm still learning how to use @braindb/astro, and I ran into a small issue when I changed the root option in my astro.config.mjs.

💡 Example Config

import { brainDbAstro } from "@braindb/astro";

export default defineConfig({
  integrations: [
    brainDbAstro({
      root: 'src/content/example',
      remarkWikiLink: true,
      git: false
    }),
  ],
});

😕 Problem

After running the build, the generated URLs look like this:

//example/entry/

But I was expecting something like:

/example/entry/

I checked the code and found this part in slugToUrl():

var slugToUrl = (slug) => {
  if (!slug.startsWith("/")) slug = `/${slug}`;
  if (!slug.endsWith("/")) slug = `${slug}/`;
  return slug;
};

It looks like generateSlug() sometimes already returns a slug that starts with /, so slugToUrl() ends up adding another slash at the beginning.


✅ Temporary Fix I Tried

I changed the function to this:

var slugToUrl = (slug) => {
  if (!slug.startsWith("/")) slug = `/${slug}`;
  if (!slug.endsWith("/")) slug = `${slug}/`;

  // <<--<<
  slug = slug.replace(/^\/+/, "").replace(/\/+$/, "");
  return `/${slug}/`;
  // >>-->>

  //return slug;
};

This fixed the issue for me — now URLs look clean and correct.


🙏 Just a Thought

I'm still learning, so I'm not sure if this is the best fix — but I wanted to share in case this helps improve the default behavior, or maybe save time for other users who run into this.

Thanks a lot for the awesome project and for your time! 😊


and I hope, there is a more detailed tutorial about brainDb hehe..😁

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions