|
| 1 | +const markdownIt = require("markdown-it") |
| 2 | +const htmlmin = require("html-minifier") |
| 3 | +const path = require('path') |
| 4 | +const fs = require('fs') |
| 5 | + |
| 6 | +const isProduction = process.env.NODE_ENV === 'production' |
| 7 | +const slugify = require('slugify') |
| 8 | +const { fstat } = require("fs") |
| 9 | +const slugify_opts = { |
| 10 | + strict: true, |
| 11 | +} |
| 12 | + |
| 13 | + |
| 14 | +module.exports = function(eleventyConfig) { |
| 15 | + // Static Syntax Highlighting Plugin |
| 16 | + const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); |
| 17 | + eleventyConfig.addPlugin(syntaxHighlight); |
| 18 | + |
| 19 | + eleventyConfig.addPassthroughCopy("src/static"); |
| 20 | + |
| 21 | + eleventyConfig.markdownTemplateEngine = 'njk' |
| 22 | + //eleventyConfig.markdownTemplateEngine = 'liquid' |
| 23 | + |
| 24 | + eleventyConfig.dir = { |
| 25 | + input: './src', |
| 26 | + output: "./public" |
| 27 | + } |
| 28 | + |
| 29 | + eleventyConfig.setDataDeepMerge(true) |
| 30 | + |
| 31 | + eleventyConfig.setTemplateFormats([ |
| 32 | + 'njk', |
| 33 | + 'md', |
| 34 | + 'jpg', |
| 35 | + 'png', |
| 36 | + 'js', |
| 37 | + 'csv', |
| 38 | + 'html', |
| 39 | + 'css', |
| 40 | + // 'svg', |
| 41 | + // 'liquid', |
| 42 | + // 'pug', |
| 43 | + // 'ejs', |
| 44 | + // 'hbs', |
| 45 | + // 'mustache', |
| 46 | + // 'haml', |
| 47 | + // '11ty.js', |
| 48 | + ]) |
| 49 | + |
| 50 | + const markdownItOptions = { |
| 51 | + html: true, |
| 52 | + breaks: true, |
| 53 | + linkify: true |
| 54 | + } |
| 55 | + |
| 56 | + md_lib = markdownIt(markdownItOptions) |
| 57 | + .disable('code') |
| 58 | + .use(require('markdown-it-attrs')) |
| 59 | + .use(require('markdown-it-anchor'), { |
| 60 | + slugify: (s) => slugify(s, slugify_opts) |
| 61 | + }) |
| 62 | + |
| 63 | + |
| 64 | + eleventyConfig.setLibrary("md", md_lib) |
| 65 | + |
| 66 | + eleventyConfig.addTransform("htmlmin", function(content, outputPath) { |
| 67 | + if(isProduction && outputPath.endsWith(".html")){ |
| 68 | + let minified = htmlmin.minify(content, { |
| 69 | + useShortDoctype: true, |
| 70 | + removeComments: true, |
| 71 | + collapseWhitespace: true |
| 72 | + }) |
| 73 | + |
| 74 | + return minified |
| 75 | + } |
| 76 | + |
| 77 | + return content |
| 78 | + }) |
| 79 | + |
| 80 | + eleventyConfig.addFilter("slugify", (content) => { |
| 81 | + return slugify(content, slugify_opts); |
| 82 | + }); |
| 83 | + |
| 84 | + eleventyConfig.addShortcode("include_relative", function (relPath) { |
| 85 | + let dir = path.dirname(this.page.inputPath); |
| 86 | + let fulLPath = path.join(dir, relPath); |
| 87 | + return `<div>${fs.readFileSync(fulLPath)}</div>`; |
| 88 | + }); |
| 89 | + |
| 90 | + return eleventyConfig |
| 91 | +} |
0 commit comments