Created
August 9, 2014 13:47
-
-
Save pathawks/4b2b1e6525021c9d774a to your computer and use it in GitHub Desktop.
Sync current CDNjs libraries to a YAML file in Jekyll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'net/https' | |
require 'uri' | |
require 'json' | |
require 'yaml/store' | |
require 'jekyll' | |
desc "Update CDNjs Libraries" | |
task :updatecdnjs do | |
site = Jekyll.configuration({}) | |
cdnjsFile = site['source'] + '/' + site['data_source'] + '/cdnjs.yml' | |
puts 'Fetching current CDNjs libraries...' | |
cdnjs_current = Net::HTTP.get(URI.parse('http://cdnjs.com/packages.min.json')) | |
cdnjs = JSON.parse(cdnjs_current) | |
File.delete(cdnjsFile) if File.exist?(cdnjsFile) | |
cdnjsYaml = YAML::Store.new(cdnjsFile) | |
cdnjsYaml.transaction do | |
cdnjs['packages'].each do |package| | |
cdnjsYaml[package['name'].to_s] = '//cdnjs.cloudflare.com/ajax/libs/'+ package['name'].to_s + '/' + package['version'].to_s + '/' + package['filename'].to_s | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment