diff --git a/.gitignore b/.gitignore index 28d092a..0e5678c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .bundle +node_modules public/feed.xml www diff --git a/.tm_properties b/.tm_properties index 48a6a61..041aff2 100644 --- a/.tm_properties +++ b/.tm_properties @@ -1 +1 @@ -exclude = "{$exclude,www}" +exclude = "{$exclude,www,node_modules}" diff --git a/Makefile b/Makefile index 04ea19d..9b37679 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,9 @@ all: compile -compile: rss +compile: @echo ./bin/compile.sh -rss: - @echo - ./bin/rss.rb public - publish: compile @echo ./bin/publish.sh www/.htaccess diff --git a/bin/compile.sh b/bin/compile.sh index 5698aea..194991f 100755 --- a/bin/compile.sh +++ b/bin/compile.sh @@ -3,13 +3,53 @@ # bail on errors set -e -bin/rss.rb public -harp compile . www +DIR=$(dirname "$0") +HARP="$DIR/../node_modules/.bin/harp" +TARGET="${1:-www}" -for FILENAME in www/*.html www/posts/*.html www/projects/*.html; do - [[ "${FILENAME##*/}" = "index.html" ]] && continue +function main() { + echo "* compile rss feed" + compile_rss - DIRNAME="${FILENAME%.html}" - mkdir -p "$DIRNAME" - mv "$FILENAME" "$DIRNAME/index.html" -done + echo "* harp compile . $TARGET" + rm -rf "$TARGET" + "$HARP" compile . "$TARGET" + + echo "* mungle html to make it available without the extension" + munge_html + + echo "* minify js" + minify_js + + echo "* minify css" + minify_css +} + +function compile_rss() { + $DIR/rss.rb public +} + +function munge_html() { + for FILE in "$TARGET"/*.html "$TARGET"/posts/*.html "$TARGET"/projects/*.html; do + [[ "${FILE##*/}" = "index.html" ]] && continue + + # make posts available without an .html extension + FILE_DIR="${FILE%.html}" + mkdir -p "$FILE_DIR" + mv "$FILE" "$FILE_DIR/index.html" + done +} + +function minify_js() { + for FILE in "$TARGET"/js/*.js; do + $DIR/minify-js.sh "$FILE" > /tmp/minified.js && mv /tmp/minified.js "$FILE" || echo "* failed to minify $FILE" + done +} + +function minify_css() { + for FILE in "$TARGET"/css/*.css; do + $DIR/minify-css.sh "$FILE" > /tmp/minified.css && mv /tmp/minified.css "$FILE" || echo "* failed to minify $FILE" + done +} + +main diff --git a/bin/minify-css.sh b/bin/minify-css.sh new file mode 100755 index 0000000..df644f5 --- /dev/null +++ b/bin/minify-css.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +DIR=$(dirname "$0") +JAR_FILENAME="$DIR/yuicompressor-2.4.8.jar" + +function minify() { + INPUT="$1" + java -jar "$JAR_FILENAME" "$INPUT" +} + +if [[ "$1" != "" ]]; then + minify "$1" +else + echo "usage: $0 [input file]" + exit 1 +fi diff --git a/bin/minify-js.sh b/bin/minify-js.sh new file mode 100755 index 0000000..496a086 --- /dev/null +++ b/bin/minify-js.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +DIR=$(dirname "$0") +UGLIFY="$DIR/../node_modules/.bin/uglifyjs" + +function minify() { + INPUT="$1" + "$UGLIFY" --compress --screw-ie8 "$INPUT" +} + +if [[ "$1" != "" ]]; then + minify "$1" +else + echo "usage: $0 [input file]" + exit 1 +fi diff --git a/bin/yuicompressor-2.4.8.jar b/bin/yuicompressor-2.4.8.jar new file mode 100644 index 0000000..a1cf0a0 Binary files /dev/null and b/bin/yuicompressor-2.4.8.jar differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..2751064 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ "name": "samhuri.net", + "description": "samhuri.net", + "version": "0.0.1", + "dependencies": { + "harp": "0.11.x", + "uglify-js": "2.4.x" + } +}