diff options
author | Connor Shea <connor.james.shea@gmail.com> | 2016-10-07 08:37:38 +0300 |
---|---|---|
committer | Connor Shea <connor.james.shea@gmail.com> | 2016-10-07 08:37:38 +0300 |
commit | 9195533c920be5677f6bf65fa7c7787d941e4493 (patch) | |
tree | 126e4f7691059f5aaae0f308239c72a6baf2b592 /lib | |
parent | 3c29f001846eb5a4c2db21d34265dd4d5a634906 (diff) |
Add a filter to replace .md URLs with .html, this fixes a ton of URLs.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/filters/markdown_to_html_ext.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/filters/markdown_to_html_ext.rb b/lib/filters/markdown_to_html_ext.rb new file mode 100644 index 00000000..51a35c09 --- /dev/null +++ b/lib/filters/markdown_to_html_ext.rb @@ -0,0 +1,16 @@ +module Nanoc::Filters + class MarkdownToHtmlExt < Nanoc::Filter + identifier :md_to_html_ext + + # Convert internal URLs that link to `.md` files to instead link to + #{ }`.html` files since that's what Nanoc actually serves. + def run(content, params = {}) + content.gsub(/href="(\S*.md)"/) do |result| # Fetch all links in the HTML Document + if /http/.match(result).nil? # Check if link is internal + result.gsub!(/\.md/, '.html') # Replace the extension if link is internal + end + result + end + end + end +end |