eleventy-plugin-unified
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"type": "module", | ||
"name": "eleventy-plugin-unified", | ||
"version": "0.0.1", | ||
"description": "Plugin to integrate the unified ecosystem into Eleventy", | ||
"version": "0.0.2", | ||
"description": "Use the unified ecosystem in Eleventy with remark and rehype.", | ||
"main": ".eleventy.cjs", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "npm run lint && npm run ava", | ||
"ava": "c8 --100 ava", | ||
"lint": "eslint src/**/*.cjs src/**/*.js .eleventy.cjs && prettier --check src/**/*.cjs src/**/*.js .eleventy.cjs" | ||
}, | ||
@@ -17,3 +19,11 @@ "keywords": [ | ||
], | ||
"repository": "NickColley/eleventy-plugin-unified", | ||
"license": "MIT", | ||
"engines": { | ||
"node": "^12.17 || ^13.7 || >= 14" | ||
}, | ||
"files": [ | ||
"src", | ||
".eleventy.cjs" | ||
], | ||
"dependencies": { | ||
@@ -25,3 +35,34 @@ "rehype-parse": "^8.0.4", | ||
"unified": "^10.1.2" | ||
}, | ||
"devDependencies": { | ||
"ava": "^5.0.1", | ||
"c8": "^7.12.0", | ||
"eslint": "^8.25.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-n": "^15.3.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"prettier": "^2.7.1" | ||
}, | ||
"eslintConfig": { | ||
"env": { | ||
"es6": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:n/recommended", | ||
"prettier" | ||
], | ||
"plugins": [ | ||
"prettier" | ||
], | ||
"rules": { | ||
"prettier/prettier": "error" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2022 | ||
}, | ||
"ignorePatterns": [ | ||
"!.eleventy.cjs" | ||
] | ||
} | ||
} |
176
README.md
# Eleventy Plugin Unified | ||
Use the [unified](https://unifiedjs.com/) ecosystem in Eleventy. | ||
You can render and transform: | ||
- markdown with the [remark](https://github.com/remarkjs/remark) ecosystem. | ||
- html with the [rehype](https://github.com/rehypejs/rehype) ecosystem. | ||
[retext](https://github.com/retextjs/retext) is not yet supported, raise an issue if you'd like this. | ||
## Install | ||
```bash | ||
npm install eleventy-plugin-unified | ||
``` | ||
```javascript | ||
// .eleventy.config.cjs | ||
const EleventyUnifiedPlugin = require("eleventy-plugin-unified"); | ||
module.exports = function (eleventyConfig) { | ||
eleventyConfig.addPlugin(EleventyUnifiedPlugin); | ||
}; | ||
``` | ||
### Full example | ||
```bash | ||
npm install eleventy-plugin-unified remark-slug rehype-format unist-util-visit | ||
``` | ||
```javascript | ||
// .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" }]], | ||
}); | ||
}; | ||
``` | ||
```javascript | ||
// ./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) | ||
```javascript | ||
// .eleventy.config.cjs | ||
const EleventyUnifiedPlugin = require("eleventy-plugin-unified"); | ||
module.exports = function (eleventyConfig) { | ||
eleventyConfig.addPlugin(EleventyUnifiedPlugin, [ | ||
markdownTransforms: [ | ||
'remark-emoji' | ||
] | ||
]); | ||
}; | ||
``` | ||
### Configuring html transforms (rehype plugins) | ||
```javascript | ||
// .eleventy.config.cjs | ||
const EleventyUnifiedPlugin = require("eleventy-plugin-unified"); | ||
module.exports = function (eleventyConfig) { | ||
eleventyConfig.addPlugin(EleventyUnifiedPlugin, [ | ||
htmlTransforms: [ | ||
'rehype-format' | ||
] | ||
]); | ||
}; | ||
``` | ||
### Configuring options for a plugin | ||
```javascript | ||
// .eleventy.config.cjs | ||
const EleventyUnifiedPlugin = require("eleventy-plugin-unified"); | ||
module.exports = function (eleventyConfig) { | ||
eleventyConfig.addPlugin(EleventyUnifiedPlugin, [ | ||
htmlTransforms: [ | ||
["rehype-format", { indent: "\t" }] | ||
], | ||
]); | ||
}; | ||
``` | ||
### Configuring internal plugins | ||
```javascript | ||
// .eleventy.config.cjs | ||
const EleventyUnifiedPlugin = require("eleventy-plugin-unified"); | ||
module.exports = function (eleventyConfig) { | ||
eleventyConfig.addPlugin(EleventyUnifiedPlugin, [ | ||
markdownTransforms: [ | ||
"./plugins/responsive-tables.js" | ||
], | ||
]); | ||
}; | ||
``` | ||
or | ||
```javascript | ||
// .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 | ||
```bash | ||
npm install eleventy-plugin-unified unist-util-visit | ||
``` | ||
```javascript | ||
// .eleventy.config.cjs | ||
const EleventyUnifiedPlugin = require("eleventy-plugin-unified"); | ||
module.exports = function (eleventyConfig) { | ||
eleventyConfig.addPlugin(EleventyUnifiedPlugin, { | ||
transformsDirectory: "./plugins/", | ||
markdownTransforms: ["log-data.js"], | ||
}); | ||
}; | ||
``` | ||
```javascript | ||
// ./plugins/log-data.js | ||
export default function logData() { | ||
const { pageContext, eleventyConfig } = this.data(); | ||
console.log({ pageContext, eleventyConfig }); | ||
} | ||
``` | ||
## Acknowledgements | ||
Inspiration from [florianeckerstorfer/eleventy-plugin-remark](https://github.com/florianeckerstorfer/eleventy-plugin-remark) | ||
Inspired by [florianeckerstorfer/eleventy-plugin-remark](https://github.com/florianeckerstorfer/eleventy-plugin-remark) |
@@ -8,3 +8,3 @@ import { unified } from "unified"; | ||
html, | ||
{ htmlTransforms, transformsDirectory, pageContext, eleventyConfig } | ||
{ htmlTransforms, transformsDirectory, pageContext, eleventyConfig } = {} | ||
) { | ||
@@ -11,0 +11,0 @@ const output = await unified() |
@@ -10,3 +10,3 @@ import { unified } from "unified"; | ||
markdown, | ||
{ markdownTransforms, transformsDirectory, pageContext, eleventyConfig } | ||
{ markdownTransforms, transformsDirectory, pageContext, eleventyConfig } = {} | ||
) { | ||
@@ -13,0 +13,0 @@ const output = await unified() |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
8951
2
180
7