feat: User setup (#95)

* allow users to add plugins to setup markdown and eleventy

* comments on function

* added userSetup.js to plugin-info.json
This commit is contained in:
Utsob Roy 2023-03-06 13:37:17 +06:00 committed by GitHub
parent 1670b2e64b
commit 59c3cde9e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -7,6 +7,10 @@ const tocPlugin = require("eleventy-plugin-nesting-toc");
const { parse } = require("node-html-parser"); const { parse } = require("node-html-parser");
const { headerToId, namedHeadingsFilter } = require("./src/helpers/utils"); const { headerToId, namedHeadingsFilter } = require("./src/helpers/utils");
const {
userMarkdownSetup,
userEleventySetup,
} = require("./src/helpers/userSetup");
const tagRegex = /(^|\s|\>)(#[^\s!@#$%^&*()=+\.,\[{\]};:'"?><]+)(?!([^<]*>))/g; const tagRegex = /(^|\s|\>)(#[^\s!@#$%^&*()=+\.,\[{\]};:'"?><]+)(?!([^<]*>))/g;
@ -156,7 +160,8 @@ module.exports = function (eleventyConfig) {
return prefix + n; return prefix + n;
}; };
}); })
.use(userMarkdownSetup);
eleventyConfig.setLibrary("md", markdownLib); eleventyConfig.setLibrary("md", markdownLib);
@ -320,6 +325,8 @@ module.exports = function (eleventyConfig) {
return variable; return variable;
}); });
userEleventySetup(eleventyConfig);
return { return {
dir: { dir: {
input: "src/site", input: "src/site",

View File

@ -12,7 +12,8 @@
"src/site/img/tree-1.svg", "src/site/img/tree-1.svg",
"src/site/img/tree-2.svg", "src/site/img/tree-2.svg",
"src/site/img/tree-3.svg", "src/site/img/tree-3.svg",
"src/helpers/userUtils.js" "src/helpers/userUtils.js",
"src/helpers/userSetup.js"
], ],
"filesToModify": [ "filesToModify": [
".eleventy.js", ".eleventy.js",

10
src/helpers/userSetup.js Normal file
View File

@ -0,0 +1,10 @@
function userMarkdownSetup(md) {
// The md parameter stands for the markdown-it instance used throughout the site generator.
// Feel free to add any plugin you want here instead of /.eleventy.js
}
function userEleventySetup(eleventyConfig) {
// The eleventyConfig parameter stands for the the config instantiated in /.eleventy.js.
// Feel free to add any plugin you want here instead of /.eleventy.js
}
exports.userMarkdownSetup = userMarkdownSetup;
exports.userEleventySetup = userEleventySetup;