generated from grislyeye/vellum-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
53 lines (45 loc) · 1.55 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
const project = require('./package.json');
const replaceLink = require('markdown-it-replace-link');
const path = require("path");
// const linkPreviewPlugin = require("./lib/link-preview-md-plugin.js");
function byIndex(left, right) {
const a = left.data.index ? Number.parseInt(left.data.index) : 0;
const b = right.data.index ? Number.parseInt(right.data.index) : 0;
return a - b;
}
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("assets");
eleventyConfig.addCollection("index", function (collectionApi) {
return collectionApi
.getFilteredByTag("pages")
.sort(byIndex);
});
eleventyConfig.addPassthroughCopy(
{
'node_modules/@lit': 'vendor/@lit',
'node_modules/vellum-doc': 'vendor/vellum-doc',
'node_modules/link-preview': 'vendor/link-preview',
'node_modules/magick.css': 'vendor/magick.css',
'node_modules/normalize.css': 'vendor/normalize.css'
}
);
eleventyConfig.addGlobalData("project", project);
eleventyConfig.amendLibrary("md", (mdLib) => {
mdLib
.use(replaceLink, {
replaceLink: function (link) {
const isUrl = URL.canParse(link);
const file = path.parse(link);
if (!isUrl && file.ext === '.md') {
const anchor = file.name;
return `#${anchor}`;
} else if (!isUrl && file.ext.startsWith('.md#')) {
const anchor = file.ext.split('#').pop();
return `#${anchor}`;
}
return link;
}
})
// .use(linkPreviewPlugin);
});
};