# coding: utf-8 require 'jekyll' # for yaml2json, generatestatic and generateurls require 'json' require 'yaml' # for parsing source titles #require 'openssl' #require 'open-uri' #require 'metainspector' # Extend string to allow for bold text. class String def bold "\033[1m#{self}\033[0m" end def prettyurl "#{self}".downcase.strip.gsub('-', '').gsub(' ', '-').gsub(/[^\w-]/, '').gsub('--', '-')[0..100] end end def check_file(file, string) File.foreach(file).detect { |line| line.include?(string) } end # Rake Jekyll tasks task :build do Rake::Task["generateurls"].invoke Rake::Task["generatestatic"].invoke Rake::Task["yaml2json"].invoke puts 'Building site...'.bold Jekyll::Commands::Build.process(profile: true) end task :clean do puts 'Cleaning up _site...'.bold Jekyll::Commands::Clean.process({}) end task :serve do Rake::Task["generateurls"].invoke Rake::Task["generatestatic"].invoke Rake::Task["yaml2json"].invoke puts 'Autoregenerating site...'.bold sh "bundle exec jekyll serve" end task :generatestatic do puts 'Generating unique promise pages...'.bold layout_file = File.open("./_layouts/promise.html", 'r') layout_template = layout_file.read yaml_file = File.open("./_data/data.yaml", 'r') yaml = yaml_file.read yaml = YAML::load(yaml) titles = {} yaml['promises'].each_with_index { |x, index| title = x['title'] titles["#{title}"] = true status = x['status'] status_info = x['status_info'] if status_info != '' status_info = "#{status_info}

" end comments = x['comments'][0] commentsarray = x['comments'].to_json.sub! "https://redd.it/", "" category = x['category'] description = x['description'] filename = title.prettyurl out_file = File.new("./promises/#{filename}.html", "w+") sources = '' x['sources'].each { |y| #begin # srctitle = MetaInspector.new(y, faraday_options: { ssl: { verify: false } }).title # if srctitle == '' || srctitle.length < 5 || srctitle.length > 200 # srctitle = y # end #rescue Exception => e # puts e.message srctitle = y #ensure # puts srctitle if srctitle.include? "https://web.archive.org/web/" srctitle = srctitle.gsub "https://web.archive.org/web/", "" srctitle = srctitle.split("/") srctitle.shift() srctitle = srctitle.join("/") end sources << "
  • #{srctitle}
  • \n" #end } tweettext = '@realDonaldTrump ' if status == "Not started" tweettext << "hasn't started" statuscolor = '#31708f' elsif status == "In progress" tweettext << "is progressing" statuscolor = '#8a6d3b' elsif status == "Achieved" tweettext << "achieved" statuscolor = '#5cb85c' elsif status == "Broken" tweettext << "broke" statuscolor = '#d9534f' elsif status == "Compromised" tweettext << "compromised on" statuscolor = '#4e5459' end tweettext << " promise no. #{index}: #{title}" tweettext_short = "#{tweettext}"[0..98] if tweettext.length > 98 tweettext_short << "..." end tweettext = CGI.escape(tweettext_short) url = title.prettyurl titleurl = CGI.escape(title) layout = "" layout << layout_template layout.gsub! "