📝 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:
But I was expecting something like:
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..😁
📝 URL Becomes
//(Double Slash) When UsingrootOptionHi there, I'm still learning how to use
@braindb/astro, and I ran into a small issue when I changed therootoption in myastro.config.mjs.💡 Example Config
😕 Problem
After running the build, the generated URLs look like this:
But I was expecting something like:
I checked the code and found this part in
slugToUrl():It looks like
generateSlug()sometimes already returns a slug that starts with/, soslugToUrl()ends up adding another slash at the beginning.✅ Temporary Fix I Tried
I changed the function to this:
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..😁