@web-alchemy/eleventy-plugin-edgejs

0.0.4 • Public • Published

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

Package Sidebar

Install

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

Weekly Downloads

0

Version

0.0.4

License

none

Unpacked Size

4.93 kB

Total Files

3

Last publish

Collaborators

  • monochromer