Created
April 10, 2014 13:57
-
-
Save notjosh/10385144 to your computer and use it in GitHub Desktop.
Crude lolcommits HTML generator
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| require 'fileutils' | |
| $PROJECT = Dir.pwd.split(File::SEPARATOR)[-1] | |
| $HOME = "#{Dir.home}/.lolcommits/#{$PROJECT}" | |
| $OUT_PATH = "#{Dir.pwd}/lolcommits" | |
| map = `git log --pretty=format:"%H %ad" --date=iso | tail -r | sed 's/ [\+\-][0-9][0-9][0-9][0-9]$//' | sed 's/[:\-]//g' | awk '{print substr ($1, 0, 11), $2"-"$3}'`.split("\n") | |
| FileUtils.mkdir_p($OUT_PATH) | |
| def templatify(images) | |
| tpl = " | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>lolcommits</title> | |
| <style type='text/css'> | |
| * { text-align: center; margin: 0; padding: 0; } | |
| </style> | |
| </head> | |
| <body> | |
| ##images## | |
| </body> | |
| </html> | |
| " | |
| images.map! do | image | | |
| "<img src='#{image}' alt='#{image}' />" | |
| end | |
| images_tpl = images.join("\n") | |
| tpl.sub(/##images##/, images_tpl) | |
| end | |
| valid_images = [] | |
| map.each do | line | | |
| hash, stamp = line.split(" ") | |
| src = "#{$HOME}/#{hash}.gif" | |
| dest = "#{$OUT_PATH}/#{stamp}-#{hash}.gif" | |
| begin | |
| FileUtils.cp(src, dest) | |
| valid_images.push(File.basename(dest)) | |
| rescue | |
| end | |
| end | |
| template = templatify(valid_images) | |
| File.open("#{$OUT_PATH}/index.htm", 'w') {|f| f.write(template) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment