-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path.eleventy.js
64 lines (55 loc) · 2.21 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
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const pluginRss = require('@11ty/eleventy-plugin-rss')
const timeToRead = require('eleventy-plugin-time-to-read')
const tableOfContents = require('eleventy-plugin-toc')
const dateFilter = require('nunjucks-date-filter')
const octicons = require('@primer/octicons')
const markdownIt = require('markdown-it')
const markdownItAnchor = require('markdown-it-anchor')
const markdownItFootnote = require('markdown-it-footnote')
const markdownItEmoji = require('markdown-it-emoji')
const slugify = require('slugify')
const compileReadme = require('./bin/compile-readme')
const generateImages = require('./bin/generate-images')
module.exports = (eleventyConfig) => {
dateFilter.setDefaultFormat('MMMM D, YYYY')
eleventyConfig.addPlugin(pluginRss)
eleventyConfig.addPlugin(tableOfContents, { tags: ['h2'] })
eleventyConfig.addPlugin(syntaxHighlight)
eleventyConfig.addPlugin(timeToRead)
eleventyConfig.addNunjucksFilter('date', dateFilter)
eleventyConfig.addPassthroughCopy('assets')
eleventyConfig.addShortcode('octicon', (name) => {
const octicon = octicons[name]
if (!octicon) throw new Error(`Octicon [${name}] does not exist`)
return octicon.toSVG()
})
const linkAfterHeader = markdownItAnchor.permalink.linkAfterHeader({
class: "anchor",
symbol: "<span hidden>#</span>",
style: "aria-labelledby",
})
const markdown = markdownIt({ html: true })
.use(markdownItFootnote)
.use(markdownItEmoji)
.use(markdownItAnchor, {
level: [1, 2, 3],
slugify: (str) => slugify(str, { lower: true, strict: true, remove: /[']/g, }),
tabIndex: false,
permalink(slug, opts, state, idx) {
state.tokens.splice(idx, 0, Object.assign(new state.Token('div_open', 'div', 1), {
attrs: [['class', `heading-wrapper ${state.tokens[idx].tag}`]],
block: true,
}))
state.tokens.splice(idx + 4, 0, Object.assign(new state.Token('div_close', 'div', -1), {
block: true,
}))
linkAfterHeader(slug, opts, state, idx + 1)
},
})
eleventyConfig.setLibrary('md', markdown)
eleventyConfig.on('afterBuild', () => {
compileReadme()
generateImages()
})
}