initial commit
This commit is contained in:
57
.eleventy.js
Normal file
57
.eleventy.js
Normal file
@@ -0,0 +1,57 @@
|
||||
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
|
||||
const textOnly = content.replace(/(<([^>]+)>)/gi, '')
|
||||
const readingSpeedPerMin = 450
|
||||
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'
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user