Created
April 27, 2015 04:42
-
-
Save rickpeyton/e6f58c3169d76a7263d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# * * * * * cd /home/rick/public/dev1.rickpeyton.com/public/ && /home/rick/.rvm/wrappers/ruby-2.1.1/ruby generate.rb > /home/rick/public/dev1.rickpeyton.com/log/cron.log | |
require 'redcarpet/compat' | |
require 'yaml' | |
require 'date' | |
def yaml_load filename | |
yaml_string = File.read filename | |
YAML::load yaml_string | |
end | |
def get_quote | |
quotes = [ | |
["Self-education is, I firmly believe, the only kind of education there is.", "Isaac Asimov"], | |
["Any fool can know. The point is to understand.", "Albert Einstein"], | |
["Live as if you were to die tomorrow. Learn as if you were to live forever.", "Mahatma Gandhi"], | |
["Tell me and I forget, teach me and I may remember, involve me and I learn.", "Benjamin Franklin"], | |
["[Kids] don't remember what you try to teach them. They remember what you are.", "Jim Henson"], | |
["We are all failures- at least the best of us are.", "J.M. Barrie"], | |
["A perverse person stirs up conflict, and a gossip separates close friends.", "Proverbs 16:28"] | |
] | |
len = quotes.length | |
quote = rand(len) | |
return quotes[quote] | |
end | |
def header (title = "I neglected to enter a title.", description = "I neglected to enter a description", quote = ["Self-education is, I firmly believe, the only kind of education there is.", "Isaac Asimov"], schema = false) | |
schema = true | |
x = <<-LONGHTML | |
<!DOCTYPE html> | |
#{"<!-- Microdata markup added by Google Structured Data Markup Helper. -->" if schema == true} | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<meta http-equiv="Cache-control" content="public"> | |
<title>#{title} by Rick Peyton</title> | |
<meta name="description" content="#{description}"> | |
<!-- Bootstrap --> | |
<link href="//netdna.bootstrapcdn.com/bootswatch/3.1.1/flatly/bootstrap.min.css" rel="stylesheet"> | |
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> | |
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | |
<!--[if lt IE 9]> | |
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> | |
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> | |
<![endif]--> | |
</head> | |
<body> | |
<!-- Google Analytics --> | |
<script> | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | |
ga('create', 'UA-20415963-1', 'rickpeyton.com'); | |
ga('require', 'linkid', 'linkid.js'); | |
ga('require', 'displayfeatures'); | |
ga('send', 'pageview'); | |
</script> | |
<div #{"itemscope itemtype='http://schema.org/Article'" if schema == true} class="container"> | |
<div class="page-header text-center"> | |
<h4><ul class="list-inline text-center"> | |
<li>A site about <a href="/technology">technology</a>, <a href="/ruby">ruby programming</a>, <a href="/food">food</a> & <a href="/other-things">other things</a> I enjoy</li> | |
<li>|</li> | |
<li>by <a href="/about.html">Rick Peyton</a></li> | |
</ul></h4> | |
<h5>#{quote[0]} <small>― #{quote[1]}</small></h5> | |
</div> | |
<div class="row"> | |
<div class="col-md-12 text-center"> | |
<ul class="list-inline text-center"> | |
<li><a href="/">Home</a></li> | |
<li><a href="/about.html">About</a></li> | |
<li><a href="/contactme.html">Contact</a></li> | |
</ul> | |
</div> | |
</div> | |
LONGHTML | |
return x | |
end | |
def post_wrap_up category | |
x = <<-LONGHTML | |
<div class="row"> | |
<div class='col-md-12'> | |
<h4>Did you find this post helpful? Give me a shout on Twitter <a href='https://twitter.com/rickpeyton'>@rickpeyton</a></h4> | |
</div> | |
<div> | |
<div class="row"> | |
<div class="col-md-12"> | |
<p><span class="glyphicon glyphicon-forward"></span> View more articles labeled <a href="/#{category}">#{category}</a></p> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-6"> | |
<br> | |
<div class="media"> | |
<a class="pull-left" href="/about.html"> | |
<img class="media-object" src="/images/rick-thumb.jpg" alt="About Rick Peyton Thumbnail"> | |
</a> | |
<div class="media-body"> | |
<h4 class="media-heading">About Rick Peyton</h4> | |
The quick 411 on me. God, my wife, my son, my family, my golden retriever, technology, ruby programming, the green bay packers -- these are the things I love. <a href="/about.html">~ More about Rick Peyton</a> | |
<br><br> | |
<a href="https://twitter.com/rickpeyton" class="twitter-follow-button" data-show-count="true" data-lang="en">Follow @rickpeyton</a> | |
</div> | |
</div> | |
<br> | |
</div> | |
<div class="col-md-6"> | |
</div> | |
</div> | |
LONGHTML | |
return x | |
end | |
def footer | |
now = DateTime.now | |
year = now.year | |
x = <<-LONGHTML | |
<div class="row"> | |
<div class="col-md-12 text-center"> | |
<hr> | |
<ul class="list-inline text-center"> | |
<li><a href="/">Home</a></li> | |
<li><a href="/about.html">About</a></li> | |
<li><a href="/contactme.html">Contact</a></li> | |
<li>|</li> | |
<li>Copyright © #{year} Rick Peyton</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> | |
<!-- Include all compiled plugins (below), or include individual files as needed --> | |
<script src="/js/bootstrap.min.js"></script> | |
<!-- Twitter Follow Widget --> | |
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> | |
</body> | |
</html> | |
LONGHTML | |
return x | |
end | |
# List post titles on index | |
all_index_posts = [] | |
File.open('index.html', 'w') do |file| | |
file.puts header "All the other Rick Peyton's are just imitating.", "My name is Rick Peyton and this is my site about technology, ruby programming, food & other things I enjoy", get_quote | |
Dir.chdir("./posts") do | |
Dir.glob("*.yml") do |name| | |
contents = yaml_load name | |
all_index_posts.push [contents[:date], contents[:title], contents[:url], contents[:category], contents[:author], contents[:post], contents[:description]] | |
end | |
# all_index_posts = [title, category, url, date] | |
# Sort posts in descending date order | |
all_index_posts = all_index_posts.sort_by{ |x| x[0] }.reverse | |
all_index_posts.each do |post| | |
pdate = post[0] | |
ptitle = post[1] | |
purl = post[2] | |
pcategory = post[3] | |
pauthor = post[4] | |
ppost = post[5] | |
pdescription = post[6] | |
ppost = Markdown.new(ppost).to_html | |
file.puts <<-LONGHTML | |
<div class="row"> | |
<div class="col-md-12"> | |
<h1><a href="/#{pcategory}/#{purl}">#{ptitle}</a></h1> | |
<p>Originally posted #{pdate}<br> | |
by #{pauthor}</p> | |
#{ppost} | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-12"> | |
<hr> | |
</div> | |
</div> | |
LONGHTML | |
end | |
file.puts "The End. (I haven't worked on pagination yet...)" | |
file.puts footer | |
end | |
end | |
# Create category indexes | |
# Go to the posts directory | |
all_category_index_posts = [] | |
Dir.chdir("./posts") do | |
Dir.glob("*.yml") do |name| | |
contents = yaml_load name | |
all_category_index_posts.push [contents[:date], contents[:title], contents[:url], contents[:category], contents[:author], contents[:post]] | |
end | |
end | |
# Create an empty array to hold all of the redirects | |
redirects = [] | |
# Create individual posts | |
Dir.chdir("./posts") do | |
Dir.glob("*.yml") do |name| | |
contents = yaml_load name | |
title = contents[:title] | |
description = contents[:description] | |
url = contents[:url] | |
category = contents[:category] | |
if contents[:redirect] | |
contents[:redirect].each do |old_path| | |
redirects.push "#{old_path} /#{category}/#{url}" | |
end | |
end | |
author = contents[:author] | |
date = contents[:date] | |
post = contents[:post] | |
post = Markdown.new(post).to_html | |
schema = true | |
if Dir.exist?("../#{category}") == false | |
Dir.mkdir("../#{category}") | |
end | |
File.open("../#{category}/#{url}", 'w') do |file| | |
file.puts header title, description, get_quote, schema | |
file.puts <<-LONGHTML | |
<div class="row"> | |
<div class="col-md-12"> | |
<h1 itemprop="name">#{title}</h1> | |
<p>Originally posted <span itemprop="datePublished" content="#{date}">#{date}</span><br> | |
by <span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name"><a href="https://plus.google.com/u/0/+RickPeyton?rel=author">#{author}</a></span></span></p> | |
#{post}<meta itemprop="url" content="https://rickpeyton.com/#{category}/#{url}"> | |
</div> | |
</div> | |
LONGHTML | |
file.puts post_wrap_up category | |
file.puts footer | |
end | |
end | |
end | |
# Loop through all posts and if the category is unque add it to an array | |
categories = [] | |
all_category_index_posts.each do |cat| | |
unless categories.include? cat[3] | |
categories.push cat[3] | |
end | |
end | |
# Take array of categories and do a new file for each | |
# Loop through all posts and write post to page where category is equal to category in array | |
categories.each do |category| | |
File.open("./#{category}/index.html", 'w') do |file| | |
file.puts header "All Posts Labeled #{category.capitalize}", "All Posts Labeled #{category.capitalize}", get_quote | |
file.puts <<-LONGHTML | |
<div class="row"> | |
<div class="col-md-12"><h3>All Posts Labeled #{category.capitalize}</h3></div> | |
</div> | |
LONGHTML | |
all_category_index_posts = all_category_index_posts.sort_by{ |x| x[0] }.reverse | |
all_category_index_posts.each do |post| | |
if post[3] == category | |
pdate = post[0] | |
ptitle = post[1] | |
purl = post[2] | |
pcategory = post[3] | |
pauthor = post[4] | |
ppost = post[5] | |
pdescription = post[6] | |
ppost = Markdown.new(ppost).to_html | |
file.puts <<-LONGHTML | |
<div class="row"> | |
<div class="col-md-12"> | |
<h1><a href="/#{pcategory}/#{purl}">#{ptitle}</a></h1> | |
<p>Originally posted #{pdate}<br> | |
by #{pauthor}</p> | |
#{ppost} | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-12"> | |
<hr> | |
</div> | |
</div> | |
LONGHTML | |
end | |
end | |
file.puts footer | |
end | |
end | |
# Create an about page | |
File.open('about.html', 'w') do |file| | |
now = DateTime.now | |
me = Date.new(1980, 11, 9) | |
married = Date.new(2006, 6, 24) | |
age = (now - me) / 365 | |
anniversary = (now - married) / 365 | |
abe = Date.new(2013, 11, 22) | |
if (now - abe) / 365 < 2 | |
x = (now - abe) / (365 / 12) | |
abe_age = "#{x.to_i} month" | |
else | |
x = (now - abe) / 365 | |
abe_age = "#{x.to_i} year" | |
end | |
file.puts header "About Rick Peyton", "A quick 411 about me, Rick Peyton. God, my wife, my son, my family, my golden retriever, technology, ruby programming, the green bay packers -- these are the things I love.", get_quote | |
file.puts <<-LONGHTML | |
<div class="row"> | |
<div class="col-md-12"> | |
<img class="center-block" src="/images/rick-rebecca-and-abe.jpg"> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-12"> | |
<br> | |
<p>The quick 411 on me. God, my wife, my son, my family, my golden retriever, technology, ruby programming, the green bay packers -- these are the things I love.</p> | |
<p>I am #{age.to_i} years old and have been married to my beautiful wife Rebecca for #{anniversary.to_i} years. We live near Birmingham, Alabama and have a #{abe_age} old son named Abraham, a golden retriever named Hitch and a cat named Starr.</p> | |
<p>I have been working for a manufacturer of Christmas Photo Cards and social stationery since 2006. Officially I am listed as Operations Manager but, as with nearly any family-owned small business, my list of duties includes; web development, email marketer, in-house tech support, SEO and internet marketing project manager, garbage man or whatever else needs to be done.</p> | |
<p>This website is hosted through <a href = "http://www.linode.com/?r=0ed5f7143f8d066a7aef3f8cbb4c420cdb86625c">Linode</a> (2GB plan) and setup with Ubuntu 12.04.4 LTS. I purchased this domain through GoDaddy on December 13, 2010</p> | |
<p>This static HTML website is generated using my own custom <a href="https://www.ruby-lang.org/en/">Ruby</a> script with each post written in <a href="http://daringfireball.net/projects/markdown/">Markdown</a> and regenerated nightly.</p> | |
</div> | |
</div> | |
LONGHTML | |
file.puts footer | |
end | |
# Create a contact page | |
File.open('contactme.html', 'w') do |file| | |
file.puts header "Get in touch with Rick Peyton", "Connect with me on Twitter or send me an email.", get_quote | |
file.puts <<-LONGHTML | |
<div class="row"> | |
<div class="col-md-12"> | |
<img class="center-block" src="/images/rick-rebecca-and-abe.jpg"> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-12 text-center"> | |
<br> | |
<p>Send me a message on <a href="https://twitter.com/rickpeyton">twitter</a> or use the form below.</p> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-4"></div> | |
<div class="col-md-4"> | |
<br> | |
<form role="form" action="/cgi-bin/sendemail.rb"> | |
<div class="form-group"> | |
<label for="InputEmail1">Email address</label> | |
<input type="email" class="form-control" id="InputEmail1" name="InputEmail1" placeholder="Enter email"> | |
</div> | |
<div class="form-group"> | |
<label for="InputName1">Name</label> | |
<input type="text" class="form-control" id="InputName1" name="InputName1" placeholder="Name"> | |
</div> | |
<div class="form-group"> | |
<label for="InputComment1">Comment</label> | |
<textarea class="form-control" rows="3" id="InputComment1" name="InputComment1"></textarea> | |
</div> | |
<button type="submit" class="btn btn-default">Submit</button> | |
</form> | |
</div> | |
<div class="col-md-4"></div> | |
</div> | |
LONGHTML | |
file.puts footer | |
end | |
# Process any 301 redirects | |
File.open(".htaccess", 'w') do |file| | |
file.puts <<-LONGHTML | |
<IfModule mod_expires.c> | |
# Enable expirations | |
ExpiresActive On | |
# Default directive | |
ExpiresDefault "access plus 1 year" | |
# My favicon | |
ExpiresByType image/x-icon "access plus 1 year" | |
# Images | |
ExpiresByType image/gif "access plus 1 year" | |
ExpiresByType image/png "access plus 1 year" | |
ExpiresByType image/jpg "access plus 1 year" | |
ExpiresByType image/jpeg "access plus 1 year" | |
# CSS | |
ExpiresByType text/css "access plus 1 year" | |
# Javascript | |
ExpiresByType application/javascript "access plus 1 year" | |
Header set Cache-Control "max-age=31536000, public" | |
</IfModule> | |
RewriteEngine On | |
RewriteCond %{HTTPS} off [OR] | |
RewriteCond %{HTTP_HOST} !^rickpeyton.com$ [NC] | |
RewriteRule ^ https://rickpeyton.com%{REQUEST_URI} [R=301,L,NE] | |
LONGHTML | |
file.puts "Redirect 301 /googleplus https://plus.google.com/u/0/102108553145967911282" | |
file.puts "Redirect 301 /about /about.html" | |
redirects.each do |redirect| | |
file.puts "Redirect 301 #{redirect}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment