forked from reveal/revealjs.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.js
90 lines (74 loc) · 2.67 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
const htmlmin = require('html-minifier')
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
module.exports = eleventyConfig => {
// Minify our HTML
eleventyConfig.addTransform('htmlmin', (content, outputPath) => {
if ( outputPath.endsWith('.html') )
{
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
})
return minified
}
return content
})
// Layout aliases
eleventyConfig.addLayoutAlias('default', 'default.njk')
eleventyConfig.addLayoutAlias('home', 'home.njk')
// Include our static assets
eleventyConfig.addPassthroughCopy('images')
eleventyConfig.addPassthroughCopy('demos')
eleventyConfig.addPlugin(syntaxHighlight, {
alwaysWrapLineHighlights: false
});
let md = require('markdown-it')({
html: true,
breaks: true,
linkify: true
});
md.use( require('markdown-it-attrs') );
md.use( require('markdown-it-anchor') );
eleventyConfig.setLibrary('md', md);
// Cut back on terminal noise during development
eleventyConfig.setQuietMode(true);
// Collection of pages that can appear in search results
eleventyConfig.addCollection('searchPages', collection => {
return collection.getFilteredByGlob('src/*.md').sort((a,b) => {
if(a.data.title < b.data.title) return -1;
if(a.data.title > b.date.title) return 1;
return 0;
}).filter( page => {
return !page.data.hidden;
} );
});
// Helper for extracting the searchable content in a page
eleventyConfig.addShortcode('searchContent', page => {
if( !page.hasOwnProperty('templateContent') ) {
console.warn('Failed to extract excerpt: Document has no property "templateContent".');
return null;
}
return JSON.stringify( page.templateContent ).slice( 1,-1 )
.replace( /[\n]\s*[\n]/gm, '\n' )
.replace( /<h1[^>]*.*<\/h1>/gm, '' )
.replace( /<[^>]*>/g, '' )
.replace( /^\\n/g, '' )
.trim();
});
// eleventyConfig.addWatchTarget("js/");
// eleventyConfig.addWatchTarget("css/");
return {
templateFormats: ['md', 'njk'],
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
passthroughFileCopy: true,
dir: {
input: 'src',
output: 'dist',
layouts: '_layouts',
includes: '_includes',
data: '_data'
}
}
}