Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Use better heading anchor link plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rg-wood committed Jul 6, 2024
1 parent 71f8d62 commit 41b68e6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 117 deletions.
26 changes: 8 additions & 18 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const project = require('./package.json');
const replaceLink = require('markdown-it-replace-link');
const path = require("path")
const markdownItAnchor = require('markdown-it-anchor');

function byIndex(left, right) {
const a = left.data.index ? Number.parseInt(left.data.index) : 0;
Expand All @@ -26,20 +25,11 @@ module.exports = function (eleventyConfig) {

eleventyConfig.addGlobalData("project", project);

eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(replaceLink, {
replaceLink: function (link) {
const isUrl = URL.canParse(link);
const file = path.parse(link);

if (!isUrl && file.ext === '.md') {
const anchor = file.name;
return `#${anchor}`;
} else if (!isUrl && file.ext.startsWith('.md#')) {
const anchor = file.ext.split('#').pop();
return `#${anchor}`;
}

return link;
}
}));
eleventyConfig.amendLibrary('md', (mdLib) => {
mdLib.use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.headerLink(),
level: [1, 2, 3, 4],
slugify: eleventyConfig.getFilter('slugify')
});
});
};
9 changes: 9 additions & 0 deletions assets/styles/_links.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
font-style: normal;
}

.content h1 a,
.content h2 a,
.content h3 a,
.content h4 a {
text-decoration: none;
background-image: none;
background-color: transparent;
}

.content a:hover {
background-color: #4b4b4b;
}
Expand Down
112 changes: 15 additions & 97 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.5.2",
"markdown-it-replace-link": "^1.2.1",
"vellum-doc": "^0.6.0"
"markdown-it-anchor": "^9.0.1",
"vellum-doc": "^0.7.0"
},
"devDependencies": {
"@11ty/eleventy": "^2.0.1",
Expand Down

0 comments on commit 41b68e6

Please sign in to comment.