-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Check for transforms before applying them
Also include JSDoc definitions
- Loading branch information
1 parent
f176080
commit c991d71
Showing
6 changed files
with
74 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,49 @@ | ||
/** | ||
* @param {Object} eleventyConfig | ||
* @param {Object} pluginOptions | ||
* @param {Array.<String>} pluginOptions.markdownTransforms | ||
* @param {Array.<String>} [pluginOptions.htmlTransforms] | ||
* @param {String} [pluginOptions.transformsDirectory] | ||
*/ | ||
function EleventyUnifiedPlugin( | ||
eleventyConfig, | ||
{ markdownTransforms, htmlTransforms, transformsDirectory } = {} | ||
) { | ||
eleventyConfig.setLibrary("md", { | ||
disable: () => {}, // Broken in 2.0.0 canary https://github.com/11ty/eleventy/issues/2613 | ||
render: async (content, pageContext) => { | ||
const { default: render } = await import("./remark.js"); | ||
return render(content, { | ||
transformsDirectory, | ||
markdownTransforms, | ||
pageContext, | ||
eleventyConfig, | ||
}); | ||
}, | ||
}); | ||
eleventyConfig.addTransform( | ||
"eleventy-plugin-unified", | ||
async function (content) { | ||
const pageContext = this; | ||
if ( | ||
!pageContext.outputPath || | ||
!pageContext.outputPath.endsWith(".html") | ||
) { | ||
return content; | ||
if (markdownTransforms instanceof Array && markdownTransforms.length) { | ||
eleventyConfig.setLibrary("md", { | ||
disable: () => {}, // Broken in 2.0.0 canary https://github.com/11ty/eleventy/issues/2613 | ||
render: async (content, pageContext) => { | ||
const { default: render } = await import("./remark.js"); | ||
return render(content, { | ||
transformsDirectory, | ||
markdownTransforms, | ||
pageContext, | ||
eleventyConfig, | ||
}); | ||
}, | ||
}); | ||
} | ||
if (htmlTransforms instanceof Array && htmlTransforms.length) { | ||
eleventyConfig.addTransform( | ||
"eleventy-plugin-unified", | ||
async function (content) { | ||
const pageContext = this; | ||
if ( | ||
!pageContext.outputPath || | ||
!pageContext.outputPath.endsWith(".html") | ||
) { | ||
return content; | ||
} | ||
const { default: render } = await import("./rehype.js"); | ||
return render(content, { | ||
htmlTransforms, | ||
transformsDirectory, | ||
pageContext, | ||
eleventyConfig, | ||
}); | ||
} | ||
const { default: render } = await import("./rehype.js"); | ||
return render(content, { | ||
htmlTransforms, | ||
transformsDirectory, | ||
pageContext, | ||
eleventyConfig, | ||
}); | ||
} | ||
); | ||
); | ||
} | ||
} | ||
|
||
module.exports = EleventyUnifiedPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters