mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-03-25 09:05:47 +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"
|
||||
BLOG_DIR="${1:-${DIR}/..}"
|
||||
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() {
|
||||
echo "* compile rss feed"
|
||||
|
|
@ -27,6 +42,8 @@ function main() {
|
|||
|
||||
echo "* minify js"
|
||||
minify_js
|
||||
|
||||
delete_lock_file
|
||||
}
|
||||
|
||||
function compile_rss() {
|
||||
|
|
|
|||
|
|
@ -160,15 +160,17 @@ class HarpBlog
|
|||
end
|
||||
|
||||
def compile
|
||||
run('make compile')
|
||||
@mutated = false
|
||||
success, output = run('make compile')
|
||||
if success
|
||||
@mutated = false
|
||||
else
|
||||
puts output
|
||||
end
|
||||
success
|
||||
end
|
||||
|
||||
def compile_if_mutated
|
||||
if @mutated
|
||||
compile
|
||||
true
|
||||
end
|
||||
compile if @mutated
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -83,14 +83,24 @@ before do
|
|||
else
|
||||
params
|
||||
end
|
||||
else
|
||||
@fields = {}
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
start = Time.now
|
||||
if blog.compile_if_mutated
|
||||
duration = Time.now.to_f - start.to_f
|
||||
puts "Compiled blog in #{duration.round}ms"
|
||||
@wait_for_compilation ||= @fields['wait']
|
||||
compile = -> {
|
||||
start = Time.now
|
||||
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
|
||||
|
||||
|
|
@ -275,6 +285,7 @@ post '/posts/drafts/:id/publish' do |id|
|
|||
|
||||
if post = blog.get_draft(id)
|
||||
new_post = blog.publish_post(post)
|
||||
@wait_for_compilation = true
|
||||
status 201
|
||||
headers 'Location' => url_for(new_post.url), 'Content-Type' => 'application/json'
|
||||
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)
|
||||
new_post = blog.unpublish_post(post)
|
||||
@wait_for_compilation = true
|
||||
status 200
|
||||
headers 'Location' => url_for(new_post.url), 'Content-Type' => 'application/json'
|
||||
JSON.generate(post: new_post.fields)
|
||||
|
|
|
|||
Loading…
Reference in a new issue