New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eleventy-plugin-unified

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eleventy-plugin-unified

Use the unified ecosystem in Eleventy with remark and rehype.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Eleventy Plugin Unified

past latest npm version

Use the unified ecosystem in Eleventy.

You can render and transform:

  • markdown with the remark ecosystem.
  • html with the rehype ecosystem.

retext is not yet supported, raise an issue if you'd like this.

Install

npm install eleventy-plugin-unified
// .eleventy.config.cjs
const EleventyUnifiedPlugin = require("eleventy-plugin-unified");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(EleventyUnifiedPlugin, [
    "remark-slug", // Add [id] attributes to headings.
  ]);
};

Full example

npm install eleventy-plugin-unified remark-slug rehype-format unist-util-visit
// .eleventy.config.cjs
const EleventyUnifiedPlugin = require("eleventy-plugin-unified");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(EleventyUnifiedPlugin, {
    transformsDirectory: "./plugins/",
    markdownTransforms: ["aria-current-links.js", "remark-slug"],
    htmlTransforms: [["rehype-format", { indent: "\t" }]],
  });
};
// ./plugins/aria-current-links.js
import { join } from "node:path";
import { visit } from "unist-util-visit";

// If the link matches the current page set 'aria-current' to true
export default function ariaCurrentLinks() {
  const {
    pageContext: { page },
  } = this.data();
  return (tree) => {
    visit(tree, ["link", "linkReference"], (node) => {
      const url = node?.url;
      if (url && join(page.filePathStem) !== join(url)) {
        return;
      }
      node.data = {
        ...node.data,
        hProperties: {
          ...node.data.hProperties,
          "aria-current": "true",
        },
      };
    });
  };
}

Configuring markdown transforms (remark plugins)

// .eleventy.config.cjs
const EleventyUnifiedPlugin = require("eleventy-plugin-unified");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(EleventyUnifiedPlugin, [
    markdownTransforms: [
        'remark-emoji'
    ]
  ]);
};

Configuring html transforms (rehype plugins)

// .eleventy.config.cjs
const EleventyUnifiedPlugin = require("eleventy-plugin-unified");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(EleventyUnifiedPlugin, [
    htmlTransforms: [
        'rehype-format'
    ]
  ]);
};

Configuring options for a plugin

// .eleventy.config.cjs
const EleventyUnifiedPlugin = require("eleventy-plugin-unified");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(EleventyUnifiedPlugin, [
    htmlTransforms: [
        ["rehype-format", { indent: "\t" }]
    ],
  ]);
};

Configuring internal plugins

// .eleventy.config.cjs
const EleventyUnifiedPlugin = require("eleventy-plugin-unified");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(EleventyUnifiedPlugin, [
    markdownTransforms: [
        "./plugins/responsive-tables.js"
    ],
  ]);
};

or

// .eleventy.config.cjs
const EleventyUnifiedPlugin = require("eleventy-plugin-unified");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(EleventyUnifiedPlugin, [
    transformsDirectory: "./plugins",
    markdownTransforms: [
        "responsive-tables.js"
    ],
  ]);
};

Getting access to page context and eleventy config

npm install eleventy-plugin-unified unist-util-visit
// .eleventy.config.cjs
const EleventyUnifiedPlugin = require("eleventy-plugin-unified");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(EleventyUnifiedPlugin, {
    transformsDirectory: "./plugins/",
    markdownTransforms: ["log-data.js"],
  });
};
// ./plugins/log-data.js

export default function logData() {
  const { pageContext, eleventyConfig } = this.data();
  console.log({ pageContext, eleventyConfig });
}

Acknowledgements

Inspired by florianeckerstorfer/eleventy-plugin-remark

Keywords

FAQs

Package last updated on 28 Oct 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc