|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const glob = require('fast-glob') |
| 4 | +const path = require('path') |
| 5 | + |
| 6 | +/** |
| 7 | + * The @11ty/eleventy configuration. |
| 8 | + * |
| 9 | + * For a full list of options, see: https://www.11ty.io/docs/config/ |
| 10 | + */ |
| 11 | +module.exports = (eleventyConfig) => { |
| 12 | + const paths = { |
| 13 | + filters: path.join(process.cwd(), 'lib/filters/*.js'), |
| 14 | + shortcodes: path.join(process.cwd(), 'lib/shortcodes/*.js'), |
| 15 | + transforms: path.join(process.cwd(), 'lib/transforms/*.js'), |
| 16 | + } |
| 17 | + const dirs = { |
| 18 | + input: 'src', |
| 19 | + data: `./_data/`, |
| 20 | + includes: `./_includes/`, |
| 21 | + layouts: `./_layouts/`, |
| 22 | + } |
| 23 | + const files = glob.sync(path.join(process.cwd(), dirs.input, '**/*')) |
| 24 | + const exts = files |
| 25 | + .map((file) => path.extname(file).replace('.', '')) |
| 26 | + .filter((value, index, self) => self.indexOf(value) === index) // Removes duplicates, Makes array unique |
| 27 | + .filter((it) => !['purs', 'css'].includes(it)) |
| 28 | + const filters = glob.sync(paths.filters) |
| 29 | + const shortcodes = glob.sync(paths.shortcodes) |
| 30 | + const transforms = glob.sync(paths.transforms) |
| 31 | + |
| 32 | + // Add all found filters |
| 33 | + filters.forEach((filter) => |
| 34 | + eleventyConfig.addFilter(resolveNameFromPath(filter), require(filter)) |
| 35 | + ) |
| 36 | + |
| 37 | + // Add all found shortcodes |
| 38 | + shortcodes.forEach((shortcode) => { |
| 39 | + const name = resolveNameFromPath(shortcode) |
| 40 | + if (name.endsWith('_ctx')) |
| 41 | + return eleventyConfig.addPairedShortcode(name, require(shortcode)) |
| 42 | + else return eleventyConfig.addShortcode(name, require(shortcode)) |
| 43 | + }) |
| 44 | + |
| 45 | + // Add all found transforms |
| 46 | + transforms.forEach((transform) => |
| 47 | + eleventyConfig.addTransform( |
| 48 | + resolveNameFromPath(transform), |
| 49 | + require(transform) |
| 50 | + ) |
| 51 | + ) |
| 52 | + |
| 53 | + // Make all files pass through to cache |
| 54 | + eleventyConfig.setTemplateFormats(exts) |
| 55 | + eleventyConfig.setWatchJavaScriptDependencies(false) |
| 56 | + |
| 57 | + // eleventyConfig.addPassthroughCopy(`${dirs.input}/assets`) |
| 58 | + |
| 59 | + // Because of Purescript pure/ folder we need to ignore it for git but pass it through the 11ty |
| 60 | + // .eleventyignore Only source of ignoring files for 11ty |
| 61 | + eleventyConfig.setUseGitIgnore(false) |
| 62 | + |
| 63 | + // eleventyConfig.setBrowserSyncConfig({ |
| 64 | + // notify: true |
| 65 | + // }); |
| 66 | + |
| 67 | + return { |
| 68 | + // Set the path from the root of the deploy domain |
| 69 | + // i.e, example.com + "/" |
| 70 | + pathPrefix: '/', |
| 71 | + |
| 72 | + // Set the src and output directories |
| 73 | + dir: dirs, |
| 74 | + |
| 75 | + // Set the default template engine from `liquid` to `njk` |
| 76 | + htmlTemplateEngine: 'njk', |
| 77 | + markdownTemplateEngine: 'njk', |
| 78 | + dataTemplateEngine: 'njk', |
| 79 | + |
| 80 | + // Set up eleventy to pass-through files to be compiled by Parcel |
| 81 | + passthroughFileCopy: true, |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +function resolveNameFromPath(pth) { |
| 86 | + return path.basename(pth, '.js') |
| 87 | +} |
0 commit comments