mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
minify JS and CSS after compilation
This commit is contained in:
parent
b0740405b1
commit
8507482d4d
8 changed files with 91 additions and 14 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
||||||
.bundle
|
.bundle
|
||||||
|
node_modules
|
||||||
public/feed.xml
|
public/feed.xml
|
||||||
www
|
www
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
exclude = "{$exclude,www}"
|
exclude = "{$exclude,www,node_modules}"
|
||||||
|
|
|
||||||
6
Makefile
6
Makefile
|
|
@ -1,13 +1,9 @@
|
||||||
all: compile
|
all: compile
|
||||||
|
|
||||||
compile: rss
|
compile:
|
||||||
@echo
|
@echo
|
||||||
./bin/compile.sh
|
./bin/compile.sh
|
||||||
|
|
||||||
rss:
|
|
||||||
@echo
|
|
||||||
./bin/rss.rb public
|
|
||||||
|
|
||||||
publish: compile
|
publish: compile
|
||||||
@echo
|
@echo
|
||||||
./bin/publish.sh www/.htaccess
|
./bin/publish.sh www/.htaccess
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,53 @@
|
||||||
# bail on errors
|
# bail on errors
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
bin/rss.rb public
|
DIR=$(dirname "$0")
|
||||||
harp compile . www
|
HARP="$DIR/../node_modules/.bin/harp"
|
||||||
|
TARGET="${1:-www}"
|
||||||
|
|
||||||
for FILENAME in www/*.html www/posts/*.html www/projects/*.html; do
|
function main() {
|
||||||
[[ "${FILENAME##*/}" = "index.html" ]] && continue
|
echo "* compile rss feed"
|
||||||
|
compile_rss
|
||||||
|
|
||||||
DIRNAME="${FILENAME%.html}"
|
echo "* harp compile . $TARGET"
|
||||||
mkdir -p "$DIRNAME"
|
rm -rf "$TARGET"
|
||||||
mv "$FILENAME" "$DIRNAME/index.html"
|
"$HARP" compile . "$TARGET"
|
||||||
done
|
|
||||||
|
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
|
||||||
|
|
|
||||||
16
bin/minify-css.sh
Executable file
16
bin/minify-css.sh
Executable file
|
|
@ -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
|
||||||
16
bin/minify-js.sh
Executable file
16
bin/minify-js.sh
Executable file
|
|
@ -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
|
||||||
BIN
bin/yuicompressor-2.4.8.jar
Normal file
BIN
bin/yuicompressor-2.4.8.jar
Normal file
Binary file not shown.
8
package.json
Normal file
8
package.json
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{ "name": "samhuri.net",
|
||||||
|
"description": "samhuri.net",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"dependencies": {
|
||||||
|
"harp": "0.11.x",
|
||||||
|
"uglify-js": "2.4.x"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue