From 519a08ea6e0ad9cb84c01f18172ce6eac3645435 Mon Sep 17 00:00:00 2001 From: Ricky de Laveaga Date: Thu, 25 Jul 2024 12:41:01 -0700 Subject: [PATCH] add @daviddarnes/heading-anchors (#41) * add @daviddarnes/heading-anchors At least until [#40](https://github.com/rdela/eleventeen/pull/40) finds resolution, building on the work in [#39](https://github.com/rdela/eleventeen/pull/39), adding [daviddarnes/heading-anchors](https://github.com/daviddarnes/heading-anchors) per rec in [11ty/eleventy #3363](https://github.com/11ty/eleventy/issues/3363) Used `position="beforeend"` and styled with a slight adjustment to [demo-styling], adding `vertical-align: bottom;` to `a[href^="#"]` and constraining styles to `heading-anchors` element. [demo-styling]: https://github.com/daviddarnes/heading-anchors/blob/main/demo-styling.html#L11-L25 * move heading-anchors code to base.njk instead of post.njk - add hover + focus styles for anchor links - delete deprecated css - 9.2.21-alpha.17 --- _includes/layouts/base.njk | 34 ++++++++++++++++++++++++++++++++-- eleventy.config.js | 2 ++ package.json | 3 ++- public/css/index.css | 28 ---------------------------- 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/_includes/layouts/base.njk b/_includes/layouts/base.njk index fb6bbe5..d37a1ce 100644 --- a/_includes/layouts/base.njk +++ b/_includes/layouts/base.njk @@ -23,7 +23,33 @@ #} {#- Add an arbitrary string to the bundle #} - {%- css %}* { box-sizing: border-box; }{% endcss %} + {%- css %} +* { box-sizing: border-box; } + +heading-anchors a[href^="#"] { + color: transparent; + display: inline-block; + margin-inline-start: 0.375ch; + max-inline-size: 1ch; + overflow-x: hidden; + pointer-events: none; + text-decoration: none; + vertical-align: bottom; + white-space: nowrap; +} + +heading-anchors a[href^="#"]::before { + content: "#"; + color: var(--text-color-link); + pointer-events: auto; +} + +heading-anchors a[href^="#"]:focus::before, +heading-anchors a[href^="#"]:hover::before { + color: var(--text-color-link-highlight); + text-decoration: underline; +} + {% endcss %} {#- Add the contents of a file to the bundle #} {%- css %}{% include "public/css/index.css" %}{% endcss %} @@ -60,7 +86,9 @@
- {{ content | safe }} + + {{ content | safe }} +