mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
tighten up params to HarpBlog#post_path
This commit is contained in:
parent
9239d4110d
commit
1dbd243008
1 changed files with 7 additions and 5 deletions
|
|
@ -55,7 +55,7 @@ class HarpBlog
|
||||||
def months
|
def months
|
||||||
years.map do |year|
|
years.map do |year|
|
||||||
# hack: month dirs (and only month dirs) are always 2 characters in length
|
# hack: month dirs (and only month dirs) are always 2 characters in length
|
||||||
Dir[post_path(year, '??')].map { |x| [year, File.basename(x)] }
|
Dir[post_path("#{year}/??")].map { |x| [year, File.basename(x)] }
|
||||||
end.flatten(1).sort
|
end.flatten(1).sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -185,8 +185,10 @@ class HarpBlog
|
||||||
File.join(@path, *components)
|
File.join(@path, *components)
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_path(*components)
|
def post_path(dir, id = nil)
|
||||||
path_for('public/posts', *components)
|
args = ['public/posts', dir]
|
||||||
|
args << "#{id}.md" if id
|
||||||
|
path_for(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def drafts_path(*components)
|
def drafts_path(*components)
|
||||||
|
|
@ -203,14 +205,14 @@ class HarpBlog
|
||||||
unless extra_fields[:draft]
|
unless extra_fields[:draft]
|
||||||
fields[:slug] = id
|
fields[:slug] = id
|
||||||
end
|
end
|
||||||
post_filename = post_path(post_dir, "#{id}.md")
|
post_filename = post_path(post_dir, id)
|
||||||
fields[:body] = File.read(post_filename)
|
fields[:body] = File.read(post_filename)
|
||||||
Post.new(fields.merge(extra_fields))
|
Post.new(fields.merge(extra_fields))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_post(post_dir, id, extra_fields = nil)
|
def read_post(post_dir, id, extra_fields = nil)
|
||||||
post_filename = post_path(post_dir, "#{id}.md")
|
post_filename = post_path(post_dir, id)
|
||||||
post_data = read_post_data(post_path(post_dir))
|
post_data = read_post_data(post_path(post_dir))
|
||||||
if File.exist?(post_filename) && fields = post_data[id]
|
if File.exist?(post_filename) && fields = post_data[id]
|
||||||
fields[:body] = File.read(post_filename)
|
fields[:body] = File.read(post_filename)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue