athul / archie

A minimal Hugo Theme
https://athul.github.io/archie
MIT License
977 stars 299 forks source link

Link to section #81

Open sean-smith opened 1 year ago

sean-smith commented 1 year ago

Would be great to add a click to create an anchor link to link to subsections. Here's an example:

image

I would love it if you could click on the ##Setup and get an anchor link like: https://swsmith.cc/posts/cost-explorer-pcluster.html#setup

The id is already setup so the only feature is to add this as a link to any headers in markdown.

sean-smith commented 7 months ago

Ok, I can get the behaviour I want with:

{{< rawhtml >}}
<a href='#setup'><h2>Setup</h2></a>
{{< /rawhtml >}}

Instead of:

## Setup

Obviously it would be ideal if this was done at the markdown layer so I don't have to go through and change all my section headers.

Any pointers on how to do that? Basically override the rendering of h1,h2,h3... headers to render as a link

sean-smith commented 7 months ago

Ok I implemented this on my site using some custom js, this looks like:

image

Example: https://swsmith.cc/posts/efa-best-practices.html#what-version-is-best

The code looks like:

https://github.com/sean-smith/swsmith.cc/commit/ea2ac86c466ff60edd49055b6bf72b17e007f9c2

If anyone is interested I'll open a pull request to contribute this back upstream.