mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-03-25 09:05:47 +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
|
||||
node_modules
|
||||
public/feed.xml
|
||||
www
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
exclude = "{$exclude,www}"
|
||||
exclude = "{$exclude,www,node_modules}"
|
||||
|
|
|
|||
6
Makefile
6
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
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