You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.8 KiB

2 years ago
  1. const htmlmin = require('html-minifier');
  2. const dateFns = require('date-fns');
  3. const lazyImagesPlugin = require('eleventy-plugin-lazyimages');
  4. const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
  5. const i18n = require('eleventy-plugin-i18n');
  6. const translations = require('./src/_data/i18n');
  7. module.exports = function (eleventyConfig) {
  8. // PLUGINS **************************************************************
  9. eleventyConfig.addPlugin(syntaxHighlight);
  10. // does not work with background images
  11. eleventyConfig.addPlugin(lazyImagesPlugin, {
  12. transformImgPath: (imgPath) => {
  13. if (imgPath.startsWith('http://') || imgPath.startsWith('https://')) {
  14. // Handle remote file
  15. return imgPath;
  16. } else {
  17. return `./src/${imgPath}`;
  18. }
  19. },
  20. });
  21. eleventyConfig.addPlugin(i18n, {
  22. translations,
  23. fallbackLocales: {
  24. '*': 'en-US',
  25. },
  26. });
  27. eleventyConfig.setEjsOptions({
  28. rmWhitespace: true,
  29. context: {
  30. dateFns,
  31. },
  32. });
  33. eleventyConfig.setBrowserSyncConfig({
  34. files: './_site/assets/styles/main.css',
  35. });
  36. // use this to redirect to en-US
  37. // eleventyConfig.setBrowserSyncConfig({
  38. // files: './_site/assets/styles/main.css',
  39. // callbacks: {
  40. // ready: function (err, bs) {
  41. // bs.addMiddleware('*', (req, res) => {
  42. // if (req.url === '/') {
  43. // res.writeHead(302, {
  44. // location: '/en-US/'
  45. // });
  46. // res.end();
  47. // }
  48. // });
  49. // }
  50. // }
  51. // });
  52. eleventyConfig.addPassthroughCopy('styles/fonts');
  53. eleventyConfig.addPassthroughCopy('src/assets/images/**/*.png');
  54. eleventyConfig.addPassthroughCopy('src/assets/images/**/*.svg');
  55. eleventyConfig.addPassthroughCopy('src/assets/images/**/*.jpg');
  56. eleventyConfig.addPassthroughCopy('node_modules/@glidejs/glide/dist');
  57. eleventyConfig.addPassthroughCopy('node_modules/blueimp-md5/js');
  58. eleventyConfig.addTransform('htmlmin', (content, outputPath) => {
  59. if (outputPath.endsWith('.html')) {
  60. const minified = htmlmin.minify(content, {
  61. useShortDoctype: true,
  62. removeComments: true,
  63. collapseWhitespace: true,
  64. minifyJS: true,
  65. });
  66. return minified;
  67. }
  68. return content;
  69. });
  70. // Import fast-glob package
  71. const fg = require('fast-glob');
  72. // Run search for images in /screenshots
  73. const galleryThumbnails = fg.sync(['**/images/screenshots/*resized*', '!**/_site']);
  74. const galleryImagesAll = fg.sync(['**/images/screenshots/*', '!**/_site']);
  75. //Create collection of screenshots
  76. eleventyConfig.addCollection('screenshotThumbnails', function (collection) {
  77. return galleryThumbnails.map((url) => {
  78. return url.replace('src/', '');
  79. });
  80. });
  81. //Create collection of screenshots
  82. eleventyConfig.addCollection('screenshotHires', function (collection) {
  83. return galleryImagesAll
  84. .filter((url) => !url.includes('resized'))
  85. .map((url) => {
  86. return url.replace('src/', '');
  87. });
  88. });
  89. return {
  90. passthroughFileCopy: true,
  91. dir: { input: 'src', output: '_site', data: '_data' },
  92. };
  93. // return {
  94. // templateFormats: ['md', 'njk', 'html', 'liquid'],
  95. // // If your site lives in a different subdirectory, change this.
  96. // // Leading or trailing slashes are all normalized away, so don’t worry about it.
  97. // // If you don’t have a subdirectory, use "" or "/" (they do the same thing)
  98. // // This is only used for URLs (it does not affect your file structure)
  99. // pathPrefix: '/',
  100. // markdownTemplateEngine: 'liquid',
  101. // htmlTemplateEngine: 'njk',
  102. // dataTemplateEngine: 'njk',
  103. // passthroughFileCopy: true,
  104. // dir: {
  105. // input: '.',
  106. // includes: '_includes',
  107. // data: '_data',
  108. // output: 'docs',
  109. // },
  110. // };
  111. };