Files
git.taskfile.build/eleventy.config.js
T
Janik von Rotz 75843337a8 docs(website): add table of contents and improve layout structure
- Implement dynamic table of contents generation in base layout
- Add project structure documentation to AGENTS.md
- Refactor CSS for responsive sidebar and content layout
- Integrate eleventy-plugin-toc for automated TOC creation
- Fix function name typo in library.md
- Update package.json to support ES modules
- Enhance mobile navigation spacing and desktop layout flexibility
2025-11-10 15:09:13 +01:00

62 lines
1.9 KiB
JavaScript

import syntaxHighlight from '@11ty/eleventy-plugin-syntaxhighlight'
import eleventyNavigationPlugin from '@11ty/eleventy-navigation'
import markdownIt from 'markdown-it'
import markdownItAnchor from 'markdown-it-anchor'
import slugify from 'slugify'
import pluginToc from 'eleventy-plugin-toc'
const generatePermalink = (slug, opts, state, idx) => {
let contentTokenIdx = null
for (let i = idx + 1; i < state.tokens.length; i++) {
if (state.tokens[i].type === 'inline') {
contentTokenIdx = i
break
}
}
if (contentTokenIdx) {
const anchorHTML = `<a class="anchor" href="#${slug}" aria-labelledby="${slug}"><span>#</span></a> `
const contentToken = state.tokens[contentTokenIdx]
if (contentToken.children && contentToken.children.length > 0) {
const textToken = new state.Token('html_inline', '', 0)
textToken.content = anchorHTML
contentToken.children.unshift(textToken)
}
}
state.tokens[idx].attrs = state.tokens[idx].attrs || []
state.tokens[idx].attrs.push(['id', slug])
}
const markdownItAnchorOptions = {
level: [1, 2, 3],
slugify: (str) =>
slugify(str, {
lower: true,
strict: true,
remove: /["]/g,
}),
tabIndex: false,
permalink: generatePermalink,
}
const markdownLibrary = markdownIt({ html: true }).use(
markdownItAnchor,
markdownItAnchorOptions
)
export default async function (eleventyConfig) {
const { IdAttributePlugin } = await import('@11ty/eleventy')
eleventyConfig.setLibrary('md', markdownLibrary)
eleventyConfig.addPlugin(IdAttributePlugin)
eleventyConfig.addPlugin(syntaxHighlight)
eleventyConfig.addPlugin(eleventyNavigationPlugin)
eleventyConfig.addPlugin(pluginToc)
eleventyConfig.addPassthroughCopy('img')
eleventyConfig.addPassthroughCopy('css')
eleventyConfig.addPassthroughCopy('js')
}