1.0.2 • Published 1 year ago
eleventy-introspector v1.0.2
eleventy-introspector
A simple library that allows you to access the Eleventy instance from anywhere (.eleventy.js
, plugins, etc.)
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;
});
};