generated from juanfrank77/foam-eleventy-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
53 lines (49 loc) · 1.49 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
module.exports = (eleventyConfig) => {
eleventyConfig.addPassthroughCopy(".htaccess");
eleventyConfig.addTransform("wiki-links", function (content, outputPath) {
if (outputPath && outputPath.endsWith(".html")) {
// We remove outer brackets from links
let output = content.replace(/(\[+(\<a(.*?)\<\/a\>)\]+)/g, "$2");
return output;
}
return content;
});
let markdownIt = require("markdown-it");
let markdownItReplaceLink = require("markdown-it-replace-link");
let markdownItOptions = {
html: true,
replaceLink: function (link, env) {
const isRelativePattern = /^(?!http|\/).*/;
const lastSegmentPattern = /[^\/]+(?=\/$|$)/i;
const isRelative = isRelativePattern.test(link);
if (isRelative) {
const hasLastSegment = lastSegmentPattern.exec(env.page.url);
// If it's nested, replace the last segment
if (hasLastSegment && env.page.url) {
return env.page.url.replace(lastSegmentPattern, link);
}
// If it's at root, just add the beginning slash
return env.page.url + link;
}
return link;
},
};
let markdownLib = markdownIt(markdownItOptions).use(markdownItReplaceLink);
eleventyConfig.setLibrary("md", markdownLib);
return {
dir: {
input: ".",
output: "_site",
includes: "_includes",
layouts: "_layouts",
},
templateFormats: [
//
"js",
"md",
"html",
"liquid",
],
passthroughFileCopy: true,
};
};