77 lines
2.0 KiB
JavaScript
77 lines
2.0 KiB
JavaScript
import pluginWebc from '@11ty/eleventy-plugin-webc'
|
|
import mdit from 'markdown-it'
|
|
import fs from 'fs/promises'
|
|
|
|
const MD_REGEX = /\.[^/.]{1,4}$/i
|
|
|
|
export default function (config) {
|
|
// markdown parser
|
|
const markdownLib = mdit({
|
|
html: true,
|
|
breaks: false,
|
|
linkify: true,
|
|
}).disable('code')
|
|
|
|
config.setLibrary('md', markdownLib)
|
|
|
|
// webc templates
|
|
config.addPlugin(pluginWebc, {
|
|
components: 'src/layouts/components/*.webc',
|
|
})
|
|
|
|
config.addPassthroughCopy({
|
|
'src/assets': '/',
|
|
'./node_modules/view-transitions-polyfill/dist/view-transitions-polyfill.js': '/scripts/vtpolyfill.js',
|
|
// 'src/admin': 'admin',
|
|
})
|
|
|
|
// add collection for pages
|
|
config.addCollection('categories', async (collection) => {
|
|
const categoryNames = (await fs.readdir('src/content/')).filter((c) => !c.match(MD_REGEX))
|
|
|
|
let categories = new Map()
|
|
|
|
for (const catName of categoryNames) {
|
|
categories = collection.getFilteredByGlob(`src/content/${catName}/index.md`).reduce((accumulator, category) => {
|
|
accumulator.set(category, [])
|
|
return accumulator
|
|
}, categories)
|
|
|
|
categories = collection.getFilteredByGlob(`src/content/${catName}/*.md`).reduce((accumulator, category) => {
|
|
const categoryIsKey = accumulator.keys().find(key => category === key)
|
|
if (!categoryIsKey) {
|
|
const categoryKey = accumulator.keys().find(key => category.data.tags.includes(key.data.tags[0]))
|
|
const catAccum = accumulator.get(categoryKey)
|
|
catAccum.push(category)
|
|
}
|
|
|
|
return accumulator
|
|
}, categories)
|
|
}
|
|
|
|
return map2arr(categories)
|
|
})
|
|
|
|
config.addCollection('pages', (collection) => {
|
|
return collection.getFilteredByGlob('src/content/*.md').filter(p => p.page.fileSlug)
|
|
})
|
|
|
|
return {
|
|
markdownTemplateEngine: 'md',
|
|
dir: {
|
|
input: 'src/content',
|
|
includes: '../layouts',
|
|
data: '../data',
|
|
output: 'dist',
|
|
},
|
|
}
|
|
}
|
|
|
|
const map2arr = (myMap) => {
|
|
const arr = []
|
|
myMap.forEach((value, key) => {
|
|
arr.push([key, value])
|
|
})
|
|
return arr
|
|
}
|