mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 01:36:13 +00:00
Disable unnecessary plugins (alerts, contrib, events, wallets)
- Remove related files to ensure successful build
This commit is contained in:
parent
5c22586e02
commit
89da1af838
8 changed files with 0 additions and 613 deletions
|
@ -1,87 +0,0 @@
|
|||
# This file is licensed under the MIT License (MIT) available on
|
||||
# http://opensource.org/licenses/MIT.
|
||||
|
||||
#alerts.rb generates alert pages using files in _alerts
|
||||
#and assign them the 'alert' category.
|
||||
|
||||
#This is later used to loop through site.pages in order
|
||||
#to display the alert's list in chronological order, both
|
||||
#on the "Alerts" page and RSS file.
|
||||
|
||||
#If "banner" variable is set in one alert file, site.ALERT
|
||||
#variable is set, allowing a clickable alert banner to be
|
||||
#displayed in _layouts/base.html .
|
||||
|
||||
#If "shorturl" variable is set in one alert file, a short alias
|
||||
#file for the alert (like /android.html) is generated for
|
||||
#Bitcoin Core non-clickable alerts.
|
||||
|
||||
require 'yaml'
|
||||
|
||||
module Jekyll
|
||||
|
||||
class AlertPage < Page
|
||||
def initialize(site, base, lang, srcdir, src, dstdir, dst, date)
|
||||
@site = site
|
||||
@base = base
|
||||
@dir = '/'+dstdir
|
||||
@name = dst
|
||||
extension = dst.split('.')[-1]
|
||||
self.process(dst)
|
||||
self.read_yaml(File.join(base, srcdir), src)
|
||||
self.data['lang'] = lang
|
||||
self.data['date'] = date
|
||||
self.data['path'] = srcdir+'/'+src
|
||||
self.data['layout'] = 'alert'
|
||||
if dstdir == ''
|
||||
self.data['canonical'] = '/en/alert/' + src.split('.')[0]
|
||||
else
|
||||
self.data['category'] = 'alert'
|
||||
if self.data.has_key?('banner') and !self.data['banner'].nil? and self.data['banner'].length>0
|
||||
site.config['ALERT']=self.data['banner']
|
||||
site.config['ALERTURL']='/'+dstdir+'/'+dst.gsub('.html','').gsub('.md','')
|
||||
if self.data.has_key?('bannerclass') and !self.data['bannerclass'].nil? and self.data['bannerclass'].length>0
|
||||
site.config['ALERTCLASS'] = self.data['bannerclass']
|
||||
end
|
||||
end
|
||||
if self.data.has_key?('active') and !self.data['active'].nil? and self.data['active'] == true
|
||||
site.config['STATUS'] = 1
|
||||
end
|
||||
if self.data.has_key?('shorturl')
|
||||
site.pages << AlertPage.new(site, base, lang, srcdir, src, '', self.data['shorturl']+'.'+extension, date)
|
||||
site.pages << AlertPage.new(site, base, lang, srcdir, src, '', self.data['shorturl']+'/index.'+extension, date)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class AlertPageGenerator < Generator
|
||||
def generate(site)
|
||||
#Generate each alert based on templates
|
||||
site.config['STATUS'] = 0
|
||||
site.config['ALERTCLASS'] = 'alert'
|
||||
#Do nothing if plugin is disabled
|
||||
if !ENV['ENABLED_PLUGINS'].nil? and ENV['ENABLED_PLUGINS'].index('alerts').nil?
|
||||
print 'Alerts disabled' + "\n"
|
||||
return
|
||||
end
|
||||
Dir.foreach('_alerts') do |file|
|
||||
next if file == '.' or file == '..'
|
||||
lang = 'en'
|
||||
src = file
|
||||
dst = file
|
||||
srcdir = '_alerts'
|
||||
dstdir = lang + '/alert'
|
||||
date = dst.split('-')
|
||||
next if date.length < 4
|
||||
date = date[0] + '-' + date[1] + '-' + date[2]
|
||||
next if !/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.match(date)
|
||||
site.pages << AlertPage.new(site, site.source, lang, '_alerts', src, dstdir, dst, date)
|
||||
end
|
||||
#TODO alerts 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
|
|
@ -1,150 +0,0 @@
|
|||
# This file is licensed under the MIT License (MIT) available on
|
||||
# http://opensource.org/licenses/MIT.
|
||||
|
||||
#contributors.rb fetches Bitcoin Core contributors list and set
|
||||
#site.contributors array. This is later used to display the
|
||||
#list of contributors on the "Development" page.
|
||||
|
||||
require 'open-uri'
|
||||
require 'json'
|
||||
|
||||
module Jekyll
|
||||
|
||||
class CategoryGenerator < Generator
|
||||
|
||||
def contributors(repo, aliases)
|
||||
contributors = []
|
||||
# Call GitHub API with 100 results per page
|
||||
page = 1
|
||||
data = []
|
||||
while page < 10 do
|
||||
begin
|
||||
ar = JSON.parse(open("https://api.github.com/repos/"+repo+"/contributors?page=#{page}&per_page=100","User-Agent"=>"Ruby/#{RUBY_VERSION}").read)
|
||||
# Prevent any error to stop the build process, return an empty array instead
|
||||
rescue
|
||||
print 'GitHub API Call Failed!'
|
||||
break
|
||||
end
|
||||
if !ar.is_a?(Array)
|
||||
print 'GitHub API Call Failed!'
|
||||
return contributors
|
||||
end
|
||||
if ar.length > 100
|
||||
print 'GitHub API exceeding the 100 results limit!'
|
||||
return contributors
|
||||
end
|
||||
# Stop calling GitHub API when no new results are returned
|
||||
break if (ar.length == 0)
|
||||
# Merge contributors into a single array
|
||||
data.push(*ar)
|
||||
page += 1
|
||||
end
|
||||
# Loop in returned results array
|
||||
result = {}
|
||||
for c in data
|
||||
# Skip incomplete / invalid data and set contributor's name
|
||||
next if !c.is_a?(Hash)
|
||||
next if !c.has_key?('contributions') or !c['contributions'].is_a?(Integer) or c['contributions'] > 1000000
|
||||
if c.has_key?('name') and c['name'].is_a?(String) and /^[A-Za-z0-9\-]{1,150}$/.match(c['name'])
|
||||
name = c['name']
|
||||
elsif c.has_key?('login') and c['login'].is_a?(String) and /^[A-Za-z0-9\-]{1,150}$/.match(c['login'])
|
||||
name = c['login']
|
||||
else
|
||||
next
|
||||
end
|
||||
# Replace name by its corresponding alias if defined in _config.yml
|
||||
name = aliases[name] if aliases.has_key?(name)
|
||||
# Assign variables
|
||||
x = {}
|
||||
x['name'] = name
|
||||
x['contributions'] = c['contributions']
|
||||
# Set login when available
|
||||
if c.has_key?('login') and c['login'].is_a?(String) and /^[A-Za-z0-9\-]{1,150}$/.match(c['login'])
|
||||
x['login'] = c['login']
|
||||
end
|
||||
# Add new contributor to the array, or increase contributions if it already exists
|
||||
if result.has_key?(name)
|
||||
result[name]['contributions'] += x['contributions']
|
||||
else
|
||||
result[name] = x
|
||||
end
|
||||
end
|
||||
# Generate final ordered contributors array
|
||||
result.each do |key, value|
|
||||
contributors.push(value)
|
||||
end
|
||||
contributors.sort_by{|c| - c['contributions']}
|
||||
end
|
||||
|
||||
def generate(site)
|
||||
# Set site.contributors global variables for liquid/jekyll
|
||||
if ! site.respond_to?('corecontributors')
|
||||
class << site
|
||||
attr_accessor :corecontributors
|
||||
attr_accessor :sitecontributors
|
||||
alias contrib_site_payload site_payload
|
||||
def site_payload
|
||||
h = contrib_site_payload
|
||||
payload = h["site"]
|
||||
payload["corecontributors"] = self.corecontributors
|
||||
payload["sitecontributors"] = self.sitecontributors
|
||||
h["site"] = payload
|
||||
h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Set site.corecontributors and site.sitecontributors arrays
|
||||
site.corecontributors = {}
|
||||
site.sitecontributors = {}
|
||||
|
||||
#Do nothing if plugin is disabled
|
||||
if !ENV['ENABLED_PLUGINS'].nil? and ENV['ENABLED_PLUGINS'].index('contributors').nil?
|
||||
print 'Contributors disabled' + "\n"
|
||||
return
|
||||
end
|
||||
|
||||
## Create cache directory if it doesn't exist
|
||||
if !File.exists?('_cache')
|
||||
Dir.mkdir('_cache')
|
||||
end
|
||||
|
||||
# Populate site.corecontributors and site.sitecontributors with
|
||||
# data from GitHub.com. Store data in the cache and only
|
||||
# re-retrieve the data if 86,400 seconds (24 hours) passes from
|
||||
# the retrieval date or if the cache file is deleted. For
|
||||
# simplicity, updates on the two cache files are linked, so if one
|
||||
# file has to be updated, they both get updated.
|
||||
corecontributors_cache = '_cache/corecontributors.marshall'
|
||||
sitecontributors_cache = '_cache/sitecontributors.marshall'
|
||||
if File.exists?(corecontributors_cache) && File.exists?(sitecontributors_cache)
|
||||
corecontributors_cache_age = (Time.now - File.stat(corecontributors_cache).mtime).to_i
|
||||
sitecontributors_cache_age = (Time.now - File.stat(sitecontributors_cache).mtime).to_i
|
||||
else
|
||||
corecontributors_cache_age = Time.now.to_i
|
||||
sitecontributors_cache_age = Time.now.to_i
|
||||
end
|
||||
|
||||
if corecontributors_cache_age > 86400 || sitecontributors_cache_age > 86400
|
||||
site.corecontributors = contributors('bitcoin/bitcoin',site.config['aliases'])
|
||||
File.open(corecontributors_cache,'w') do |file|
|
||||
Marshal.dump(site.corecontributors, file)
|
||||
end
|
||||
site.sitecontributors = contributors('bitcoin-dot-org/bitcoin.org',site.config['aliases'])
|
||||
File.open(sitecontributors_cache,'w') do |file|
|
||||
Marshal.dump(site.sitecontributors, file)
|
||||
end
|
||||
else
|
||||
File.open(corecontributors_cache,'r') do |file|
|
||||
site.corecontributors = Marshal.load(file)
|
||||
end
|
||||
File.open(sitecontributors_cache,'r') do |file|
|
||||
site.sitecontributors = Marshal.load(file)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,102 +0,0 @@
|
|||
# This file is licensed under the MIT License (MIT) available on
|
||||
# http://opensource.org/licenses/MIT.
|
||||
|
||||
#events.rb sets the site.conferences array based
|
||||
#on events in _events/
|
||||
#This is later used to populate the events map and display the
|
||||
#list in chronological order, in the RSS file and events pages.
|
||||
|
||||
require 'open-uri'
|
||||
require 'json'
|
||||
require 'date'
|
||||
require 'yaml'
|
||||
require 'cgi'
|
||||
|
||||
module Jekyll
|
||||
|
||||
class EventPageGenerator < Generator
|
||||
|
||||
def conferences
|
||||
conferences = []
|
||||
# Loop in _events.yml
|
||||
YAML.load_file('_events.yml').each do |data|
|
||||
# Skip event if it has started more than five days ago
|
||||
date = data['date'].to_s.split('-')
|
||||
next if Time.new.to_i > (Time.new(date[0].to_i,date[1].to_i,date[2].to_i).to_i + 432000)
|
||||
# Get geolocalisation data from Google Maps
|
||||
if data.has_key?('address')
|
||||
begin
|
||||
geoloc = JSON.parse(open("https://maps.googleapis.com/maps/api/geocode/json?address=" + CGI::escape(data['address'] + ', ' + data['city'] + ', ' + data['country']) + "&sensor=false","User-Agent"=>"Ruby/#{RUBY_VERSION}").read)
|
||||
if geoloc['status'] == 'OK'
|
||||
data['geoloc'] = {'lat' => geoloc['results'][0]['geometry']['location']['lat'].to_s, 'lon' => geoloc['results'][0]['geometry']['location']['lng'].to_s}
|
||||
end
|
||||
rescue
|
||||
print 'Google Maps API Call Failed!'
|
||||
end
|
||||
end
|
||||
# Populate conferences array
|
||||
conferences.push(data)
|
||||
end
|
||||
return conferences
|
||||
end
|
||||
|
||||
def generate(site)
|
||||
# Set site.meetups and site.conferences global variables for liquid/jekyll
|
||||
if ! site.respond_to?('conferences')
|
||||
class << site
|
||||
attr_accessor :meetups, :conferences
|
||||
alias event_site_payload site_payload
|
||||
def site_payload
|
||||
h = event_site_payload
|
||||
payload = h["site"]
|
||||
payload["conferences"] = self.conferences
|
||||
h["site"] = payload
|
||||
h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Set site.conferences array
|
||||
site.conferences = {}
|
||||
|
||||
#Do nothing if plugin is disabled
|
||||
if !ENV['ENABLED_PLUGINS'].nil? and ENV['ENABLED_PLUGINS'].index('events').nil?
|
||||
print 'Events disabled' + "\n"
|
||||
return
|
||||
end
|
||||
|
||||
## Create cache directory if it doesn't exist
|
||||
if !File.exists?('_cache')
|
||||
Dir.mkdir('_cache')
|
||||
end
|
||||
|
||||
## Populate site.conferences with conferences from _events.yml
|
||||
## plus geodata from Google. Store data in the cache and only
|
||||
## re-retrieve the geodata if _events.yml is edited or the cache
|
||||
## file is deleted.
|
||||
conferences_cache = '_cache/conferences.marshall'
|
||||
events_file = '_events.yml'
|
||||
|
||||
events_file_unix_time = File.stat(events_file).mtime.to_i
|
||||
if File.exists?(conferences_cache)
|
||||
conferences_cache_unix_time = File.stat(conferences_cache).mtime.to_i
|
||||
else
|
||||
conferences_cache_unix_time = 0
|
||||
end
|
||||
|
||||
if events_file_unix_time >= conferences_cache_unix_time
|
||||
site.conferences = conferences()
|
||||
File.open(conferences_cache,'w') do |file|
|
||||
Marshal.dump(site.conferences, file)
|
||||
end
|
||||
else
|
||||
File.open(conferences_cache,'r') do |file|
|
||||
site.conferences = Marshal.load(file)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,137 +0,0 @@
|
|||
# This file is licensed under the MIT License (MIT) available on
|
||||
# http://opensource.org/licenses/MIT.
|
||||
|
||||
require 'yaml'
|
||||
|
||||
module Jekyll
|
||||
|
||||
class WalletPage < Page
|
||||
def initialize(site, base, dir, wallet, platform, os, title, lang)
|
||||
@site = site
|
||||
@base = base
|
||||
@dir = dir
|
||||
@name = 'index.html'
|
||||
|
||||
self.process(@name)
|
||||
self.read_yaml(File.join(base, '_layouts'), 'wallet-container.html')
|
||||
self.data['wallet'] = wallet
|
||||
self.data['platform'] = platform
|
||||
self.data['os'] = os
|
||||
self.data['id'] = ['wallets', platform['name'], os['name'], wallet['id']].join('-')
|
||||
self.data['lang'] = lang
|
||||
self.data['title'] = title
|
||||
end
|
||||
end
|
||||
|
||||
class PlatformPage < Page
|
||||
def initialize(site, base, dir, platform, os, title, lang)
|
||||
@site = site
|
||||
@base = base
|
||||
@dir = dir
|
||||
@name = 'index.html'
|
||||
|
||||
self.process(@name)
|
||||
self.read_yaml(File.join(base, '_layouts'), 'wallet-platform.html')
|
||||
self.data['platform'] = platform
|
||||
self.data['os'] = os
|
||||
self.data['id'] = ['wallets', platform['name'], os['name']].join('-')
|
||||
self.data['lang'] = lang
|
||||
self.data['title'] = title
|
||||
end
|
||||
end
|
||||
|
||||
class WalletsPageGenerator < Generator
|
||||
safe true
|
||||
|
||||
def generate(site)
|
||||
# Get the collection of wallets from _wallets
|
||||
walletsCol = site.collections['wallets'];
|
||||
|
||||
# Get the collection of wallets from _wallets
|
||||
platformsCol = site.collections['platforms'];
|
||||
|
||||
# Output dir
|
||||
# TODO: Make this configurable and "translatable"
|
||||
walletsDir = 'wallets'
|
||||
|
||||
# Loading translations.
|
||||
# Copy-paste from _plugins/templates.rb
|
||||
locs = {}
|
||||
enabled = ENV['ENABLED_LANGS'];
|
||||
enabled = enabled.split(' ') if !enabled.nil?
|
||||
Dir.foreach('_translations') do |file|
|
||||
next if file == '.' or file == '..' or file == 'COPYING'
|
||||
lang = file.split('.')[0]
|
||||
# Ignore language if it's disabled
|
||||
if lang != 'en' and !enabled.nil? and !enabled.include?(lang)
|
||||
puts('Lang ' + lang + ' disabled')
|
||||
next
|
||||
end
|
||||
locs[lang] = YAML.load_file("_translations/"+file)[lang]
|
||||
end
|
||||
|
||||
# Getting information about each found wallet
|
||||
locs.each do |lang,value|
|
||||
title = locs[lang]['choose-your-wallet']['title']
|
||||
|
||||
platformsCol.docs.each do |doc|
|
||||
file = doc.path
|
||||
data = YAML.load_file(file)
|
||||
platform = data['platform']
|
||||
os = data['os']
|
||||
if platform['name'] == os['name']
|
||||
dir = File.join(platform['name'])
|
||||
else
|
||||
dir = File.join(platform['name'], os['name'])
|
||||
end
|
||||
|
||||
platformTitle = locs[lang]['choose-your-wallet']['walletcat' + platform['name']]
|
||||
osTitle = locs[lang]['choose-your-wallet']['platform' + os['name']]
|
||||
if osTitle.nil?
|
||||
fullTitle = [platformTitle, title].join(' - ')
|
||||
else
|
||||
fullTitle = [platformTitle, osTitle, title].join(' - ')
|
||||
end
|
||||
site.pages << PlatformPage.new(site, site.source, File.join(lang, walletsDir, dir), platform, os, fullTitle, lang)
|
||||
end
|
||||
|
||||
walletsCol.docs.each do |doc|
|
||||
file = doc.path
|
||||
wallet = YAML.load_file(file)
|
||||
walletPlatforms = wallet['platform']
|
||||
|
||||
# Going through all available combinations of
|
||||
# platforms and OSes
|
||||
walletPlatforms.each do |platform|
|
||||
platform['os'].each do |os|
|
||||
|
||||
# This allows generation only of valid wallet pages
|
||||
if platform['name']
|
||||
if platform['name'] == os['name']
|
||||
dir = File.join(platform['name'], wallet['id'])
|
||||
else
|
||||
dir = File.join(platform['name'], os['name'], wallet['id'])
|
||||
end
|
||||
|
||||
platformTitle = locs[lang]['choose-your-wallet']['walletcat' + platform['name']]
|
||||
osTitle = locs[lang]['choose-your-wallet']['platform' + os['name']]
|
||||
walletTitle = wallet['title']
|
||||
|
||||
if osTitle.nil?
|
||||
fullTitle = [walletTitle, platformTitle, title].join(' - ')
|
||||
else
|
||||
fullTitle = [walletTitle, platformTitle, osTitle, title].join(' - ')
|
||||
end
|
||||
|
||||
site.pages << WalletPage.new(site, site.source, File.join(lang, walletsDir, dir), wallet, platform, os, fullTitle, lang)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue