0.0.4 • Published 11 months ago

@web-alchemy/eleventy-plugin-edgejs v0.0.4

Weekly downloads
-
License
-
Repository
github
Last release
11 months ago

Eleventy Plugin that adds support Edge.js template engine

This plugin allows to use Edge.js as template engine for Eleventy.

Installation

npm install @web-alchemy/eleventy-plugin-edgejs

Usage

const EdgeJsPlugin = require('@web-alchemy/eleventy-plugin-edgejs')

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(EdgeJsPlugin, {
    // you can extend current edge instance
    extendEdgeInstance: async function (edge, eleventyUserConfig) {
      edge.global('version', '1.0.0')

      edge.registerTag({
        block: false,
        seekable: true,
        tagName: 'rawInclude',
        compile (parser, buffer, token) {
          const fileName = token.properties.jsArg.trim()
          const fullPath = path.join(process.cwd(), eleventyUserConfig.dir.input, fileName)
          const fileContent = fs.readFileSync(fullPath, 'utf-8')
          buffer.outputRaw(fileContent)
        }
      })
    },

    // ... or create own new edge instance
    createEdgeInstance: async function(eleventyUserConfig) {
      const { Edge } = require('edge.js')
      
      const edge = new Edge({
        cache: false
      })
      
      const { dir } = eleventyUserConfig

      edge.mount(path.join(cwd, dir.input))
      edge.mount('includes', path.join(cwd, dir.input, dir.includes))
      
      return edge
    },

    // optional condition for skipping template rendering
    skipRenderCondition: function (inputContent, inputPath) {
      return inputPath.includes('components')
    }
  })
}

If options has createEdgeInstance function, then extendEdgeInstance will be ignored.

Links