mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-03-25 09:05:47 +00:00
implement previewing posts & drafts
This commit is contained in:
parent
1dbd243008
commit
e44afbe80d
2 changed files with 21 additions and 10 deletions
|
|
@ -80,16 +80,16 @@ class HarpBlog
|
|||
read_post(File.join(year, month), id)
|
||||
end
|
||||
|
||||
def get_post_html(year, month, id)
|
||||
raise 'unimplemented'
|
||||
end
|
||||
|
||||
def get_draft(id)
|
||||
read_post('drafts', id, draft: true)
|
||||
end
|
||||
|
||||
def get_draft_html(id)
|
||||
raise 'unimplemented'
|
||||
def preview_post(year, month, id)
|
||||
read_rendered_post(File.join(year, month), id)
|
||||
end
|
||||
|
||||
def preview_draft(id)
|
||||
read_rendered_post('drafts', id)
|
||||
end
|
||||
|
||||
def create_post(title, body, url, extra_fields = nil)
|
||||
|
|
@ -191,8 +191,8 @@ class HarpBlog
|
|||
path_for(*args)
|
||||
end
|
||||
|
||||
def drafts_path(*components)
|
||||
post_path('drafts', *components)
|
||||
def rendered_post_path(dir, id)
|
||||
path_for('www/posts', dir, id, 'index.html')
|
||||
end
|
||||
|
||||
def read_posts(post_dir, extra_fields = nil)
|
||||
|
|
@ -235,6 +235,17 @@ class HarpBlog
|
|||
end
|
||||
end
|
||||
|
||||
def read_rendered_post(post_dir, id)
|
||||
post_filename = rendered_post_path(post_dir, id)
|
||||
if File.exists?(post_filename)
|
||||
File.read(post_filename)
|
||||
else
|
||||
message = "missing rendered HTML for post #{post_dir}/#{id} at path #{post_filename}"
|
||||
$stderr.puts "[HarpBlog#read_rendered_post] #{message}"
|
||||
raise InvalidDataError.new(message)
|
||||
end
|
||||
end
|
||||
|
||||
def save_post(action, post)
|
||||
git_fetch
|
||||
git_reset_hard('origin/master')
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ get '/posts/:year/:month/:id' do |year, month, id|
|
|||
elsif request.accept?('text/html')
|
||||
status 200
|
||||
headers 'Content-Type' => 'text/html'
|
||||
blog.get_post_html(year, month, id)
|
||||
blog.preview_post(year, month, id)
|
||||
else
|
||||
status 400
|
||||
"content not available in an acceptable format: #{request.accept.join(', ')}"
|
||||
|
|
@ -202,7 +202,7 @@ get '/drafts/:id' do |id|
|
|||
elsif request.accept?('text/html')
|
||||
status 200
|
||||
headers 'Content-Type' => 'text/html'
|
||||
blog.get_draft_html(id)
|
||||
blog.preview_draft(id)
|
||||
else
|
||||
status 400
|
||||
"content not available in an acceptable format: #{request.accept.join(', ')}"
|
||||
|
|
|
|||
Loading…
Reference in a new issue