11// eleventy.config.js
22const { DateTime } = require ( "luxon" ) ; // Import Luxon library for dates
33const syntaxHighlight = require ( "@11ty/eleventy-plugin-syntaxhighlight" ) ;
4+ const pluginTOC = require ( 'eleventy-plugin-toc' ) ;
5+ const markdownIt = require ( 'markdown-it' ) ;
6+ const markdownItAnchor = require ( 'markdown-it-anchor' ) ;
47
58module . exports = function ( eleventyConfig ) {
69
710 eleventyConfig . addPlugin ( syntaxHighlight ) ;
11+
12+ // --- TOC & Anchor Plugin Configuration ---
13+ eleventyConfig . setLibrary (
14+ 'md' ,
15+ markdownIt ( {
16+ html : true ,
17+ linkify : true ,
18+ typographer : true ,
19+ } ) . use ( markdownItAnchor , {
20+ slugify : s => s . trim ( ) . toLowerCase ( ) . replace ( / [ \s + , . ' ] / g, '-' ) . replace ( / [ ( ) ] / g, '' ) , // Ensure consistent slugification
21+ permalink : markdownItAnchor . permalink . ariaHidden ( {
22+ placement : 'before' , // Or 'after'
23+ class : 'heading-anchor-link' , // Optional: A class for styling the anchor link
24+ symbol : '#' , // Optional: The symbol for the anchor link
25+ level : [ 2 , 3 , 4 ] // Optional: Only add permalinks to h2, h3, h4
26+ } )
27+ } )
28+ ) ;
29+
30+ eleventyConfig . addPlugin ( pluginTOC , {
31+ tags : [ 'h2' , 'h3' ] , // Which heading tags to include in the TOC, h4 can be added if needed
32+ wrapper : 'nav' , // What element to wrap the TOC in, e.g., 'nav'
33+ wrapperClass : 'toc' , // Class for the wrapper element
34+ ul : true , // Whether to use an unordered list (ul) or ordered list (ol)
35+ flat : false // Whether to generate a flat list or nested list
36+ } ) ;
37+
38+
839 // --- Passthrough Copy ---
940 // (Keep your existing passthrough copy lines)
1041 eleventyConfig . addPassthroughCopy ( "src/css" ) ;
@@ -52,4 +83,4 @@ module.exports = function(eleventyConfig) {
5283 markdownTemplateEngine : "njk" ,
5384 htmlTemplateEngine : "njk"
5485 } ;
55- } ;
86+ } ;
0 commit comments