HiDeoo / starlight-links-validator

Starlight plugin to validate internal links
https://starlight-links-validator.vercel.app
MIT License
62 stars 5 forks source link

linking to /Index.mdx #56

Closed robmunger closed 2 months ago

robmunger commented 2 months ago

Describe the bug

This is super minor - an annoyance, really.

If the site homepage is named Index.md instead of index.md, the site works fine if starlight-links-validator isn't used.

However, if starlight-links-validator is used, it will identify all links to / as invalid and will prevent the site from building.

To Reproduce

  1. Start a new Starlight site and add starlight-links-validator.
  2. Rename /src/content/docs/index.md to Index.md.
  3. Add a link to the homepage to a markdown page. For example, I added [home page](/) to /src/content/docs/guides/example.md
  4. npm run build
  5. I get the following error:
    
    validating links 
    15:08:24 [ERROR] ✗ Found 1 invalid link in 1 file.
    15:08:24 ▶ guides/example/
    15:08:24   └─ / - invalid link

[AstroUserError] Links validation failed.



Here is a stackblitz:
https://stackblitz.com/github/withastro/starlight/tree/main/examples/basics?file=src%2Fcontent%2Fdocs%2Fguides%2Fexample.md

### Expected behavior

The build should complete. 

If I build the site without starlight-links-validator, the site builds and the links work properly, whether the file is named with an upper or lower-case i.

I like using PascalCase for my .mdx files because I can read them more easily, so I like the flexibility provided by vanilla Astro to name the file Index.mdx.

### How often does this bug happen?

Every time

### System Info

I ran it on stackblitz:
https://stackblitz.com/github/withastro/starlight/tree/main/examples/basics?file=src%2Fcontent%2Fdocs%2Fguides%2Fexample.md

### Additional Context

Thanks for your awesome link checker!
HiDeoo commented 2 months ago

Thanks for your feedback.

If I build the site without starlight-links-validator, the site builds and the links work properly, whether the file is named with an upper or lower-case i.

This is correct, altho this validator is not only caring about the project building and links working but also by design enforces some other rules, e.g. errors on fallback pages, inconsistent locales, relative links, etc.

I like using PascalCase for my .mdx files because I can read them more easily, so I like the flexibility provided by vanilla Astro to name the file Index.mdx.

Some of the rules I mentioned above have options to be disabled, but the one you're facing is not one of them.

Personally, I think this very specific case should not deserve a new option as it's a very specific case and can also be very confusing for other users/contributors.

I may be entirely wrong so I'll keep an eye on this issue to see if more people are facing the same problem and re-evaluate my opinion if necessary.

In the meantime, I think using the exclude option would be a good workaround as you know the index page exists and you're fine with it being PascalCase.

export default defineConfig({
  integrations: [
    starlight({
      plugins: [
        starlightLinksValidator({
          exclude: ["/"]
        }),
      ],
    }),
  ],
})
CodeAndWeb commented 2 months ago

Funny. I just wanted to create an issue about a link to "/" too ;-) I am using a documentation in which I use / as the first page of the content ("getting started") instead of using the frontend page. https://ngx-translate.org/

robmunger commented 2 months ago

Thanks for pointing out that great workaround! I'll use it. I really like that excluding that page doesn't prevent the software from identifying bad links to anchors on that page.

I wonder if it might be helpful to have a different error message when a link is rejected because the source code file name doesn't follow case conventions. Is that something you'd consider?