-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
71 lines (61 loc) · 2.27 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
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const markdownIt = require('markdown-it')
const markdownItAnchor = require('markdown-it-anchor')
const { DateTime } = require("luxon")
module.exports = function(eleventyConfig) {
// Plugins
eleventyConfig.addPlugin(syntaxHighlight)
// To enable merging of tags
eleventyConfig.setDataDeepMerge(true)
// Copy these static files to _site folder
eleventyConfig.addPassthroughCopy('src/assets')
eleventyConfig.addPassthroughCopy('src/manifest.json')
// To create excerpts
eleventyConfig.setFrontMatterParsingOptions({
excerpt: true,
excerpt_alias: 'post_excerpt',
excerpt_separator: '<!-- excerpt -->'
})
// To create a filter to determine duration of post
eleventyConfig.addFilter('readTime', (value) => {
const content = value
const textOnly = content.replace(/(<([^>]+)>)/gi, '')
const readingSpeedPerMin = 450
return Math.max(1, Math.floor(textOnly.length / readingSpeedPerMin))
})
// filter to format post date to year-month-day
eleventyConfig.addFilter("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat('yyyy-MM-dd');
})
// Enable us to iterate over all the tags, excluding posts and all
eleventyConfig.addCollection('tagList', collection => {
const tagsSet = new Set()
collection.getAll().forEach(item => {
if (!item.data.tags) return
item.data.tags
.filter(tag => !['posts', 'all'].includes(tag))
.forEach(tag => tagsSet.add(tag))
})
return Array.from(tagsSet).sort()
})
const md = markdownIt({ html: true, linkify: true })
md.use(markdownItAnchor, {
level: [1, 2],
permalink: markdownItAnchor.permalink.headerLink({
safariReaderFix: true,
class: 'header-anchor',
})
})
eleventyConfig.setLibrary('md', md)
// creates a shortcode that allows inserting images with alt-texts. Usage {% asset_img 'imagename','alt-text' %}
// you can pass an optional third argument to give the image a custom path. defaults to /assets/img/posts/
eleventyConfig.addShortcode('asset_img', (filename, alt, path = '/assets/img/posts/') =>
`<img class="my-4" src="${path}${filename}" alt="${alt}" />`
)
return {
dir: {
input: 'src',
output: 'docs'
}
}
}