-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_config.ts
139 lines (124 loc) · 4 KB
/
_config.ts
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import lume from "lume/mod.ts";
import jsx from "lume/plugins/jsx.ts";
import mdx from "lume/plugins/mdx.ts";
import sitemap from "lume/plugins/sitemap.ts";
import tailwindcss from "lume/plugins/tailwindcss.ts";
import postcss from "lume/plugins/postcss.ts";
import typographyPlugin from "npm:@tailwindcss/typography";
import prism from "lume/plugins/prism.ts";
import basePath from "lume/plugins/base_path.ts";
function extractHeadings(markdown: string) {
const headingRegex = /^(##|###) (.+)$/gm;
const headings = [];
let match;
while ((match = headingRegex.exec(markdown)) !== null) {
headings.push({
level: match[1] === "##" ? 2 : 3,
text: match[2],
});
}
return headings;
}
function slugify(str: string) {
return str
.toLowerCase() // Convert to lowercase
.trim() // Remove leading and trailing whitespace
.normalize("NFKD") // Normalize the string to decompose combined characters
.replace(/[\u0300-\u036f]/g, "") // Remove diacritical marks
.replace(/[^a-z0-9\s-]/g, "") // Remove non-alphanumeric characters
.replace(/\s+/g, "-") // Replace spaces with hyphens
.replace(/-+/g, "-"); // Remove consecutive hyphens
}
const site = lume({
location: new URL("https://limette.dev/"), // ← Note the path /blog/
});
site.ignore("README.md");
site.use(basePath());
site.use(
sitemap({
filename: "sitemap.xml", // to change the sitemap filename
// query: "indexable=true", // Select only pages with the indexable attribute as true
sort: "date=desc", // To sort by data in ascendent order
})
);
site.use(jsx());
site.use(mdx());
site.use(
tailwindcss({
// Extract the classes from HTML and JSX files
extensions: [".vto", ".html"],
options: {
content: [".vto"],
darkMode: "selector",
theme: {
fontSize: {
xs: ["0.75rem", { lineHeight: "1rem" }],
sm: ["0.875rem", { lineHeight: "1.5rem" }],
base: ["1rem", { lineHeight: "2rem" }],
lg: ["1.125rem", { lineHeight: "1.75rem" }],
xl: ["1.25rem", { lineHeight: "2rem" }],
"2xl": ["1.5rem", { lineHeight: "2.5rem" }],
"3xl": ["2rem", { lineHeight: "2.5rem" }],
"4xl": ["2.5rem", { lineHeight: "3rem" }],
"5xl": ["3rem", { lineHeight: "3.5rem" }],
"6xl": ["3.75rem", { lineHeight: "1" }],
"7xl": ["4.5rem", { lineHeight: "1" }],
"8xl": ["6rem", { lineHeight: "1" }],
"9xl": ["8rem", { lineHeight: "1" }],
},
extend: {
fontFamily: {
sans: "var(--font-inter)",
display: ["var(--font-lexend)", { fontFeatureSettings: '"ss01"' }],
},
maxWidth: {
"8xl": "88rem",
},
},
},
plugins: [typographyPlugin],
},
})
);
site.use(postcss());
// Copy all image files
site.copy([".jpg", ".gif", ".png", ".svg", ".ico", ".woff2", ".js"]);
// Add ids to headings
site.process([".html"], (pages) => {
for (const page of pages) {
if (!page.data.url.startsWith("/docs")) continue;
for (const heading of page.document
.querySelector(".prose")
?.querySelectorAll?.("h2, h3") || []) {
if (!heading.hasAttribute("id")) {
heading.setAttribute("id", slugify(heading.textContent));
}
}
}
});
// Extract content structure
site.preprocess([".html"], (pages) => {
for (const page of pages) {
if (!page.data.url.startsWith("/docs")) continue;
const headings: { title: string; url: string; items: unknown[] }[] = [];
for (const heading of extractHeadings(page.data.content)) {
if (heading.level === 2) {
headings.push({
title: heading.text,
url: "#" + slugify(heading.text),
items: [],
});
}
if (heading.level === 3) {
headings?.[headings.length - 1]?.items?.push({
title: heading.text,
url: "#" + slugify(heading.text),
items: [],
});
}
}
page.__contentStructure = headings;
}
});
site.use(prism());
export default site;