-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eleventy.js
122 lines (103 loc) · 4.3 KB
/
.eleventy.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const embedYouTube = require("eleventy-plugin-youtube-embed");
const fs = require("fs");
const pluginTOC = require('eleventy-plugin-toc')
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("src/assets");
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(embedYouTube);
// Generates a Table of Content using an Eleventy filter
eleventyConfig.addPlugin(pluginTOC, {
tags: ['h2', 'h3'],
});
// Provides syntax highlighting
eleventyConfig.addPlugin(syntaxHighlight, {
templateFormats: ["md"],
alwaysWrapLineHighlights: false,
});
eleventyConfig.addWatchTarget("./src/assets/");
eleventyConfig.setBrowserSyncConfig({
ui: false,
callbacks: {
ready: function (err, bs) {
bs.addMiddleware("*", (req, res) => {
const content_404 = fs.readFileSync("dist/404.html");
// Provides the 404 content without redirect.
res.write(content_404);
// Add 404 http status code in request header.
// res.writeHead(404, { "Content-Type": "text/html" });
res.writeHead(404);
res.end();
});
},
},
});
eleventyConfig.setUseGitIgnore(false);
// Populates all headings with an id attribute
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const markdownLib = markdownIt({ html: true }).use(markdownItAnchor);
eleventyConfig.setLibrary("md", markdownLib);
eleventyConfig.addCollection("androidv2", function (collectionApi) {
return collectionApi.getFilteredByTags("android", "v2");
});
eleventyConfig.addCollection("androidv3", function (collectionApi) {
return collectionApi.getFilteredByTags("android", "v3");
});
eleventyConfig.addCollection("iosv2", function (collectionApi) {
return collectionApi.getFilteredByTags("ios", "v2");
});
eleventyConfig.addCollection("iosv3", function (collectionApi) {
return collectionApi.getFilteredByTags("ios", "v3");
});
eleventyConfig.addCollection("webv3", function (collectionApi) {
return collectionApi.getFilteredByTags("web", "v3");
});
eleventyConfig.addCollection("changelogs", function (collectionApi) {
return collectionApi.getFilteredByTags("changelogs");
});
eleventyConfig.addCollection("directions", function (collectionApi) {
return collectionApi.getFilteredByTags("directions");
});
eleventyConfig.addCollection("map", function (collectionApi) {
return collectionApi.getFilteredByTags("map");
});
eleventyConfig.addCollection("data", function (collectionApi) {
return collectionApi.getFilteredByTags("data");
});
eleventyConfig.addCollection("searching", function (collectionApi) {
return collectionApi.getFilteredByTags("searching");
});
eleventyConfig.addCollection("cms", function (collectionApi) {
return collectionApi.getFilteredByTags("cms");
});
eleventyConfig.addCollection("legacy", function (collectionApi) {
return collectionApi.getFilteredByTags("legacy");
});
eleventyConfig.addCollection("legacy-android-v3", function (collectionApi) {
return collectionApi.getFilteredByTags("legacy-android-v3");
});
eleventyConfig.addCollection("docs", function (collectionApi) {
return collectionApi.getFilteredByTags("docs");
});
eleventyConfig.addCollection("getting-started", function (collectionApi) {
return collectionApi.getFilteredByTags("getting-started");
});
eleventyConfig.addCollection("published", function (collectionApi) {
return [...collectionApi.getFilteredByGlob("./src/**/*.md")].filter(
(post) => !post.data.draft
);
});
return {
dir: {
input: `src`,
output: `dist`,
includes: `_includes`,
data: `_data`,
},
templateFormats: ["njk", "md"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
};
};