Skip to content

Commit

Permalink
add @daviddarnes/heading-anchors (#41)
Browse files Browse the repository at this point in the history
* add @daviddarnes/heading-anchors

At least until [#40](#40) finds
resolution, building on the work in
[#39](#39), adding
[daviddarnes/heading-anchors](https://github.com/daviddarnes/heading-anchors)
per rec in [11ty/eleventy #3363](11ty/eleventy#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
  • Loading branch information
rdela authored Jul 25, 2024
1 parent 70de112 commit 519a08e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
34 changes: 32 additions & 2 deletions _includes/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down Expand Up @@ -60,7 +86,9 @@
</header>

<main id="skip">
{{ content | safe }}
<heading-anchors position="beforeend">
{{ content | safe }}
</heading-anchors>
</main>

<footer>
Expand Down Expand Up @@ -158,6 +186,8 @@ activateColorScheme();
{% endjs %}
{% endif %}

<script type="module" src="/js/heading-anchors.js"></script>

{#
getBundleFileUrl Writes the bundle content to a content-hashed file location in your
output directory and returns the URL to the file for use.
Expand Down
2 changes: 2 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default async function(eleventyConfig) {
eleventyConfig.addPassthroughCopy({
"./public/": "/",
"./node_modules/prismjs/themes/prism-okaidia.css": "/css/prism-okaidia.css",
"./node_modules/@daviddarnes/heading-anchors/heading-anchors.js":
"/js/heading-anchors.js",
});

// Run Eleventy when these files change:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eleventeen",
"version": "9.2.20-alpha.17",
"version": "9.2.21-alpha.17",
"description": "Starter repository for a website built with Eleventy + eleventeen",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -45,6 +45,7 @@
"@11ty/eleventy-plugin-bundle": "^2.0.2",
"@11ty/eleventy-plugin-rss": "^2.0.2",
"@11ty/eleventy-plugin-syntaxhighlight": "^5.0.0",
"@daviddarnes/heading-anchors": "^2.0.0",
"@famebot/chromagen": "^1.0.1",
"luxon": "^3.4.4"
}
Expand Down
28 changes: 0 additions & 28 deletions public/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -435,31 +435,3 @@ header {
.post-metadata time {
margin-inline-end: 1em;
}

/* Direct Links / Markdown Headers
.header-anchor {
text-decoration: none;
font-style: normal;
font-size: 1em;
margin-inline-start: 0.1em;
}
a.header-anchor,
a.header-anchor:visited {
color: transparent;
}
a.header-anchor:focus,
a.header-anchor:hover {
text-decoration: underline;
}
a.header-anchor:focus,
:hover > a.header-anchor {
color: var(--text-color-link-highlight);
}
h2 + .header-anchor {
font-size: 1.5em;
}
*/

0 comments on commit 519a08e

Please sign in to comment.