vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
13.29k stars 2.15k forks source link

Fix documentation regarding anchor links #4193

Closed bjoernmartin closed 1 month ago

bjoernmartin commented 2 months ago

Working with vitepress v1.3.3, I noticed a link in the format ./#heading does not work / leads to a docs generation error, whereas #heading works for me. Hence this PR.

Description

Linked Issues

Additional Context


[!TIP] The author of this PR can publish a preview release by commenting /publish below.

brc-dd commented 1 month ago

read the sentence again, it's to go to foo/index.md#heading from foo/one.md

what you've written is how you jump to different header within the same file

bjoernmartin commented 1 month ago

It still fixed working with Vitepress for me, so no idea how your explanation invalidates that. But who am I to force you accepting help?

brc-dd commented 1 month ago

That section reads:

For example, given the following directory structure:

. ├─ index.md ├─ foo │ ├─ index.md │ ├─ one.md │ └─ two.md └─ bar ├─ index.md ├─ three.md └─ four.md


And providing you are in `foo/one.md`:

...

[foo heading](./#heading) <!-- anchors user to a heading in the foo index file -->

So, if you make it

[foo heading](#heading)

It will go to /foo/one.html#heading not /foo/#heading

The original version might have caused issue for you because you might not have a foo/index.md in first place. So, trying to link to it rightfully threw dead link found error.

image