-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheleventy.config.js
99 lines (88 loc) · 3.45 KB
/
eleventy.config.js
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
import fs from 'fs';
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import markdownit from "markdown-it";
import anchor from "markdown-it-anchor";
import tocPlugin from "eleventy-plugin-toc";
const VERSION = '0.4.0';
export default function (eleventyConfig) {
// Get utility sections
// Those can be retrieved from the single _utilities.css file.
// Every section is a single line CSS comment
const slothUtilitySections = [];
fs.readFileSync('src/_utilities.css').toString().split("\n").filter((l) => l.startsWith('/*')).forEach((section) => {
slothUtilitySections.push(section.trim().slice(2, -2).trim().toLowerCase());
});
// Get components
// Those can be retrieved by all files existing in the components/ directory
const slothComponents = [];
fs.readdirSync('src/components').forEach(file => {
const slug = file.slice(1, -4);
slothComponents.push({
slug: slug,
js: ['tab', 'toast'].includes(slug),
});
});
// Init plugins
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.setLibrary("md", markdownit().set({ html: true }).use(anchor));
eleventyConfig.addPlugin(tocPlugin, {
tags: ["h2", "h3"],
ul: true,
});
// Build search index
const index = [];
const docsSrc = 'docs/pages/';
const dirs = fs.readdirSync(docsSrc, { withFileTypes: true }).filter((e) => e.isDirectory()).map((d) => d.name);
dirs.forEach((d) => {
fs.readdirSync(`${docsSrc}${d}`).forEach(file => {
const name = file.slice(0, -3);
const meta = fs.readFileSync(`${docsSrc}${d}/${file}`).toString().split("\n", 5);
const title = meta.filter((l) => l.startsWith('title:')).join().slice(6).trim();
const text = meta.filter((l) => l.startsWith('description:')).join().slice(12).trim();
const tags = meta.filter((l) => l.startsWith('tags:')).join().slice(5).trim();
index.push({
title: title,
name: name,
url: `/${d}/${name}`,
text: text,
tags: tags,
cat: d
});
});
});
// Sort entries alphabetically by title
index.sort((a, b) => a.title.localeCompare(b.title));
// Write search index to file
fs.mkdirSync('docs/public/assets/scripts', { recursive: true })
fs.writeFileSync('docs/public/assets/scripts/searchIndex.json', JSON.stringify(index));
// Global data
eleventyConfig.addGlobalData('baseUrl', 'https://slothcss.devmount.com');
eleventyConfig.addGlobalData('repoUrl', 'https://github.com/devmount/sloth.css');
eleventyConfig.addGlobalData('cdnUrl', 'https://unpkg.com/@devmount/sloth.css@^0');
eleventyConfig.addGlobalData('creatorUrl', 'https://devmount.com');
eleventyConfig.addGlobalData('donationUrl', 'https://paypal.me/devmount');
eleventyConfig.addGlobalData('layout', 'default');
eleventyConfig.addGlobalData('meta', {
title: 'Sloth.css',
version: VERSION,
description: 'A drop-in utility component CSS library for lazy mammals.',
utilitySections: slothUtilitySections,
components: slothComponents,
});
// Layout aliases
eleventyConfig.addLayoutAlias('default', 'default.njk');
// Get sloth.css
eleventyConfig.addPassthroughCopy({ 'docs/assets': 'assets'});
eleventyConfig.addPassthroughCopy({ src: 'assets/styles' });
// 11ty config
return {
dir: {
input: "docs/pages",
output: "docs/public",
includes: "../_includes",
},
// Nunjucks instead of Liquid for markdown
markdownTemplateEngine: 'njk',
templateEngineOverride: ['njk'],
}
};