human-anatomy-3d/.eleventy.js
2021-11-03 20:48:28 +01:00

119 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const htmlmin = require('html-minifier');
const dateFns = require('date-fns');
const lazyImagesPlugin = require('eleventy-plugin-lazyimages');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const i18n = require('eleventy-plugin-i18n');
const translations = require('./src/_data/i18n');
module.exports = function (eleventyConfig) {
// PLUGINS **************************************************************
eleventyConfig.addPlugin(syntaxHighlight);
// does not work with background images
eleventyConfig.addPlugin(lazyImagesPlugin, {
transformImgPath: (imgPath) => {
if (imgPath.startsWith('http://') || imgPath.startsWith('https://')) {
// Handle remote file
return imgPath;
} else {
return `./src/${imgPath}`;
}
},
});
eleventyConfig.addPlugin(i18n, {
translations,
fallbackLocales: {
'es-ES': 'en-US'
}
});
eleventyConfig.setEjsOptions({
rmWhitespace: true,
context: {
dateFns,
},
});
eleventyConfig.setBrowserSyncConfig({
files: './_site/assets/styles/main.css',
});
// use this to redirect to en-GB
// eleventyConfig.setBrowserSyncConfig({
// files: './_site/assets/styles/main.css',
// callbacks: {
// ready: function (err, bs) {
// bs.addMiddleware('*', (req, res) => {
// if (req.url === '/') {
// res.writeHead(302, {
// location: '/en-GB/'
// });
// res.end();
// }
// });
// }
// }
// });
eleventyConfig.addPassthroughCopy("styles/fonts");
eleventyConfig.addPassthroughCopy("src/assets/images/**/*.png");
eleventyConfig.addPassthroughCopy("src/assets/images/**/*.svg");
eleventyConfig.addPassthroughCopy("node_modules/@glidejs/glide/dist");
eleventyConfig.addTransform('htmlmin', (content, outputPath) => {
if (outputPath.endsWith('.html')) {
const minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
minifyJS: true,
});
return minified;
}
return content;
});
// Import fast-glob package
const fg = require('fast-glob');
// Run search for images in /screenshots
const galleryImages = fg.sync(['**/images/screenshots/*resized*', '!**/_site']);
//Create collection of screenshots
eleventyConfig.addCollection('screenshots', function (collection) {
return galleryImages.map(url => {
return url.replace('src/', '');
});
});
return {
passthroughFileCopy: true,
dir: { input: 'src', output: '_site', data: '_data' },
};
// return {
// templateFormats: ['md', 'njk', 'html', 'liquid'],
// // If your site lives in a different subdirectory, change this.
// // Leading or trailing slashes are all normalized away, so dont worry about it.
// // If you dont have a subdirectory, use "" or "/" (they do the same thing)
// // This is only used for URLs (it does not affect your file structure)
// pathPrefix: '/',
// markdownTemplateEngine: 'liquid',
// htmlTemplateEngine: 'njk',
// dataTemplateEngine: 'njk',
// passthroughFileCopy: true,
// dir: {
// input: '.',
// includes: '_includes',
// data: '_data',
// output: 'docs',
// },
// };
};