Skip to content
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

Feature request: anchor links on hover #935

Closed
ottok opened this issue Jan 28, 2024 · 7 comments · Fixed by #992
Closed

Feature request: anchor links on hover #935

ottok opened this issue Jan 28, 2024 · 7 comments · Fixed by #992

Comments

@ottok
Copy link

ottok commented Jan 28, 2024

What happened?

Sometimes people want to link directly to a section in a post. This could be made easy with an anchor link that comes visible on hover would. See example of hover effect/link in The Stack docs.

image

Hugo version

0.122.0

Theme version

1.0.0

What browsers are you seeing the problem on?

Chrome

More information about the browser

No response

Relevant log output

No response

Link to Minimal Reproducible Example

https://optimizedbyotto.com

CaiJimmy added a commit that referenced this issue Mar 27, 2024
CaiJimmy added a commit that referenced this issue Mar 27, 2024
NapalmCodes pushed a commit to NapalmCodes/hugo-theme-stack that referenced this issue Mar 30, 2024
* fix(sidebar): hide translations selector if only one translation available (CaiJimmy#950)

hide translations menu if only one translation available

* release: 3.22.0

* fix(sidebar): translation selector - avoid cast per PR CaiJimmy#950  (CaiJimmy#961)

avoid cast per PR CaiJimmy#950

* feat(comments): add support for Beaudar(表达)comment system (CaiJimmy#931)

https://beaudar.lipk.org/

* fix(comment): moved waline `placeholder` parameter to `locale.placeholder` (CaiJimmy#914)

fix waline parameter

* fix(sidebar): improve accessibility of sidebar bottom menu (CaiJimmy#925)

* fix(menu): <ol> containing other than <li>, <script> or <template> elements

* fix(menu): add title to language select menu

* release: 3.23.0

* fix(i18n): add missing `zh-cn` translations (CaiJimmy#964)

* feat: update Hugo version and minimum version requirement to 0.123.0 (CaiJimmy#970)

* fix: `.Site.LastChange` deprecation (CaiJimmy#968)

Fix the deprecation warning emitted from Hugo, and fix the typo in ` exampleSite/content/page/about/index.md`

* feat: bump KaTeX to latest released version `0.16.9` (CaiJimmy#969)

Bump KaTeX to latest released version 0.16.9

* fix(sidebar): menu-bottom-section not showing in mobile (CaiJimmy#966)

* fix(sidebar): Bottom section not showing in mobile

* fix(sidebar): Align bottom section to bottom

* fix(sidebar): Gap missing in bottom section

* refactor(sidebar): Simplify styles

* refactor(sidebar): Remove useless padding-left

* refactor(sidebar): Remove useless margin-top

* refactor(sidebar): Combine duplicate flex-direction

* refactor(sidebar): Remove redundant width

* release: 3.24.0

* fix(head): prevent Go template from escaping HTML entities in meta description (CaiJimmy#973)

* fix: favicon does not load if baseurl includes a subfolder (CaiJimmy#972)

Use relURL https://gohugo.io/functions/urls/relurl/

* release: 3.24.1

* fix: remove `\n` character from meta description (CaiJimmy#980)

* fix: deprecation warning for `.Site.Author` (CaiJimmy#979)

Fix deprecation warning for .Site.Author, deprecated in Hugo 0.124.0

* release 3.24.2

* fix: use page resource permalink in link image (CaiJimmy#990)

closes CaiJimmy#982

* docs: update some invalid documentation links (CaiJimmy#983)

Update some documentation links (some were dead links)

* feat(i18n): update translations for `ja` (CaiJimmy#984)

* feat(i18n): update translations for `ja`

* Apply review suggestions

* fix(i18n): wrap `footer.builtWith` with double quotes in Japanese translation (CaiJimmy#991)

* feat: add anchor link to markdown heading (CaiJimmy#992)

closes CaiJimmy#935

* fix: rename `.social-menu` to `.menu-social` to avoid being blocked by ad blockers (CaiJimmy#993)

closes CaiJimmy#924

* fix: make KaTeX render all math inside `document.body` (CaiJimmy#994)

Since it only accepts one element, I cannot pass `.article-content` and `#TableOfContent` to it. The official documentation uses `document.body` directly, so I guess that's fine.

closes CaiJimmy#882

* release: 3.25.0

* Fix to dark mode toggle

* Style fixes

* Style fixes

* Style fix

* Tweak

* Fix

* Remove hash sign

* Make sub heading text the anchor

---------

Co-authored-by: James McMurry <jmcmurry@semanticnoise.com>
Co-authored-by: Jimmy Cai <hi@jimmycai.com>
Co-authored-by: Jiarong Hong <64763790+hongjr03@users.noreply.github.com>
Co-authored-by: L-Super <40905056+L-Super@users.noreply.github.com>
Co-authored-by: Jiahao Li <42709836+TheJiahao@users.noreply.github.com>
Co-authored-by: Zeyu Huang <fhfuih@outlook.com>
Co-authored-by: Andreas Deininger <andreas@deininger.net>
Co-authored-by: Andrew Doering <delize@users.noreply.github.com>
Co-authored-by: andrewmoise <andrew.moise@gmail.com>
Co-authored-by: Shun Sakai <sorairolake@protonmail.ch>
@ottok
Copy link
Author

ottok commented Mar 30, 2024

I confirm anchor links were introduced in 539c39d, but seems they are always visible instead of appearing on hover like they do on in for example The Stack docs. I am double-checking if this is a result of my own customizations conflicting or what is going on.

@CaiJimmy
Copy link
Owner

I confirm anchor links were introduced in 539c39d, but seems they are always visible instead of appearing on hover like they do on in for example The Stack docs. I am double-checking if this is a result of my own customizations conflicting or what is going on.

It was not actually implemented. I'll make a patch for it. It looks better if it only appears on hover, which reduces visual clutter.

@ottok
Copy link
Author

ottok commented Mar 31, 2024

Ok, good to know, I will then wait for you to do it as you are likely to do it better than me.

If it helps, here are my notes:

# The Stack theme markup currently
<h2 id="example-4">
    <a href="#example-4">#</a>
    Example 4
</h2>

# Documentation site markup
<h2 id="cover" tabindex="-1">
  cover 
  <a class="header-anchor" href="#cover" aria-label="Permalink to &quot;cover&quot;">​</a>
</h2>

# CSS on documentation site that places '#' character in :before of the h2 title
.vp-doc .header-anchor {
    position: absolute;
    top: 0;
    left: 0;
    margin-left: -.87em;
    font-weight: 500;
    -webkit-user-select: none;
    user-select: none;
    opacity: 0;
    text-decoration: none;
    transition: color .25s, opacity .25s;
}
.vp-doc h2 .header-anchor {
    top: 24px;
}
.vp-doc .header-anchor:before {
    content: var('#');
}

# By default the '#' character is same color as background, and on hover it becomes visible with transition animation
.vp-doc a:hover {
    color: var('green');
}

@CaiJimmy
Copy link
Owner

CaiJimmy commented Apr 2, 2024

It's available already (#999), thanks for the tip!

@ottok
Copy link
Author

ottok commented Apr 7, 2024

I noticed that the HTML markup you have in the implementation now adds a link permanently in the page. For example:

<h2 id="learnings-from-heartbleed"><a href="#learnings-from-heartbleed" class="header-anchor">#</a>
Learnings from Heartbleed</h2>

This results in RSS feed readers and screen readers seeing an extra # now. The implementation on the theme docs site (e.g. https://stack.jimmycai.com/config/image-processing#cover) is better as it is based on CSS :before rule, and does not pollute anything visible in the output. It also has a aria-label for screen readers.

@getvictor
Copy link

I agree. The extra # does not look good and looks like a bug. Example: https://demo.stack.jimmycai.com/p/image-gallery/

What's the easiest way to get rid of it? Downgrade to the previous version?

@CaiJimmy
Copy link
Owner

CaiJimmy commented May 2, 2024

I agree. The extra # does not look good and looks like a bug. Example: https://demo.stack.jimmycai.com/p/image-gallery/

What's the easiest way to get rid of it? Downgrade to the previous version?

This has been fixed now with #1016.

albanpetit pushed a commit to albanpetit/albanpetit.com-theme that referenced this issue May 3, 2024
186526 pushed a commit to 186526/hugo-theme-stack that referenced this issue May 6, 2024
cyp0633 pushed a commit to cyp0633/stack-mod that referenced this issue Jul 8, 2024
ous50 pushed a commit to ous50/hugo-theme-stack that referenced this issue Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants