I am pretty new to websites with Jekyll hosted on Github, and I was wondering if there was a neat way to include the contents of a markdown page (say this one) into a post (say this one) in order to always have the contents up to date if the source page is modified?
1 Answer
Breno Salgado posted this simple Jekyll plugin on StackOverflow:
./_plugins/markdown_tag.rb:
module Jekyll
class MarkdownTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text.strip
end
require "kramdown"
def render(context)
"#{Kramdown::Document.new(File.read(File.join(Dir.pwd, '_includes', @text))).to_html}"
end
end
end
Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag)
According to this page you should be able to use code like this:
{% markdown test.md %}
To render the contents of the markdown file.
-
Great, thank you for that, I managed to set it up. However, because the files I want to include are in a different repo (but same project), how do I tell Jekyll to look for them there (and not just in '_includes'), without having to create a submodule?– straguJun 20, 2014 at 5:01
-
At the end, it is not possible to use a custom plugin on GitHub Pages because they override parts of _config.yml to always enable the Jekyll safe mode (and therefore only allow the few plugins supported by GitHub). I will have to find a different solution...– straguJun 20, 2014 at 14:06