Skip to content

Commit

Permalink
[WIP] Added custom promise pages (#144)
Browse files Browse the repository at this point in the history
* Added custom promise pages

* Fixed some bugs and added loader

* Fixed W3 issues and seperated css and js from html

* Implement #145

* Added title generator

* Fixed empty title bug

* #146 merge conflict fix

* Fixed some bugs, improved markdown

* Better replying and better word-wrapping

* Fix for Travis CI?

* Fix for broken urls

* Removed duplicate that caused bug

* Center chevrons

* Minified JS and used sass

* Delete all promises before re-generating

* gem ⬆️
  • Loading branch information
MrLuit authored and VirenMohindra committed May 4, 2017
1 parent f2a8600 commit 578566c
Show file tree
Hide file tree
Showing 189 changed files with 8,130 additions and 125 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Expand Up @@ -22,6 +22,10 @@ gem 'html-proofer'

gem 'rake'

gem 'unf_ext'

gem 'metainspector'

# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
# gem "github-pages", group: :jekyll_plugins
Expand Down
48 changes: 43 additions & 5 deletions Gemfile.lock
@@ -1,19 +1,34 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (5.0.2)
activesupport (5.1.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.0)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
colorator (1.1.0)
colored (1.2)
concurrent-ruby (1.0.5)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
ethon (0.10.1)
ffi (>= 1.3.0)
faraday (0.12.1)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6)
faraday (>= 0.7.4)
http-cookie (~> 1.0.0)
faraday-encoding (0.0.4)
faraday
faraday-http-cache (2.0.0)
faraday (~> 0.8)
faraday_middleware (0.11.0.1)
faraday (>= 0.7.4, < 1.0)
fastimage (2.1.0)
ffi (1.9.18)
ffi (1.9.18-x86-mingw32)
forwardable-extended (2.6.0)
html-proofer (3.6.0)
activesupport (>= 4.2, < 6.0)
Expand All @@ -24,6 +39,8 @@ GEM
parallel (~> 1.3)
typhoeus (~> 0.7)
yell (~> 2.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (0.8.1)
jekyll (3.3.0)
addressable (~> 2.4)
Expand All @@ -40,7 +57,7 @@ GEM
jekyll (~> 3.3)
jekyll-sass-converter (1.5.0)
sass (~> 3.4)
jekyll-sitemap (1.0.0)
jekyll-sitemap (1.1.1)
jekyll (~> 3.3)
jekyll-watch (1.5.0)
listen (~> 3.0, < 3.1)
Expand All @@ -50,12 +67,26 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
mercenary (0.3.6)
metainspector (5.4.1)
addressable (~> 2.5)
faraday (~> 0.11)
faraday-cookie_jar (~> 0.0)
faraday-encoding (~> 0.0)
faraday-http-cache (~> 2.0)
faraday_middleware (~> 0.11)
fastimage (~> 2.1)
nesty (~> 1.0)
nokogiri (~> 1.7)
mini_portile2 (2.1.0)
minima (2.1.0)
minima (2.1.1)
jekyll (~> 3.3)
minitest (5.10.1)
multipart-post (2.0.0)
nesty (1.0.2)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
nokogiri (1.7.1-x86-mingw32)
mini_portile2 (~> 2.1.0)
parallel (1.11.1)
pathutil (0.14.0)
forwardable-extended (~> 2.6)
Expand All @@ -72,21 +103,28 @@ GEM
ethon (>= 0.8.0)
tzinfo (1.2.3)
thread_safe (~> 0.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
unf_ext (0.0.7.4-x86-mingw32)
yell (2.0.7)

PLATFORMS
ruby
x86-mingw32

DEPENDENCIES
html-proofer
jekyll (= 3.3.0)
jekyll-feed (~> 0.6)
jekyll-sitemap
metainspector
minima (~> 2.0)
rake
unf_ext

RUBY VERSION
ruby 2.2.3p173

BUNDLED WITH
1.13.6
1.14.6
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -33,6 +33,11 @@ We'd love to get contributions from you! For a quick guide to getting your syste
10. Rich data so Google can parse it. Maybe something on http://schema.org/?
11. ~~Add tweet button #47~~

# Also check

- [TrumpTrackerRSS](https://github.com/MrLuit/TrumpTrackerRSS) - A RSS feed of all changes in the database file
- [TrumpTrackerBot](https://github.com/MrLuit/TrumpTrackerBot) - A bot that creates a new Reddit thread for every addition to the database

# Report Issues
1. Pull Request would be the best option.
2. Otherwise you can email me @ {firstName}.{lastName}+trump@gmail.com
209 changes: 167 additions & 42 deletions Rakefile
@@ -1,67 +1,192 @@
# coding: utf-8
require 'jekyll'

# for yaml2json
# 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 bold
"\033[1m#{self}\033[0m"
end
def prettyurl
"#{self}".downcase.strip.gsub('-', '').gsub(' ', '-').gsub(/[^\w-]/, '').gsub('--', '-')[0..100]
end
end

# Rake Jekyll tasks
task :build do
Rake::Task["json2yaml"].invoke
puts 'Building site...'.bold
Jekyll::Commands::Build.process(profile: true)
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({})
puts 'Cleaning up _site...'.bold
Jekyll::Commands::Clean.process({})
end

task :serve do
Rake::Task["json2yaml"].invoke
puts 'Autoregenerating site...'.bold
sh "bundle exec jekyll serve"
Rake::Task["generateurls"].invoke
Rake::Task["generatestatic"].invoke
Rake::Task["yaml2json"].invoke
puts 'Autoregenerating site...'.bold
sh "bundle exec jekyll serve"
end

task :json2yaml do
input_filename = "./_data/data.yaml"
output_filename = input_filename.sub(/(yml|yaml)$/, 'json')

input_file = File.open(input_filename, 'r')
input_yml = input_file.read
input_file.close
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)
Pathname.new("./promises/").children.each { |p| p.unlink }
yaml['promises'].each_with_index {
|x, index|
title = x['title'];
status = x['status'];
comments = x['comments']
category = x['category']
description = x['description']
filename = title.prettyurl
out_file = File.new("./promises/#{filename}.html", "w+")
layout = "---\nlayout: page\npermalink: /:basename/\n---\n"
layout << layout_template
$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 << "<li><a class='src' target='_blank' href='#{y}'>#{srctitle}</a></li>\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.gsub! "<ul class='sources'>", "<ul class='sources'>\n#{$sources}"
layout.gsub! "{{ page.title }}", title
layout.gsub! "{{ page.titleurl }}", titleurl
layout.gsub! "{{ page.url }}", url
layout.gsub! "{{ page.statuscolor }}", statuscolor
layout.gsub! "{{ page.status }}", status
layout.gsub! "{{ page.description }}", description
layout.gsub! "{{ tweettext }}", tweettext
layout.gsub! "{{ page.comments }}", comments
comments.sub! "https://redd.it/", ""
layout.gsub! "{{ page.commentsid }}", comments
layout.gsub! "{{ page.category }}", category
out_file.puts(layout)
out_file.close
}
yaml_file.close
layout_file.close
puts 'Done generating promise pages.'.bold
end

output_json = JSON.dump(YAML::load(input_yml))
output_file = File.open(output_filename, 'w+')
output_file.write(output_json)
output_file.close
puts 'data.json successfully created.'.bold
task :generateurls do
yaml_file = File.open("./_data/data.yaml", 'r');
yaml = yaml_file.read
fullyaml = ''
yaml = yaml.split(" -")
yaml.each_with_index {
|x, index|
if x.include? "title: '"
title = x.split("title: '")[1].split("'\n")[0]
url = "url: 'https://trumptracker.github.io/"
url << title.prettyurl
url << "/'"
oldurl = "url: '"
oldurl << x.split("url: '")[1].split("'\n")[0]
oldurl << "'"
x.sub! oldurl, url
end
fullyaml << x
if index != yaml.size - 1
fullyaml << " -"
end
}
yaml_file.close
output_file = File.open("./_data/data.yaml", 'w+')
output_file.write(fullyaml)
output_file.close
end

task :yaml2json do
puts 'Converting YAML to JSON...'.bold
input_filename = "./_data/data.yaml"
output_filename = input_filename.sub(/(yml|yaml)$/, 'json')
input_file = File.open(input_filename, 'r')
input_yml = input_file.read
input_file.close
output_json = JSON.dump(YAML::load(input_yml))
output_file = File.open(output_filename, 'w+')
output_file.write(output_json)
output_file.close
puts 'data.json successfully created.'.bold
end

task :test do
require 'html-proofer'
sh "rm -rf ./_site"
sh "bundle exec jekyll build"
Rake::Task["json2yaml"].invoke

options = {
:allow_hash_href => true,
:check_favicon => true,
:check_opengraph => true,
:check_html => true,
:check_img_http => true,
:cache => { :timeframe => '15d' },
:enforce_https => true,
:check_external_hash => true,
:url_ignore => [/https:\/\/web.archive.org\/web\//]
}
HTMLProofer.check_directory("./_site", options).run
end
require 'html-proofer'
sh "rm -rf ./_site"
sh "bundle exec jekyll build"
Rake::Task["generateurls"].invoke
Rake::Task["generatestatic"].invoke
Rake::Task["yaml2json"].invoke
options = {
:allow_hash_href => true,
:check_favicon => true,
:check_opengraph => true,
:check_html => true,
:check_img_http => true,
:cache => { :timeframe => '15d' },
:enforce_https => true,
:check_external_hash => true,
:url_ignore => [/https:\/\/web.archive.org\/web\//]
}
HTMLProofer.check_directory("./_site", options).run
end
2 changes: 1 addition & 1 deletion _data/data.json

Large diffs are not rendered by default.

0 comments on commit 578566c

Please sign in to comment.