-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Table of contents links are incorrect when layout includes <base> element in <head> #4735
Comments
This also affects the statically generated pages. |
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
Stale or not, I can confirm that this issue exists across multiple browsers. The Table of Contents generated by Hugo is essentially broken if |
@jeetsukumaran That seems the obvious solution...not sure how doable it is withing hugo code. |
@digitalcraftsman for ToC does it still just generated #anchors even with BaseURL, and is there a way to configure it to generate the right URL when using BaseURL? |
Since EDIT: I came up with a JS hack that you need to insert into the <script>
document.querySelectorAll('#TableOfContents a').forEach((node) => node.setAttribute('href', {{ .Permalink }} + node.getAttribute('href')))
</script> |
Depending on your use case, I was able to make similar adjustments in the template using:
Hope that this helps. |
This issue has been discussed before. I will redo the ToC integration in the not so distant future and will have this in mind. Curious: Why do you need |
|
It's mentioned in this section https://github.com/gohugoio/hugoThemes#adding-a-theme-to-the-list |
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
The table of content outputs anchor links like "#section", whether you run hugo with the This means that when you use the To fix this in the table of content, I came up with this workaround:
This prefixes the anchor links with the relative link of the current page. When the browser adds the base URL prefix to that, everything will work fine. |
Some themes include a However, I believe that the table of contents links should work either way, and have re-opened this issue. We recently fixed a similar problem with the pagination template. @thombergs Hugo does not insert a |
@jmooring right, thanks for clearing that up. I didn't check if the Anyway, if Hugo's table of contents would render |
I think it would need to be We have another issue that would allow people to render the ToC items as they please -- I'm closing this in favour of #5087 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
With Hugo version v0.40.3 using the {{ .TableOfContents }} variable when one has a
<base href="$.Site.BaseURL">
in a<HEAD>
section, and usinghugo server
fails with Firefox (both ESR and 5x.xSpecifically the relative references for page fragments (e.g.
href="#nameofheading"
) get turned intohttp://localhost:1313/#nameofheading
instead of properly being relative (.e.g. on a /section1/page1/ you should gethttp://localhost:1313/section1/page1/#nameofheading
).I'm not not sure if this is a browser issue or a Hugo issue, when using BaseURL (as required by the theme site, becase of issue #2575)
The text was updated successfully, but these errors were encountered: