2023-06-05 19:38:11 -07:00
|
|
|
const esbuild = require('esbuild')
|
2023-06-05 18:33:36 -07:00
|
|
|
|
|
|
|
module.exports = function (eleventyConfig) {
|
|
|
|
// Process SCSS
|
2023-06-04 18:53:07 -07:00
|
|
|
eleventyConfig.addPlugin(require('eleventy-sass'), {
|
|
|
|
postcss: require('postcss')([
|
|
|
|
require('postcss-preset-env'),
|
2023-06-05 19:38:11 -07:00
|
|
|
require('cssnano'),
|
|
|
|
]),
|
|
|
|
})
|
2023-06-04 18:53:07 -07:00
|
|
|
|
2023-06-05 21:53:24 -07:00
|
|
|
// Copy CSS assets
|
|
|
|
eleventyConfig.addPassthroughCopy('src/style/assets')
|
|
|
|
|
2023-06-07 19:39:51 -07:00
|
|
|
// Copy collections & links
|
2023-06-08 18:01:48 -07:00
|
|
|
eleventyConfig.addPassthroughCopy('src/collections/images/**/*')
|
2023-06-07 20:37:28 -07:00
|
|
|
eleventyConfig.addPassthroughCopy('src/images')
|
2023-06-06 19:18:44 -07:00
|
|
|
|
2023-06-05 19:38:11 -07:00
|
|
|
// Process JS
|
|
|
|
eleventyConfig.addTemplateFormats('js')
|
|
|
|
eleventyConfig.addExtension('js', {
|
|
|
|
outputFileExtension: 'js',
|
|
|
|
compile: async (content, path) => {
|
|
|
|
if (path !== './src/js/main.js') {
|
|
|
|
return
|
|
|
|
}
|
2023-06-05 18:33:36 -07:00
|
|
|
|
2023-06-05 19:38:11 -07:00
|
|
|
return async () => {
|
|
|
|
const output = await esbuild.build({
|
|
|
|
target: 'es2020',
|
|
|
|
entryPoints: [path],
|
|
|
|
minify: true,
|
|
|
|
bundle: true,
|
|
|
|
write: false,
|
|
|
|
})
|
|
|
|
|
|
|
|
return output.outputFiles[0].text
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-06-08 16:43:45 -07:00
|
|
|
// Convert img filename to alt text
|
|
|
|
eleventyConfig.addFilter('toAlt', (text) => {
|
|
|
|
const basename = text.split('.')
|
2023-06-08 17:09:47 -07:00
|
|
|
return basename[0].replace(/-/g, ' ')
|
2023-06-08 16:43:45 -07:00
|
|
|
})
|
|
|
|
|
2023-06-08 20:03:36 -07:00
|
|
|
// Convert diary date path to slug
|
|
|
|
eleventyConfig.addFilter('datePathSlugify', (path) => {
|
|
|
|
const folders = path.split('/')
|
|
|
|
const file = folders.pop().split('.')
|
|
|
|
return `${folders[3]}/${folders[4]}/${file[0]}`
|
|
|
|
})
|
|
|
|
|
2023-06-08 20:17:58 -07:00
|
|
|
// RSS
|
|
|
|
eleventyConfig.addPlugin(require('@11ty/eleventy-plugin-rss'))
|
|
|
|
|
2023-06-05 19:38:11 -07:00
|
|
|
return {dir: {input: 'src', output: 'dist'}}
|
2023-06-04 16:55:36 -07:00
|
|
|
}
|