2021-04-07 12:21:17 -04:00
|
|
|
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
|
|
|
|
const markdownIt = require('markdown-it')
|
|
|
|
const markdownItAnchor = require('markdown-it-anchor')
|
|
|
|
|
|
|
|
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
|
2021-04-14 15:23:11 -04:00
|
|
|
const textOnly = content.split(" ")//content.replace(/(<([^>]+)>)/gi, '')
|
|
|
|
const readingSpeedPerMin = 300
|
2021-04-07 12:21:17 -04:00
|
|
|
return Math.max(1, Math.floor(textOnly.length / readingSpeedPerMin))
|
|
|
|
})
|
|
|
|
|
|
|
|
// 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({ linkify: true, html: true })
|
|
|
|
md.use(markdownItAnchor, { level: [1, 2], permalink: true, permalinkBefore: false, permalinkSymbol: '#' })
|
|
|
|
eleventyConfig.setLibrary('md', md)
|
|
|
|
|
|
|
|
// asset_img shortcode
|
|
|
|
eleventyConfig.addLiquidShortcode('asset_img', (filename, alt) => {
|
|
|
|
return `<img class="my-4" src="/assets/img/posts/${filename}" alt="${alt}" />`
|
|
|
|
})
|
|
|
|
|
|
|
|
return {
|
|
|
|
dir: {
|
|
|
|
input: 'src'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|