2023-10-28 19:15:28 +00:00
|
|
|
// node requires
|
|
|
|
const fs = require('fs')
|
|
|
|
|
|
|
|
// webc plugin
|
2023-10-26 18:12:52 +00:00
|
|
|
const pluginWebc = require('@11ty/eleventy-plugin-webc')
|
2023-10-28 19:15:28 +00:00
|
|
|
|
|
|
|
// markdown plugin
|
2022-12-23 12:03:56 +00:00
|
|
|
const markdownIt = require('markdown-it')
|
|
|
|
const mdla = require('markdown-it-link-attributes')
|
|
|
|
|
2023-10-28 19:15:28 +00:00
|
|
|
// ~> config start
|
2019-12-02 15:46:19 +00:00
|
|
|
module.exports = (config) => {
|
2023-10-26 18:12:52 +00:00
|
|
|
// webc
|
|
|
|
config.addPlugin(pluginWebc, {
|
|
|
|
components: '_includes/components/**/*.webc'
|
|
|
|
})
|
|
|
|
|
2022-12-23 12:03:56 +00:00
|
|
|
// markdown setup
|
|
|
|
const mdOptions = {
|
|
|
|
html: true,
|
|
|
|
linkify: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
const markdownLib = markdownIt(mdOptions)
|
|
|
|
.use(mdla, {
|
2022-12-24 20:18:44 +00:00
|
|
|
matcher(href, _c) {
|
2022-12-23 12:03:56 +00:00
|
|
|
return href.match(/\/@\w+/)
|
|
|
|
},
|
|
|
|
attrs: {
|
|
|
|
rel: 'me',
|
2023-01-10 17:07:18 +00:00
|
|
|
target: '_blank',
|
|
|
|
},
|
2022-12-23 12:03:56 +00:00
|
|
|
})
|
|
|
|
|
2023-01-10 17:07:18 +00:00
|
|
|
config.setLibrary('md', markdownLib)
|
2022-12-23 12:03:56 +00:00
|
|
|
|
2019-12-02 17:11:32 +00:00
|
|
|
// add collection for pages
|
2023-10-26 18:12:52 +00:00
|
|
|
config.addCollection('categories', (collection) => {
|
2023-10-28 20:20:49 +00:00
|
|
|
|
2023-10-26 18:12:52 +00:00
|
|
|
let categories = fs.readdirSync('_content')
|
|
|
|
categories = categories.filter(c => !c.match(/\.[^/.]{1,4}$/i))
|
|
|
|
|
|
|
|
let _cat = {}
|
|
|
|
|
|
|
|
categories.forEach(cat => {
|
|
|
|
let sorted = []
|
|
|
|
let unsorted = []
|
2019-12-02 15:46:19 +00:00
|
|
|
|
2023-10-26 18:12:52 +00:00
|
|
|
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
|
|
|
|
}
|
2021-07-19 17:55:59 +00:00
|
|
|
} else {
|
2023-10-26 18:12:52 +00:00
|
|
|
unsorted.push(page)
|
2021-07-19 17:55:59 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-26 18:12:52 +00:00
|
|
|
sorted = sorted.filter(p => p.data.published)
|
2021-07-19 17:55:59 +00:00
|
|
|
|
2023-10-26 18:12:52 +00:00
|
|
|
_cat[cat] = sorted.concat(unsorted)
|
|
|
|
})
|
2023-09-03 19:43:03 +00:00
|
|
|
|
2023-10-28 20:20:49 +00:00
|
|
|
let _p = collection.getFilteredByGlob('_content/*.md')
|
|
|
|
let pages = {}
|
|
|
|
// _cat = { ..._cat, ...pages }
|
|
|
|
|
|
|
|
_p.forEach(p => {
|
|
|
|
if (p.data.title != 'index') {
|
|
|
|
pages[p.data.title] = p
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return { ..._cat, ...pages }
|
2019-12-06 15:21:29 +00:00
|
|
|
})
|
|
|
|
|
2022-07-13 16:36:48 +00:00
|
|
|
// custom filters
|
2023-01-10 17:07:18 +00:00
|
|
|
config.addFilter('makeLowercase', (value) => {
|
2022-07-13 16:36:48 +00:00
|
|
|
if (typeof value === 'string' || value instanceof String) {
|
|
|
|
return value.toLowerCase()
|
|
|
|
}
|
|
|
|
})
|
2021-07-19 17:55:59 +00:00
|
|
|
|
2022-07-13 16:36:48 +00:00
|
|
|
// added passthrough for global assets
|
2023-01-10 17:07:18 +00:00
|
|
|
config.addPassthroughCopy('assets')
|
2023-10-26 10:06:12 +00:00
|
|
|
|
2022-07-13 16:36:48 +00:00
|
|
|
// added passthrough for images in their respective folders
|
2023-01-10 17:07:18 +00:00
|
|
|
config.addPassthroughCopy('_content/**/images/**')
|
2021-07-19 17:55:59 +00:00
|
|
|
|
2022-07-13 16:36:48 +00:00
|
|
|
// reutrn updated config
|
|
|
|
return {
|
2023-10-26 18:12:52 +00:00
|
|
|
htmlTemplateEngine: 'webc',
|
2022-07-13 16:36:48 +00:00
|
|
|
dir: {
|
2023-01-10 17:07:18 +00:00
|
|
|
input: '_content', // content
|
|
|
|
includes: '../_includes', // templates
|
|
|
|
output: '_site', // rendered site
|
|
|
|
data: '../_data', // global data files
|
|
|
|
},
|
2019-12-02 15:46:19 +00:00
|
|
|
}
|
2021-07-19 17:55:59 +00:00
|
|
|
}
|