-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path.eleventy.js
More file actions
95 lines (83 loc) · 2.95 KB
/
.eleventy.js
File metadata and controls
95 lines (83 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import fs from "node:fs";
import eleventyLucideicons from "@grimlink/eleventy-plugin-lucide-icons";
import eleventySyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
import pluginTOC from "eleventy-plugin-toc";
import * as lucideIcons from "lucide-static";
import { registerLlmExports } from "./src/eleventy/llm-exports.js";
import { registerNavigationFilters } from "./src/eleventy/navigation.js";
const readSiteData = () => {
try {
const raw = fs.readFileSync(
new URL("./_data/site.json", import.meta.url),
"utf8",
);
return JSON.parse(raw) || null;
} catch {
return null;
}
};
export default function eleventyConfigFile(eleventyConfig) {
eleventyConfig.addPassthroughCopy("assets");
eleventyConfig.addPassthroughCopy("media");
// Plugins
eleventyConfig.addPlugin(eleventyLucideicons);
eleventyConfig.addPlugin(eleventySyntaxHighlight);
eleventyConfig.addPlugin(pluginTOC);
// Global data (for absolute URLs in meta tags + llm exports).
const site = readSiteData();
const siteTitle = site?.title || "Pages CMS";
const isServe = process.argv.includes("--serve");
const siteUrl = process.env.SITE_URL || (isServe ? "" : site?.url || "");
eleventyConfig.addGlobalData("siteUrl", siteUrl);
// Markdown
const markdown = markdownIt({ html: true, breaks: true, linkify: true }).use(
markdownItAnchor,
{
permalink: markdownItAnchor.permalink.headerLink(),
},
);
const defaultTableOpen = markdown.renderer.rules.table_open;
const defaultTableClose = markdown.renderer.rules.table_close;
markdown.renderer.rules.table_open = (tokens, idx, mdOptions, env, self) => {
return (
'<div class="relative w-full overflow-auto my-6"><table>' +
(defaultTableOpen
? defaultTableOpen(tokens, idx, mdOptions, env, self)
: "")
);
};
markdown.renderer.rules.table_close = (tokens, idx, mdOptions, env, self) => {
return (
(defaultTableClose
? defaultTableClose(tokens, idx, mdOptions, env, self)
: "") + "</table></div>"
);
};
eleventyConfig.setLibrary("md", markdown);
eleventyConfig.addFilter("markdown", function markdownFilter(value) {
return markdown.render(String(value || ""));
});
eleventyConfig.addFilter("markdownUrl", function markdownUrl(pageUrl) {
if (pageUrl === "/") return "/index.md";
if (pageUrl === "/docs/" || pageUrl === "/docs") return "/docs/index.md";
return pageUrl.replace(/\/$/, "") + ".md";
});
registerNavigationFilters(eleventyConfig, lucideIcons);
registerLlmExports(eleventyConfig, {
getSiteUrl: () => siteUrl,
getSiteTitle: () => siteTitle,
getSiteDescription: () => site?.description || "",
});
return {
dir: {
input: ".",
output: "_site",
includes: "_includes",
layouts: "_includes/layouts",
data: "_data",
},
markdownTemplateEngine: "njk",
};
}