diff --git a/Makefile b/Makefile index ef8ad47..15fb1d2 100644 --- a/Makefile +++ b/Makefile @@ -2,17 +2,19 @@ all: blog blog: sitegen @echo - ./bin/compile . www + rm -rf www + ./bin/sitegen . www publish: blog @echo - ./bin/publish --delete + ./bin/publish --delete www/ publish_beta: @echo ./bin/build-sitegen - ./bin/compile . www "https://beta.samhuri.net" - ./bin/publish --beta --delete + rm -rf www + ./bin/sitegen . www "https://beta.samhuri.net" + ./bin/publish --beta --delete www/ sitegen: @echo diff --git a/Readme.md b/Readme.md index ccbf6bd..551561d 100644 --- a/Readme.md +++ b/Readme.md @@ -105,11 +105,11 @@ Execution, trying TDD for the first time: - [x] Munge HTML files to make them available without an extension (index.html hack, do it in the SiteGenerator) - - [ ] Use perf tools on beta.samhuri.net and compare to samhuri.net to see if inlining css and minifying JS is actually worthwhile + - [x] Use perf tools on beta.samhuri.net and compare to samhuri.net to see if inlining css and minifying JS is actually worthwhile - - [ ] Inline CSS? + - [x] Inline CSS? Nope - - [ ] Minify JS? Now that we're keeping node, why not ... + - [x] Minify JS? Now that we're keeping node, why not ... Nope! Ditched node too - [ ] Add a server for local use and simple production setups (or use a file watcher + `python -m SimpleHTTPServer`?) diff --git a/bin/compile b/bin/compile deleted file mode 100755 index e0db938..0000000 --- a/bin/compile +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -# bail on errors -set -e - -THIS_DIR=$(dirname "$0") -SOURCE_DIR="$1" -TARGET_DIR="$2" -URL_OVERRIDE="$3" - -function main() { - rm -rf "$TARGET_DIR" - - echo "* generate site from $SOURCE_DIR into $TARGET_DIR" - "$THIS_DIR/sitegen" "$SOURCE_DIR" "$TARGET_DIR" "$URL_OVERRIDE" - - # echo "* inline CSS" - # ruby -w $THIS_DIR/inline-css "$TARGET_DIR" - - # echo "* minify js" - # minify_js -} - -# function minify_js() { -# for FILE in "$TARGET_DIR"/js/*.js; do -# $THIS_DIR/minify-js.sh "$FILE" > /tmp/minified.js && mv /tmp/minified.js "$FILE" || echo "* failed to minify $FILE" -# done -# } - -main diff --git a/bin/inline-css b/bin/inline-css deleted file mode 100755 index 325a19f..0000000 --- a/bin/inline-css +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env ruby -w - -require 'rubygems' -require 'bundler/setup' -require 'nokogiri' -require 'css_parser' - -# Styles are so small, inline them all. - -def main - root_dir = ARGV.shift - CSSInliner.new(root_dir).inline_all_css -end - -class CSSInliner - - def initialize(root_dir) - @root_dir = root_dir - end - - def inline_all_css - Dir[File.join(@root_dir, '**/*.html')].each do |html_path| - next if html_path =~ /\/Chalk\/|\/tweets\// - inline_css(html_path) - end - end - - def inline_css(html_path) - html = File.read(html_path) - doc = Nokogiri::HTML.parse(html) - css_parser = CssParser::Parser.new - - doc.css('link').each do |link| - if link['rel'] == 'stylesheet' - path = File.join(@root_dir, link['href']) - css = File.read(path) - css_parser.add_block!(css) - - style_node = Nokogiri::HTML.parse(" - - ").css('style') - - link.replace(style_node) - end - end - - File.write(html_path, doc.to_html) - end - -end - -main if $0 == __FILE__ diff --git a/bin/publish b/bin/publish index d302b9d..b2343e3 100755 --- a/bin/publish +++ b/bin/publish @@ -50,5 +50,4 @@ if [[ $ECHO -eq 1 ]]; then echo "$CMD" fi -cp .git/$(cat .git/HEAD | cut -d' ' -f2) www/version.txt $CMD diff --git a/bin/redirects b/bin/redirects deleted file mode 100755 index b129cd0..0000000 --- a/bin/redirects +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env ruby - -def pad(n) - n = n.to_i - if n < 10 - "0#{n}" - else - "#{n}" - end -end - -Dir.chdir File.join(File.dirname(__FILE__), '../public/posts') - -Dir['*.html.md'].each do |filename| - name = filename.sub('.html.md', '') - date, *rest = name.split('-') - year, month, _ = date.split('.') - slug = rest.join('-') - puts "Redirect 301 /blog/#{name} /posts/#{year}/#{pad(month)}/#{slug}" -end diff --git a/bin/test b/bin/test index 19b3873..96b8707 100755 --- a/bin/test +++ b/bin/test @@ -3,7 +3,7 @@ set -e for site in Tests/test-*; do - bin/compile "$site/in" "$site/actual" + bin/sitegen "$site/in" "$site/actual" diff -bru "$site/expected" "$site/actual" rm -r "$site/actual" done