From 9cf76b2f189cf39105fa59b4bd1b7617af26283c Mon Sep 17 00:00:00 2001 From: "David A. Harding" Date: Wed, 3 Jun 2015 15:27:29 -0400 Subject: [PATCH] New Plugin: Githubify Bitcoin Core Release Notes --- _plugins/githubify.rb | 73 +++++++++++++++++++++++++++++++++++++++++++ _releases/0.10.0.md | 2 ++ _releases/0.10.1.md | 2 ++ _releases/0.10.2.md | 2 ++ 4 files changed, 79 insertions(+) create mode 100644 _plugins/githubify.rb diff --git a/_plugins/githubify.rb b/_plugins/githubify.rb new file mode 100644 index 00000000..0ccd3899 --- /dev/null +++ b/_plugins/githubify.rb @@ -0,0 +1,73 @@ +# This file is licensed under the MIT License (MIT) available on +# http://opensource.org/licenses/MIT. + +## githubify.rb automatically adds links to pull requests, issues, and +## commits using pattern matches + +## Example (URL is the repository to link to): +## {% githubify https://github.com/bitcoin/bitcoin %} +## ...content... +## {% endgithubify %} + +module Jekyll + +require 'yaml' + + class GitHubifyBlock < Liquid::Block + + def initialize(tag_name, text, tokens) + super + @repository_url = text.strip() + end + + def render(context) + output = super + + ## Convert #1234 into URL for the pull request + ## If #1234 links to an issue, GitHub automatically redirects + # + ## Require at least two digits to reduce false positive matches + output.gsub!(/#([0-9][0-9][0-9]*)/){ |s| + '' + s + '' + } + + ## Convert `123abcd` into URL for the commit + # + ## Only operate on 7 to 10 chars to reduce false positive matches + output.gsub!(/`([0-9abcdef]{7,10})`/){ |s| + '' + s + '' + } + + output + end + end +end + + +## Code to run if plugin is disabled +module Jekyll + +require 'yaml' + + class GitHubifyBlockDisabled < Liquid::Block + + def initialize(tag_name, text, tokens) + super + end + + def render(context) + output = super + + output + end + end +end + +#Do nothing if plugin is disabled +plugin_name = "githubify" +if !ENV['ENABLED_PLUGINS'].nil? and ENV['ENABLED_PLUGINS'].index(plugin_name).nil? + print plugin_name + ' disabled' + "\n" + Liquid::Template.register_tag(plugin_name, Jekyll::GitHubifyBlockDisabled) +else + Liquid::Template.register_tag(plugin_name, Jekyll::GitHubifyBlock) +end diff --git a/_releases/0.10.0.md b/_releases/0.10.0.md index c6c73fcd..39c00e46 100644 --- a/_releases/0.10.0.md +++ b/_releases/0.10.0.md @@ -22,6 +22,7 @@ optional_magnetlink: "magnet:?xt=urn:btih:170c61fe09dafecfbb97cb4dccd32173383f4e ## 2. Place URLs inside angle brackets, like --- +{% githubify https://github.com/bitcoin/bitcoin %} Bitcoin Core version 0.10.0 is now available from: @@ -798,3 +799,4 @@ Thanks to everyone who contributed to this release: - Zak Wilcox As well as everyone that helped translating on [Transifex](https://www.transifex.com/projects/p/bitcoin/). +{% endgithubify %} diff --git a/_releases/0.10.1.md b/_releases/0.10.1.md index 17df1b49..1917ba0e 100644 --- a/_releases/0.10.1.md +++ b/_releases/0.10.1.md @@ -22,6 +22,7 @@ optional_magnetlink: "magnet:?xt=urn:btih:b6f8da60aaf2007cd6db631637951ae673e310 ## 2. Place URLs inside angle brackets, like --- +{% githubify https://github.com/bitcoin/bitcoin %} Bitcoin Core version 0.10.1 is now available from: @@ -161,3 +162,4 @@ Thanks to everyone who contributed to this release: - Wladimir J. van der Laan As well as everyone that helped translating on [Transifex](https://www.transifex.com/projects/p/bitcoin/). +{% endgithubify %} diff --git a/_releases/0.10.2.md b/_releases/0.10.2.md index 30cdf599..cfc94cbf 100644 --- a/_releases/0.10.2.md +++ b/_releases/0.10.2.md @@ -22,6 +22,7 @@ optional_magnetlink: "magnet:?xt=urn:btih:746a616aa8de97856c207e7a899c7ee315e8c4 ## 2. Place URLs inside angle brackets, like --- +{% githubify https://github.com/bitcoin/bitcoin %} Bitcoin Core version 0.10.2 is now available from: @@ -109,3 +110,4 @@ And all those who contributed additional code review and/or security research: As well as everyone that helped translating on [Transifex](https://www.transifex.com/projects/p/bitcoin/). +{% endgithubify %}