1- /* eslint-disable @typescript-eslint/no-unsafe-call */
2-
31import eleventyNavigationPlugin from '@11ty/eleventy-navigation'
42import eleventyRemark from '@fec/eleventy-plugin-remark'
5- import dedent from 'dedent'
63import { rehype } from 'rehype'
74import rehypeAutolinkHeadings from 'rehype-autolink-headings'
85import rehypeSlug from 'rehype-slug'
9- import { remark } from 'remark'
106import remarkDirective from 'remark-directive'
117
128import { remarkDirectives } from './remark/directives.js'
139import { remarkHeadings } from './remark/headings.js'
1410import { remarkSample } from './remark/sample.js'
11+ import { rehypeTableOfContents } from './remark/table-of-contents.js'
1512
16- /** @param {import('@11ty/eleventy').UserConfig } eleventyConfig */
13+ /** @param {import('@11ty/eleventy/UserConfig ').default } eleventyConfig */
1714export default async function config ( eleventyConfig ) {
1815 eleventyConfig . addPassthroughCopy ( {
1916 'src/assets/fonts' : './assets/fonts' ,
@@ -23,32 +20,6 @@ export default async function config(eleventyConfig) {
2320 } )
2421 eleventyConfig . addPassthroughCopy ( { 'src/public' : '.' } )
2522
26- eleventyConfig . addPairedShortcode (
27- 'navitem' ,
28- ( content , url , isSelected , isInactive ) => {
29- let tag = ''
30-
31- if ( isInactive ) {
32- tag = `<span class="px-3 py-2 relative block text-grey-400">${ content } </span>`
33- } else {
34- let linkClass = [
35- 'px-3 py-2 transition-colors duration-200 relative block' ,
36- isSelected && 'text-sky-700' ,
37- ! isSelected && 'hover:text-grey-900 text-grey-500' ,
38- ] . join ( ' ' )
39-
40- tag = dedent `<a class="${ linkClass } " href="${ url } ">
41- <span class="rounded-md absolute inset-0 bg-sky-50 ${
42- ! isSelected && 'opacity-0'
43- } "></span>
44- <span class="relative">${ content } </span>
45- </a>`
46- }
47-
48- return `<li>${ tag } </li>`
49- } ,
50- )
51-
5223 eleventyConfig . addPlugin ( eleventyNavigationPlugin )
5324 eleventyConfig . addPlugin ( eleventyRemark , {
5425 plugins : [
@@ -62,14 +33,25 @@ export default async function config(eleventyConfig) {
6233
6334 eleventyConfig . addTransform (
6435 'rehype' ,
65- /** @param {string } content */ async ( content , outputPath ) => {
36+ /**
37+ * @param {string } content
38+ * @param {string } outputPath
39+ */
40+ async ( content , outputPath ) => {
6641 let newContent = content
6742
6843 if ( outputPath ?. endsWith ( '.html' ) ) {
6944 let result = await rehype ( )
7045 . use ( rehypeSlug )
7146 . use ( rehypeAutolinkHeadings , {
72- test : ( element , index , parent ) => parent . tagName !== 'nav' ,
47+ test ( element , index , parent ) {
48+ return (
49+ parent ?. type === 'element' &&
50+ parent ?. tagName !== 'nav' &&
51+ element . tagName !== 'h1' &&
52+ element . tagName !== 'h5'
53+ )
54+ } ,
7355 properties : {
7456 class :
7557 'absolute ml-[-0.75em] md:ml-[-1em] pr-[0.5em] !no-underline !text-grey-400 opacity-0 group-hover:opacity-100' ,
@@ -88,6 +70,18 @@ export default async function config(eleventyConfig) {
8870 } ,
8971 )
9072
73+ eleventyConfig . addAsyncFilter (
74+ 'toc' ,
75+ /** @param {string } content */ async ( content ) => {
76+ let output = await rehype ( )
77+ . data ( 'settings' , { fragment : true } )
78+ . use ( rehypeSlug )
79+ . use ( rehypeTableOfContents )
80+ . process ( content )
81+ return output . toString ( )
82+ } ,
83+ )
84+
9185 return {
9286 dir : {
9387 input : 'src' ,
0 commit comments