mirror of
https://github.com/github/choosealicense.com
synced 2025-01-24 12:27:48 +01:00
39 lines
1.1 KiB
Ruby
Executable File
39 lines
1.1 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
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
|
|
spdx_text = data['standardLicenseTemplate'].gsub(/ +\n/, "\n")
|
|
license_text = ''
|
|
|
|
spdx_text.lines.each do |line|
|
|
if line.length <= 78
|
|
license_text += line
|
|
else
|
|
indented_line = line.match(/\A(\s*)(.*)/)
|
|
line_indent = indented_line[1]
|
|
line_text = indented_line[2]
|
|
text_width = 78 - line_indent.length
|
|
license_text += line_text.gsub(/(.{1,#{text_width}})(\s+|\Z)/, "#{line_indent}\\1\n")
|
|
end
|
|
end
|
|
|
|
raw_content = File.read(license.path)
|
|
matches = raw_content.match Jekyll::Document::YAML_FRONT_MATTER_REGEXP
|
|
|
|
output = matches[1]
|
|
output << "---\n\n"
|
|
output << license_text
|
|
|
|
File.write(license.path, output)
|
|
end
|