facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
55.4k stars 8.31k forks source link

Blog anchor links in paginated lists should be resolved against blog post url, not current url #10287

Open afunkliru opened 2 months ago

afunkliru commented 2 months ago

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Anchor tags shown on an entry of https://docusaurus.io/blog, doesn't go to the entry page's anchor tag. It goes to the https://docusaurus.io/blog#ANCHOR-TAG.

Reproducible demo

No response

Steps to reproduce

  1. go to https://docusaurus.io/blog with a description that links to an anchor tag on the entry's page
  2. Click on anchor tag in the entry page's one-liner description above the truncate line.
  3. Goes to broken link.

Expected behavior

Expect to go to the entry page's anchor, not to stay on the blog's home page.

Actual behavior

Stays on blog's home page.

Your environment

Self-service

OzakIOne commented 1 month ago

I'm not sure that I understood, you expect https://docusaurus.io/blog#Docusaurus-3.1 to scroll to Docusaurus 3.1 title ?

slorber commented 1 month ago

It's hard to understand what it's about indeed, can you please provide a concrete runnable example and screenshots?

What I think I understand is that you have anchor tag links [xyz](#xyz) appearing above the blog <!-- truncate --> marker (if any), so they get rendered in the blog paginated views. And you expect clicking those anchors to lead to https://docusaurus.io/blog/post#xyz instead of https://docusaurus.io/blog/#xyz, is that correct?

Josh-Cena commented 1 month ago

@slorber Yes, I believe what you said is the expected behavior.

I could see a reason for wanting this, and I don't think it's impossible to build—we just need to resolve anchor links to absolute URLs. I'm actually surprised if we are not doing that atm.

slorber commented 1 month ago

I'm actually surprised if we are not doing that atm.

Afaik no we are not doing that atm.

It's not just anchor links, but all relative links in general (which we advise to not use, but still an edge case to solve)

Josh-Cena commented 1 month ago

It occurs to me as safe to normalize them, since each page can only map to one slug. But I'm not sure if the Markdown loader can be aware of the current page's mapped URL, or how we should take care of imported Markdown, etc.

Maybe we can at least do this in the blog plugin that processes the truncated query? Not sure.