mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
only wait for compilation unless when necessary
This commit is contained in:
parent
b504f87e3c
commit
732da17859
3 changed files with 41 additions and 10 deletions
|
|
@ -7,6 +7,21 @@ DIR=$(dirname "$0")
|
||||||
HARP="node_modules/harp/bin/harp"
|
HARP="node_modules/harp/bin/harp"
|
||||||
BLOG_DIR="${1:-${DIR}/..}"
|
BLOG_DIR="${1:-${DIR}/..}"
|
||||||
TARGET="${BLOG_DIR%/}/${2:-www}"
|
TARGET="${BLOG_DIR%/}/${2:-www}"
|
||||||
|
LOCK_FILE="$BLOG_DIR/compile.lock"
|
||||||
|
|
||||||
|
if [[ -e "$LOCK_FILE" ]]; then
|
||||||
|
echo "Bailing, another compilation is running"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
function lock {
|
||||||
|
echo $$ >| "$LOCK_FILE"
|
||||||
|
}
|
||||||
|
function delete_lock_file {
|
||||||
|
rm -f "$LOCK_FILE"
|
||||||
|
}
|
||||||
|
trap delete_lock_file SIGHUP SIGINT SIGTERM SIGEXIT
|
||||||
|
lock
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
echo "* compile rss feed"
|
echo "* compile rss feed"
|
||||||
|
|
@ -27,6 +42,8 @@ function main() {
|
||||||
|
|
||||||
echo "* minify js"
|
echo "* minify js"
|
||||||
minify_js
|
minify_js
|
||||||
|
|
||||||
|
delete_lock_file
|
||||||
}
|
}
|
||||||
|
|
||||||
function compile_rss() {
|
function compile_rss() {
|
||||||
|
|
|
||||||
|
|
@ -160,15 +160,17 @@ class HarpBlog
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile
|
def compile
|
||||||
run('make compile')
|
success, output = run('make compile')
|
||||||
@mutated = false
|
if success
|
||||||
|
@mutated = false
|
||||||
|
else
|
||||||
|
puts output
|
||||||
|
end
|
||||||
|
success
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile_if_mutated
|
def compile_if_mutated
|
||||||
if @mutated
|
compile if @mutated
|
||||||
compile
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,14 +83,24 @@ before do
|
||||||
else
|
else
|
||||||
params
|
params
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
@fields = {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
start = Time.now
|
@wait_for_compilation ||= @fields['wait']
|
||||||
if blog.compile_if_mutated
|
compile = -> {
|
||||||
duration = Time.now.to_f - start.to_f
|
start = Time.now
|
||||||
puts "Compiled blog in #{duration.round}ms"
|
if blog.compile_if_mutated
|
||||||
|
duration = Time.now.to_f - start.to_f
|
||||||
|
puts "Compiled blog in #{duration.round(2)}s"
|
||||||
|
end
|
||||||
|
}
|
||||||
|
if @wait_for_compilation
|
||||||
|
compile.call
|
||||||
|
else
|
||||||
|
Thread.new &compile
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -275,6 +285,7 @@ post '/posts/drafts/:id/publish' do |id|
|
||||||
|
|
||||||
if post = blog.get_draft(id)
|
if post = blog.get_draft(id)
|
||||||
new_post = blog.publish_post(post)
|
new_post = blog.publish_post(post)
|
||||||
|
@wait_for_compilation = true
|
||||||
status 201
|
status 201
|
||||||
headers 'Location' => url_for(new_post.url), 'Content-Type' => 'application/json'
|
headers 'Location' => url_for(new_post.url), 'Content-Type' => 'application/json'
|
||||||
JSON.generate(post: new_post.fields)
|
JSON.generate(post: new_post.fields)
|
||||||
|
|
@ -391,6 +402,7 @@ post '/posts/:year/:month/:id/unpublish' do |year, month, id|
|
||||||
|
|
||||||
if post = blog.get_post(year, month, id)
|
if post = blog.get_post(year, month, id)
|
||||||
new_post = blog.unpublish_post(post)
|
new_post = blog.unpublish_post(post)
|
||||||
|
@wait_for_compilation = true
|
||||||
status 200
|
status 200
|
||||||
headers 'Location' => url_for(new_post.url), 'Content-Type' => 'application/json'
|
headers 'Location' => url_for(new_post.url), 'Content-Type' => 'application/json'
|
||||||
JSON.generate(post: new_post.fields)
|
JSON.generate(post: new_post.fields)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue