Merge pulls #1048 and #1051

- 1048: Conditionally build some pages differently based on environmental variables
- 1051: Backend: cache events and contributor listings
This commit is contained in:
David A. Harding 2015-09-09 07:57:11 -04:00
commit 266ab858e2
No known key found for this signature in database
GPG key ID: 4B29C30FF29EC4B7
12 changed files with 181 additions and 7 deletions

View file

@ -106,9 +106,44 @@ module Jekyll
return
end
# Populate site.corecontributors and site.sitecontributors arrays
site.corecontributors = contributors('bitcoin/bitcoin',site.config['aliases'])
site.sitecontributors = contributors('bitcoin-dot-org/bitcoin.org',site.config['aliases'])
## 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

20
_plugins/env.rb Normal file
View file

@ -0,0 +1,20 @@
# This file is licensed under the MIT License (MIT) available on
# http://opensource.org/licenses/MIT.
## env.rb takes select environmental variables and makes them available
## to the site templates. Currently, only variables starting with
## BITCOINORG_ are exported
module Jekyll
class EnvGenerator < Generator
def generate(site)
## If necessary, initialize env hash table
site.config["env"] = site.config["env"] ? site.config["env"] : {}
## Load matching environmental variables in to array
ENV.keys.grep /^BITCOINORG_/ do |key|
site.config['env'].merge!({ key => ENV[key] })
end
end
end
end

View file

@ -142,9 +142,58 @@ module Jekyll
return
end
# Populate site.conferences and site.meetups arrays
site.conferences = conferences()
site.meetups = meetups()
## 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
# Populate site.meetups with data from Meetup.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.
meetups_cache = '_cache/meetups.marshall'
if File.exists?(meetups_cache)
meetups_cache_age = (Time.now - File.stat(meetups_cache).mtime).to_i
else
meetups_cache_age = Time.now.to_i
end
if meetups_cache_age > 86400
site.meetups = meetups()
File.open(meetups_cache,'w') do |file|
Marshal.dump(site.meetups, file)
end
else
File.open(meetups_cache,'r') do |file|
site.meetups = Marshal.load(file)
end
end
end
end