Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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"]
- ]
- 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"])
- x = <<-LONGHTML
- <!DOCTYPE html>
- <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>
- <div 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
- x = <<-LONGHTML
- <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>
- <!-- Google Analytics -->
- <script type="text/javascript">
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-20415963-1']);
- _gaq.push(['_trackPageview']);
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
- </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
- if Dir.exist?("../#{category}") == false
- Dir.mkdir("../#{category}")
- end
- File.open("../#{category}/#{url}", 'w') do |file|
- file.puts header title, description, get_quote
- file.puts <<-LONGHTML
- <div class="row">
- <div class="col-md-12">
- <h1>#{title}</h1>
- <p>Originally posted #{date}<br>
- by #{author}</p>
- #{post}
- </div>
- </div>
- LONGHTML
- file.puts post_wrap_up
- 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>I plan to add a respectable contact form in the near future.</p>
- <p>But for now just send me a message on <a href="https://twitter.com/rickpeyton">twitter</a> or email me therickpeyton@gmail.com</p>
- </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} !=on
- RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
- 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
Advertisement
Add Comment
Please, Sign In to add comment