diff --git a/.gitignore b/.gitignore index a8f0bf6b..4be1ed11 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ ehthumbs.db Thumbs.db .bundle vendor +_cache diff --git a/Makefile b/Makefile index a0bbf648..44c4f758 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ build: | egrep -v 'sha256sums.txt' \ | sort \ | xargs -d '\n' sha256sum > _site/sha256sums.txt - $S git show --oneline > _site/commit.txt + $S git log -1 --format="%H" > _site/commit.txt ## Jekyll annoyingly returns success even when it emits errors and ## exceptions, so we'll grep its output for error strings diff --git a/_plugins/contributors.rb b/_plugins/contributors.rb index b1dffa57..74ea41b4 100644 --- a/_plugins/contributors.rb +++ b/_plugins/contributors.rb @@ -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 diff --git a/_plugins/events.rb b/_plugins/events.rb index b9394313..a3e1b191 100644 --- a/_plugins/events.rb +++ b/_plugins/events.rb @@ -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