-
-
Save btskinner/4dbe92f204bee43e82c2 to your computer and use it in GitHub Desktop.
Ruby module to include online markdown files in Jekyll site
This file contains hidden or 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
=begin | |
Tag to include markdown text from linked file (e.g. Github README.md) | |
Usage: | |
{% linkmarkdown <filename> %} | |
=end | |
require 'open-uri' | |
module Jekyll | |
class MarkdownTag < Liquid::Tag | |
def initialize(tag_name, url, tokens) | |
super | |
@url = url.strip | |
end | |
def render(context) | |
contents = URI.open(@url, &:read) | |
site = context.registers[:site] | |
converter = Jekyll::Converters::Markdown::KramdownParser.new(site.config) | |
contents = (Liquid::Template.parse contents).render site.site_payload | |
html = converter.convert(contents) | |
end | |
end | |
end | |
Liquid::Template.register_tag('linkmarkdown', Jekyll::MarkdownTag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment