forked from bitcoin-dot-org/Bitcoin.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
releases.rb
98 lines (76 loc) · 3.17 KB
/
releases.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# This file is licensed under the MIT License (MIT) available on
# http://opensource.org/licenses/MIT.
#releases.rb generates release pages using files in _releases
#and assign them the 'release' category.
#This is later used to loop through site.pages in order
#to display the release's list in version order, both
#on the "Version history" page and RSS file.
# This plugin also finds the highest required_version of
# Bitcoin Core and populates the Download page with variables set in
# that release file
require 'yaml'
module Jekyll
class ReleasePage < Page
def initialize(site, base, lang, srcdir, src, output_directory)
@site = site
@base = base
@dir = '/' output_directory
## Read in the file's YAML header
self.read_yaml(File.join(base, srcdir), src)
## Die if required_ variables aren't set
if self.data['required_version']
version = self.data['required_version']
else
abort("Error: Variable required_version not set when processing " src)
end
## Output file is v<version>.md (converted later to HTML)
output_file = "v" version ".md"
@name = output_file
self.process(output_file)
## Title required for <title></title> in _layouts/base.html
self.data['title'] = self.data['optional_title'] ? self.data['optional_title'] : "Bitcoin Core version %v released"
self.data['title'].gsub!('%v', version)
## For translation, but currently always set to "en"
self.data['lang'] = lang
## Only processes numeric version numbers with up to five decimals
self.data['versionint'] = versiontoint(self.data['required_version'])
self.data['layout'] = 'release'
self.data['category'] = 'release'
## If this is the highest version we've seen so far...
if !site.config.has_key?('DOWNLOAD_VERSION') or site.config['DOWNLOAD_VERSIONINT'] < self.data['versionint']
site.config['DOWNLOAD_VERSIONINT'] = self.data['versionint']
site.config['DOWNLOAD_VERSION'] = self.data['required_version']
site.config['DOWNLOAD_MAGNETLINK'] = self.data['optional_magnetlink'] ? self.data['optional_magnetlink'] : nil
end
end
def versiontoint(v)
x = 0
ar = v.split('.').map{|s| s.to_i}
ar.each_index do |k|
x = ar[k] * (1000 ** (5 - k))
end
return x
end
end
class ReleasePageGenerator < Generator
def generate(site)
#Do nothing if plugin is disabled
if !ENV['ENABLED_PLUGINS'].nil? and ENV['ENABLED_PLUGINS'].index('releases').nil?
print 'Releases disabled' "\n"
return
end
#generate each release based on templates
Dir.foreach('_releases') do |file|
next if file == '.' or file == '..'
lang = 'en'
src = file
srcdir = '_releases'
output_directory = lang '/release'
site.pages << ReleasePage.new(site, site.source, lang, '_releases', src, output_directory)
end
#TODO releases are only generated for english language,
#but they could also be translated at some point. They would however
#need to fallback to english when no translation is available.
end
end
end