Comments (9)
This is working as intended, cf release blog post: https://docusaurus.io/blog/releases/3.1#broken-anchors-checker
You are creating your own anchors, and fall under this case where you need to tell Docusaurus about the anchors:
Use the broken links API:
useBrokenLinks().collectAnchor("pricing-section")
Alternatively, you can also add onBrokenAnchors: "ignore"
to your config: this will not warn you about such false positives.
Note that I'm not sure having multiple h1 elements on a page like you did is a good semantic html practice.
from docusaurus.
So that means anchor errors get reported on <h1>
but not on <h2>
(etc) links?
from docusaurus.
No, you have to use the API for any anchor you create in your code (if you want to link to it at least, and avoid the warning (that you can turn off anyway)).
What I'm saying is unrelated: it's probably not a best practice to use multiple h1 on the same page. This is unrelated to Docusaurus.
from docusaurus.
Ok. I got it mostly working with useBrokenLinks().collectAnchor("pricing-section")
However, there are side cases that I'd like to report. I'm not sure how you want to handle them.
If I add UTM parameters, I get a broken link warning for:
/blog/post#anchor?utm_source=source
I don't get a broken link warning for
/blog/post?utm_source=source#anchor
Both links work. However, the correct way to format such a link is to add the query parameters first and the anchor at the end like this: /blog/post?utm_source=source#anchor
Maybe the warning could explain in more detail what's wrong.
The other case is if I use an anchor link in a markdown file that points to the same document like this: [information](#anchor)
This also throws a warning.
However, if I add the full path, it's fine: [information](/path/to/document#anchor)
If the path ever changes to the document, that's not ideal. I think [information](#anchor)
should not throw a warning.
from docusaurus.
/blog/post#anchor?utm_source=source
This is simply not a valid query parameter and Docusaurus can't know better than the URL parser itself. I presume it works because of how analytics tools work: they just do a string search for the utm_source
fragment (at least that's how the ancient Urchin Tracking Module worked, if I recall correctly).
[information](#anchor)
Really? That should not be an error. It's used extensively on our own website too. If it still happens on the latest version, maybe send another issue with a minimal repro.
from docusaurus.
Ok about the anchor. It's not only analytics. Docusaurus opens the correct anchor when a misconfigured URL is clicked. So it's just weird that it throws the broken link error. I know that /blog/post#anchor?utm_source=source
is invalid. In my case, I received some texts from a content writer who didn't know about it, and I didn't check. So that's how they ended up in there. I just think it would be nice if other Docusaurus users, who don't know that adding query parameters after an anchor is not a valid way to format a URL, would somehow learn about it. The current warning will leave them more puzzled than help. But if it is not possible to parse this in a way that helps to throw a more informative warning, then that's how it is.
Never mind about [information](#anchor)
it was a spelling error.
Thanks!
from docusaurus.
@alewolf please create repros using Docusaurus.new for each indépendant case, first to prove the issue actually exist and then so that we can study your setup in depth. Here you don't even post the error messages you get.
It's not the role of Docusaurus to teach you about urls. You could also put the domain name after the anchor if you want to. Technically that is probably a valid anchor, so do we want to prevent users from doing so if it's valid bug weird?
Using a ? after a # is weird but if browsers support it, we can't warn users that it is a possible mistake because some users might do that on purpose
from docusaurus.
It's not the role of Docusaurus to teach you about URLs.
You don't have to teach me. Luckily I know how a "valid" URL format looks like.
However, Docusaurus flags those wrongly formatted URLs as broken links, even though you admit, in reality those links work. It's not the best user experience for Docusaurus users who don't know why those broken links are flagged as broken, especially when they work.
So here's a CodeSandbox example: https://codesandbox.io/p/live/3be4c123-896c-4acb-bd98-70a669f0737c
from docusaurus.
Those are actually not wrongly formatted urls.
This url is weird perfectly valid: https://docusaurus.io/docs#anchor?alsoPartOfAnchor=42
It's just that by interverting url parts you probably end up with a valid anchor that is not the one you wanted in the first place.
Docuaurus will tell you that #anchor?alsoPartOfAnchor=42
anchor does not exist on the target page, which is... true
And that anchor is weird, but perfectly valid: we can't reject it because some users migth want to do these weird things that the web allow, on purpose.
from docusaurus.
Related Issues (20)
- Add `showLastUpdateTime` and `showLastUpdateAuthor` to blogs HOT 1
- Add `sortSidebarByLastUpdate` to blogs to change the order in the sidebar HOT 8
- Add `pageBasePath` to blog plugin configuration HOT 3
- Add a trailing slash to feed URLs if `trailingSlash` is enabled HOT 1
- Hide redundant year in dates shown in the Archive page HOT 9
- Enhance support for posts related to events in the past HOT 8
- Error when importing Docusaurus Swizzle component into Netlify CMS HOT 1
- Change code highlight module to Shiki HOT 1
- MDX fails building website when using a <code> inside of a <TabItem> element HOT 3
- 'baseUrl' is ignored in Production routing HOT 5
- Error when importing Docusaurus Swizzle component into Netlify CMS HOT 1
- Allow `tags` in `generated-index` sidebar item HOT 4
- MDX v3.0.1 fails to import <details> HOT 7
- Tabs not working on Docusaurus Static build HOT 5
- Doesn't support protocol-relative URL's HOT 1
- Layout moves around when switching tabs (scroll position issue) HOT 2
- Scripts in head don't load from component on production HOT 2
- The htmlLang setting in the localeConfigs of i18n is invalid, and the source code remains as en HOT 5
- Pages do not support Markdown "file path" links HOT 6
- navigation to '/index.html' with a static web server duplicates the page's content. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docusaurus.