eleventy-introspector

1.0.2 • Public • Published

eleventy-introspector

A simple library that allows you to access the Eleventy instance from anywhere (.eleventy.js, plugins, etc.)

npm npm peer dependency version License: MIT

Installation

npm install eleventy-introspector

Usage

Open up your Eleventy config file (probably .eleventy.js), for example, require eleventy-introspector, and use its eleventy property as you like.

const intros = require("eleventy-introspector");
const path = require("path");

module.exports = function(eleventyConfig) {
  eleventyConfig.addShortcode("installedPlugins", function() {
    return intros.eleventy.config.plugins.map(p => {
      return intros.eleventy.eleventyConfig.userConfig._getPluginName(p.plugin) ?? "N/A";
    }).join(", ");
  });

  eleventyConfig.addFilter("inputPathToOutputPath", function(inputPath) {
    return intros.eleventy.writer.templateMap.getMap().find(mapEntry => {
      return path.relative(mapEntry.inputPath, inputPath) === "";
    })?.outputPath;
  });
};

Package Sidebar

Install

npm i eleventy-introspector

Weekly Downloads

171

Version

1.0.2

License

MIT

Unpacked Size

5.41 kB

Total Files

5

Last publish

Collaborators

  • kentaroi