work.suroh.tk/.eleventy.js

70 lines
1.6 KiB
JavaScript
Raw Normal View History

const markdownIt = require('markdown-it')
const mdla = require('markdown-it-link-attributes')
module.exports = (config) => {
// markdown setup
const mdOptions = {
html: true,
linkify: true,
}
const markdownLib = markdownIt(mdOptions)
.use(mdla, {
matcher(href, _c) {
return href.match(/\/@\w+/)
},
attrs: {
rel: 'me',
2023-01-10 17:07:18 +00:00
target: '_blank',
},
})
2023-01-10 17:07:18 +00:00
.disable('code')
2023-01-10 17:07:18 +00:00
config.setLibrary('md', markdownLib)
// add collection for pages
config.addCollection('pages', (collection) => {
2021-07-19 17:55:59 +00:00
let sorted = []
let unsorted = []
2023-09-03 19:43:03 +00:00
let pages = collection.getFilteredByGlob('**/*.md')
2021-07-19 17:55:59 +00:00
for (let page of pages) {
if (page.data.sort) {
if (sorted[page.data.sort]) {
sorted.splice(page.data.sort, 0, page)
2021-07-19 17:55:59 +00:00
} else {
sorted[page.data.sort] = page
}
} else {
unsorted.push(page)
}
}
2021-07-19 17:55:59 +00:00
2023-09-03 19:43:03 +00:00
sorted = sorted.filter(p => p.data.published)
2021-07-19 17:55:59 +00:00
return sorted.concat(unsorted)
})
// custom filters
2023-01-10 17:07:18 +00:00
config.addFilter('makeLowercase', (value) => {
if (typeof value === 'string' || value instanceof String) {
return value.toLowerCase()
}
})
2021-07-19 17:55:59 +00:00
// added passthrough for global assets
2023-01-10 17:07:18 +00:00
config.addPassthroughCopy('assets')
// 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
// reutrn updated config
return {
dir: {
2023-01-10 17:07:18 +00:00
input: '_content', // content
includes: '../_includes', // templates
output: '_site', // rendered site
data: '../_data', // global data files
},
}
2021-07-19 17:55:59 +00:00
}