Skip to content

Instantly share code, notes, and snippets.

@pathawks
Created August 9, 2014 13:47
Show Gist options
  • Save pathawks/4b2b1e6525021c9d774a to your computer and use it in GitHub Desktop.
Save pathawks/4b2b1e6525021c9d774a to your computer and use it in GitHub Desktop.
Sync current CDNjs libraries to a YAML file in Jekyll
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