2022-12-23 12:03:56 +00:00
|
|
|
const markdownIt = require('markdown-it')
|
|
|
|
const mdla = require('markdown-it-link-attributes')
|
|
|
|
|
2019-12-02 15:46:19 +00:00
|
|
|
module.exports = (config) => {
|
|
|
|
|
2022-12-23 12:03:56 +00:00
|
|
|
// markdown setup
|
|
|
|
const mdOptions = {
|
|
|
|
html: true,
|
|
|
|
linkify: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
const markdownLib = markdownIt(mdOptions)
|
|
|
|
.use(mdla, {
|
|
|
|
matcher(href, _config) {
|
|
|
|
return href.match(/\/@\w+/)
|
|
|
|
},
|
|
|
|
attrs: {
|
|
|
|
rel: 'me',
|
|
|
|
target: '_blank'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.disable("code")
|
|
|
|
|
|
|
|
config.setLibrary("md", markdownLib)
|
|
|
|
|
|
|
|
|
2019-12-02 17:11:32 +00:00
|
|
|
// add collection for pages
|
2019-12-02 15:46:19 +00:00
|
|
|
config.addCollection('pages', (collection) => {
|
2021-07-19 17:55:59 +00:00
|
|
|
let sorted = []
|
|
|
|
let unsorted = []
|
|
|
|
const pages = collection.getFilteredByGlob('**/*.md')
|
2019-12-02 15:46:19 +00:00
|
|
|
|
2021-07-19 17:55:59 +00:00
|
|
|
for (let page of pages) {
|
|
|
|
if (page.data.sort) {
|
|
|
|
if (sorted[page.data.sort]) {
|
2022-07-13 16:36:48 +00:00
|
|
|
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)
|
|
|
|
}
|
2019-12-06 15:21:29 +00:00
|
|
|
}
|
2021-07-19 17:55:59 +00:00
|
|
|
|
|
|
|
return sorted.concat(unsorted)
|
2019-12-06 15:21:29 +00:00
|
|
|
})
|
|
|
|
|
2022-07-13 16:36:48 +00:00
|
|
|
// custom filters
|
|
|
|
config.addFilter("makeLowercase", (value) => {
|
|
|
|
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
|
|
|
|
config.addPassthroughCopy("assets")
|
|
|
|
// added passthrough for images in their respective folders
|
|
|
|
config.addPassthroughCopy("_content/**/images/**")
|
2021-07-19 17:55:59 +00:00
|
|
|
|
2022-07-13 16:36:48 +00:00
|
|
|
// reutrn updated config
|
|
|
|
return {
|
|
|
|
dir: {
|
|
|
|
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
|
|
|
}
|