88 lines
2.1 KiB
JavaScript
88 lines
2.1 KiB
JavaScript
const pluginWebc = require('@11ty/eleventy-plugin-webc')
|
|
const markdownIt = require('markdown-it')
|
|
const mdla = require('markdown-it-link-attributes')
|
|
const fs = require('fs')
|
|
|
|
module.exports = (config) => {
|
|
// webc
|
|
config.addPlugin(pluginWebc, {
|
|
components: '_includes/components/**/*.webc'
|
|
})
|
|
|
|
// markdown setup
|
|
const mdOptions = {
|
|
html: true,
|
|
linkify: true,
|
|
}
|
|
|
|
const markdownLib = markdownIt(mdOptions)
|
|
.use(mdla, {
|
|
matcher(href, _c) {
|
|
return href.match(/\/@\w+/)
|
|
},
|
|
attrs: {
|
|
rel: 'me',
|
|
target: '_blank',
|
|
},
|
|
})
|
|
|
|
config.setLibrary('md', markdownLib)
|
|
|
|
// add collection for pages
|
|
config.addCollection('categories', (collection) => {
|
|
// let categories = collection.getFilteredByGlob('**')
|
|
let categories = fs.readdirSync('_content')
|
|
categories = categories.filter(c => !c.match(/\.[^/.]{1,4}$/i))
|
|
|
|
let _cat = {}
|
|
|
|
categories.forEach(cat => {
|
|
let sorted = []
|
|
let unsorted = []
|
|
|
|
let pages = collection.getFilteredByGlob(`_content/${cat}/*.md`)
|
|
|
|
for (let page of pages) {
|
|
if (page.data.sort) {
|
|
if (sorted[page.data.sort]) {
|
|
sorted.splice(page.data.sort, 0, page)
|
|
} else {
|
|
sorted[page.data.sort] = page
|
|
}
|
|
} else {
|
|
unsorted.push(page)
|
|
}
|
|
}
|
|
sorted = sorted.filter(p => p.data.published)
|
|
|
|
_cat[cat] = sorted.concat(unsorted)
|
|
})
|
|
|
|
return _cat
|
|
})
|
|
|
|
// custom filters
|
|
config.addFilter('makeLowercase', (value) => {
|
|
if (typeof value === 'string' || value instanceof String) {
|
|
return value.toLowerCase()
|
|
}
|
|
})
|
|
|
|
// added passthrough for global assets
|
|
config.addPassthroughCopy('assets')
|
|
|
|
// added passthrough for images in their respective folders
|
|
config.addPassthroughCopy('_content/**/images/**')
|
|
|
|
// reutrn updated config
|
|
return {
|
|
htmlTemplateEngine: 'webc',
|
|
dir: {
|
|
input: '_content', // content
|
|
includes: '../_includes', // templates
|
|
output: '_site', // rendered site
|
|
data: '../_data', // global data files
|
|
},
|
|
}
|
|
}
|