human-anatomy-3d/.eleventy.js

121 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-06-20 18:16:50 +00:00
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');
2020-06-20 18:16:50 +00:00
module.exports = function (eleventyConfig) {
// PLUGINS **************************************************************
2020-06-20 18:16:50 +00:00
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'
}
2020-06-20 18:16:50 +00:00
});
2020-06-20 18:16:50 +00:00
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("**/*.png");
eleventyConfig.addPassthroughCopy("**/*.svg");
eleventyConfig.addPassthroughCopy("node_modules/@glidejs/glide/dist");
2020-06-20 18:16:50 +00:00
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 /gallery and /sponsors
const galleryImages = fg.sync(['**/images/screenshots/*', '!**/_site']);
console.log(galleryImages);
//Create collection of sponsor logos
eleventyConfig.addCollection('screenshots', function (collection) {
return galleryImages.map(url => {
return url.replace('src/', '');
});
});
2020-06-20 18:16:50 +00:00
return {
passthroughFileCopy: true,
2020-06-20 18:16:50 +00:00
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',
// },
// };
2020-06-20 18:16:50 +00:00
};