Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorConnor Shea <connor.james.shea@gmail.com>2016-10-07 08:37:38 +0300
committerConnor Shea <connor.james.shea@gmail.com>2016-10-07 08:37:38 +0300
commit9195533c920be5677f6bf65fa7c7787d941e4493 (patch)
tree126e4f7691059f5aaae0f308239c72a6baf2b592 /lib
parent3c29f001846eb5a4c2db21d34265dd4d5a634906 (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.rb16
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