Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
eleventy-plugin-transformdom
Advanced tools
An eleventy plugin to modify the DOM when outputting HTML
Process & change the generated HTML output of your Eleventy site.
Configure the plugin with your CSS selectors and transform functions, then the plugin will run them on each HTML file generated by Eleventy.
Some of the things you could use it to do include:
title
tag to match the first heading on the pageloading="lazy"
attributes to imagesLike this project? Buy me a coffee via PayPal or ko-fi
In your project directory run:
# Using npm
npm install eleventy-plugin-transformdom --save-dev
# Or using yarn
yarn add eleventy-plugin-transformdom --dev
Then update your project's .eleventy.js
to use the plugin:
const transformDomPlugin = require('eleventy-plugin-transformdom');
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(transformDomPlugin, [
{
selector: 'img',
transform: ({ elements }) => {
elements.forEach((img) => {
img.setAttribute('loading', 'lazy');
});
},
},
]);
};
☝️ The example above shows a Transform Item that finds all the images in your HTML and adds loading="lazy"
to the markup. Read on to learn how to customise your own transforms.
The plugin takes a Transform Item array as configuration.
A Transform Item is an Object that contains two keys; selector
& transform
Each Transform Item will be run in order. This means you can write a Transform Item that modifies the DOM, then the next Transform Item can further modify the resulting DOM, and so on.
The "selector" is a CSS selector (string
).
Multiple selectors may be separated with commas.
The "transform" is a function ((args) => void
) that will be run on the generated HTML.
The function will be passed an Object as argument. The args
Object has the following entries:
Key | Type | Description |
---|---|---|
elements | Element[] | An array of elements in the DOM matching the provided selector |
window | DOMWindow | The window of the generated HTML |
document | Document | The window.document of the generated HTML |
inputPath | string | The source file path from which Eleventy is generating the HTML |
outputPath | string | The output path/filename of the HTML file being generated |
inputDir | string | The source directory from which Eleventy is building the site (see the Eleventy docs) |
outputDir | string | The directory inside which the finished templates will be written to by Eleventy (see the Eleventy docs) |
Note: async transform functions are supported, however they will be run in sequence to prevent race conditions.
This project welcomes suggestions and Pull Requests!
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details
Like this project? Buy me a coffee via PayPal or ko-fi
FAQs
An eleventy plugin to modify the DOM when outputting HTML
The npm package eleventy-plugin-transformdom receives a total of 20 weekly downloads. As such, eleventy-plugin-transformdom popularity was classified as not popular.
We found that eleventy-plugin-transformdom demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.