1
0
mirror of https://github.com/github/choosealicense.com synced 2024-12-22 12:50:24 +01:00

add script to vendor licenses from SPDX api

This commit is contained in:
Ben Balter 2017-03-05 17:40:46 -05:00
parent 6c36a601a0
commit 2dc5291498
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4

22
script/vendor-license-text Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env ruby
require 'jekyll'
require 'open-uri'
site_path = File.expand_path("../", File.dirname(__FILE__))
config = Jekyll.configuration("source" => site_path)
site = Jekyll::Site.new(config)
site.read
site.collections['licenses'].docs.each do |license|
puts "Updating the #{license.data["title"]}..."
uri = "https://spdx.org/licenses/#{license.data["spdx-id"]}.json"
data = JSON.parse open(uri).read
raw_content = File.read(license.path)
matches = raw_content.match Jekyll::Document::YAML_FRONT_MATTER_REGEXP
output = matches[1]
output << "---\n\n"
output << data["standardLicenseTemplate"].gsub(/ +\n/, "\n")
File.write(license.path, output)
end