-
Notifications
You must be signed in to change notification settings - Fork 3
/
.eleventy.js
116 lines (101 loc) · 3.52 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
const Prism = require('prismjs');
const loadLanguages = require('prismjs/components/');
const siteConfig = require('./config/blog.js');
const markdownItReplaceLink = require('markdown-it-replace-link');
const emoji = require('markdown-it-emoji');
loadLanguages(['apex', 'css', 'html', 'js', 'xml', 'javascript']);
const markdownIt = require('markdown-it')({
html: true,
breaks: true,
linkify: true,
xhtmlOut: true,
typographer: true,
highlight: function (str, lang) {
if (lang && Prism.languages[lang]) {
return (
'<pre class="language-' +
lang +
'"><code>' +
Prism.highlight(str, Prism.languages[lang], lang) +
'</code></pre>'
);
}
return (
'<pre class="language-none"><code>' +
markdownIt.utils.escapeHtml(str) +
'</code></pre>'
);
},
replaceLink: function (link, env) {
if (link.startsWith('/')) {
return link.replace('/', siteConfig.publicPath);
}
return link;
}
})
.use(markdownItReplaceLink)
.use(emoji);
markdownIt.renderer.rules.table_open = function (tokens, idx) {
return '<table class="table-auto w-full border-2 my-4">';
};
markdownIt.renderer.rules.th_open = function (tokens, idx) {
return '<th class="border p-1.5">';
};
markdownIt.renderer.rules.td_open = function (tokens, idx) {
return '<td class="border p-1.5">';
};
markdownIt.renderer.rules.ordered_list_open = function (tokens, idx) {
return '<ol class="list-decimal list-outside pl-8">';
};
markdownIt.renderer.rules.bullet_list_open = function (tokens, idx) {
return '<ul class="list-disc list-outside pl-8">';
};
markdownIt.renderer.rules.paragraph_open = function (tokens, idx) {
return '<p class="mb-3">';
};
let defaultLinkRender =
markdownIt.renderer.rules.link_open ||
function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};
markdownIt.renderer.rules.link_open = function (
tokens,
idx,
options,
env,
self
) {
let aIndex = tokens[idx].attrIndex('class');
let classNames = 'text-blue-600 dark:text-blue-400 hover:underline';
if (aIndex < 0) {
tokens[idx].attrPush(['class', classNames]); // add new attribute
} else {
tokens[idx].attrs[aIndex][1] = classNames; // replace value of existing attr
}
return defaultLinkRender(tokens, idx, options, env, self);
};
module.exports = function (eleventyConfig) {
eleventyConfig.setLibrary('md', markdownIt);
eleventyConfig.setTemplateFormats(['md', 'njk']);
eleventyConfig.addLayoutAlias('post', 'layout-post.njk');
eleventyConfig.addPassthroughCopy('build/resources');
eleventyConfig.addPassthroughCopy('build/admin');
eleventyConfig.addPassthroughCopy('build/**/*.js');
eleventyConfig.addPassthroughCopy('build/**/*.html');
eleventyConfig.addCollection('posts', function (collectionApi) {
return collectionApi.getFilteredByGlob('build/posts/**/*.md');
});
// Plugin for setting _blank and rel=noopener on external links in markdown content
eleventyConfig.addPlugin(require('./_11ty/external-links.js'));
// Plugin for minifying HTML
eleventyConfig.addPlugin(require('./_11ty/html-minify.js'));
return {
dir: {
input: 'build',
includes: '_includes',
output: 'public',
data: '../config'
},
pathPrefix: siteConfig.publicPath
};
};