diff options
author | Connor Shea <connor.james.shea@gmail.com> | 2016-10-22 02:27:31 +0300 |
---|---|---|
committer | Connor Shea <connor.james.shea@gmail.com> | 2016-10-22 02:35:38 +0300 |
commit | e96a8447c080b329240fadbc8b698476a94c4f78 (patch) | |
tree | a794666ff373f5fb4a5bf155e9076a93b7f298de /lib | |
parent | 48890c97df3f9bbc2fd326875bb46b99d32c6bf0 (diff) |
Add Edit on GitLab.com links to every page. Doesn't actually work for Omnibus right now.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/filters/edit_on_gitlab_link.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/filters/edit_on_gitlab_link.rb b/lib/filters/edit_on_gitlab_link.rb new file mode 100644 index 00000000..06010030 --- /dev/null +++ b/lib/filters/edit_on_gitlab_link.rb @@ -0,0 +1,24 @@ +module Nanoc::Filters + class EditOnGitLabLink < Nanoc::Filter + identifier :edit_on_gitlab_link + + def run(content, params = {}) + # Returns the source content's path. + content_filename = @item[:content_filename] + # Make an array out of the path + content_filename_array = content_filename.split('/') + # Remove "/content/" + content_filename_array.shift + # Get the product name. + product = content_filename_array.shift + # This should be the path from the doc/ directory for a given file. + content_filename = content_filename_array.join("/") + + # Replace `EDIT_ON_GITLAB_LINK` with the actual URL. + content.gsub(/href="(EDIT_ON_GITLAB_LINK)"/) do |result| + result.gsub!(/EDIT_ON_GITLAB_LINK/, "https://gitlab.com/gitlab-org/gitlab-#{product}/blob/master/doc/#{content_filename}") + result + end + end + end +end |