This repository has been archived on 2023-03-14. You can view files and clone it, but cannot push or open issues or pull requests.
personal-website-old/.eleventy.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-10-18 20:58:07 +00:00
const pluginNavigation = require('@11ty/eleventy-navigation')
const markdownItAttrs = require('markdown-it-attrs')
2022-01-22 08:31:25 +00:00
const markdownIt = require('markdown-it')
const htmlmin = require('html-minifier')
const yaml = require("js-yaml");
2021-10-07 20:45:46 +00:00
const options = {
html: true,
breaks: true,
linkify: true
2021-10-18 20:58:07 +00:00
}
const markdownLib = markdownIt(options).use(markdownItAttrs)
2021-10-07 20:45:46 +00:00
2022-01-22 08:31:25 +00:00
2021-05-20 20:02:50 +00:00
module.exports = function (eleventyConfig) {
2022-01-22 08:31:25 +00:00
eleventyConfig.addDataExtension("yml", contents => yaml.load(contents));
2021-10-18 20:58:07 +00:00
eleventyConfig.addGlobalData('username', 'Laureηt')
eleventyConfig.addWatchTarget('./src/scss/')
2022-01-22 08:31:25 +00:00
eleventyConfig.setLibrary('md', markdownLib)
eleventyConfig.addPlugin(pluginNavigation)
2021-05-20 20:02:50 +00:00
eleventyConfig.addPassthroughCopy({
2021-10-18 20:58:07 +00:00
'assets/': './'
})
2021-10-18 20:58:07 +00:00
if (process.env.ELEVENTY_ENV === 'prod') {
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
2021-10-07 16:31:51 +00:00
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
2021-10-18 20:58:07 +00:00
if (outputPath && outputPath.endsWith('.html')) {
const minified = htmlmin.minify(content, {
2022-01-22 08:31:25 +00:00
collapseWhitespace: true,
2021-10-07 16:31:51 +00:00
useShortDoctype: true,
removeComments: true,
2022-01-22 08:31:25 +00:00
minifyCSS: true,
minifyJS: true
2021-10-18 20:58:07 +00:00
})
return minified
2021-10-07 16:31:51 +00:00
} else {
2021-10-18 20:58:07 +00:00
return content
2021-10-07 16:31:51 +00:00
}
2021-10-18 20:58:07 +00:00
})
2021-10-07 16:31:51 +00:00
}
2021-10-18 20:58:07 +00:00
eleventyConfig.addShortcode('year', () => {
const year = new Date().getFullYear()
return year.toString()
})
2021-05-20 20:02:50 +00:00
return {
2022-01-22 08:42:17 +00:00
markdownTemplateEngine: 'njk',
2021-10-07 20:45:46 +00:00
passthroughFileCopy: true,
2021-05-20 20:02:50 +00:00
dir: {
2022-01-22 08:31:25 +00:00
includes: '_includes',
2021-10-18 20:58:07 +00:00
output: '_site',
2022-01-22 08:31:25 +00:00
data: '_data',
input: 'src'
2021-10-18 20:58:07 +00:00
}
2021-05-20 20:02:50 +00:00
}
2021-10-07 16:31:51 +00:00
}