Last active
April 30, 2020 05:08
-
-
Save jaylandro/a16d4df00b2a60735bb9b9222244e180 to your computer and use it in GitHub Desktop.
11ty: Convert href links to markdown (.md) files to directory path links
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
const markdownEngine = markdownIt({ | |
html: true, | |
linkify: true | |
}); | |
const defaultRender = markdownEngine.renderer.rules.link_open || function(tokens, idx, options, env, self) { | |
return self.renderToken(tokens, idx, options); | |
}; | |
markdownEngine.renderer.rules.link_open = function (tokens, idx, options, env, self) { | |
const isMarkDownLink = tokens[idx].attrGet('href').search('.md') !== -1; | |
if (isMarkDownLink) { | |
let newLink = tokens[idx].attrGet('href').replace('.md', ''); | |
tokens[idx].attrSet('href', newLink); | |
} | |
return defaultRender(tokens, idx, options, env, self); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment