#Trailing slash inconsistences with Starlight

5 messages · Page 1 of 1 (latest)

meager rover
#

Hello! I posted this in #starlight and was asked to make a support thread so ta-da. Copying my message from that channel with additional information:

Original post:

I've noticed that trailing slashes are not consistent in starlight, is this correct?

If you define an internal link using the shorthand:

      sidebar: [
        "welcome",
...

It will generate a url to {site}/welcome.

But if you instead use autogenerate to do something like (and create a welcome/welcome.mdx to go along with it):

   sidebar: [
        {
          label: 'Welcome',
          autogenerate: { directory: 'welcome' },
        },
...

It will generate a url to {site}/welcome/welcome/.

If you enable trailingSlash: "always", then it will add the trailing slash at the end of the first example, but even in production (using preview) which seems counter to what the docs say?

Is this correct, this seems wrong to me but maybe I'm missing something.


Additional information:

I spun up a fresh starlight project and you can obverse the same thing with the stock examples that are generated. The Example Guide (which uses a slug) is missing a trailing slash, where as the Reference (which uses autogenerate) contains a trailing slash.

When you build (and true in dev too, but trailingSlash is not supposed to affect prod), you can also see the hrefs that get generated in the files in the dist folder - when trailingSlash is not set (so default ignore) the href for the example guide is href="/guides/example" but when you set trailingSlash to always, the href in the html changes to href="/guides/example/"

Let me know if you need any further information! Thank you!

#

superior-satellite@0.0.1 astro C:\Users\marty\Offline Projects\Starlight Test
astro "info"

Astro v4.16.2
Node v20.10.0
System Windows (x64)
Package Manager pnpm
Output static
Adapter none
Integrations <@&1055234544183287879>/starlight

Astro info on the fresh project if that's helpful

alpine solstice
#

Hi @meager rover! Starlight uses the Astro trailingSlash option to decide how to handle slashes, but the default is trailingSlash: 'ignore', which means we don’t really have a good indication of what a user wants, so I guess it makes sense it’s not always consistent — with the 'never' or 'always' options we have a clear signal which way to go.

meager rover
#

Awesome thanks for the response and confirmation! I guess the docs is tricky because the note about the trailing slashes affecting only Dev is in the astro docs and not the starlight ones because it's not technically a starlight thing.

I guess this would be good to document the behaviour and maybe even treat ignore as always I guess for this purpose? That should still be compatible with the intent behind the trailingSlash option I believe?

waxen pendantBOT
#
If your issue is resolved, please help by doing the following two steps:
  1. From the ellipses (3-dot menu) in the top-right corner of the post (not the first message), edit the tags to include the Solved tag.
  2. From the same ellipses, select Close Post.
    Your post will still be available to search and can be re-opened simply by replying in it. Closing a post moves it down with older posts, so we can more easily focus on issues that still need to be resovled.
    Thank you for your help!