lib/bhook/md_file.rb in bhook-0.1.3 vs lib/bhook/md_file.rb in bhook-0.1.4

- old
+ new

@@ -9,39 +9,49 @@ AFTER_H1_TEMPLATE = T.let(File.read(Bhook::AFTER_H1_TEMPLATE_PATH), String) sig { returns(Pathname) } attr_reader :src_file_path - sig { params(src_file_path: Pathname, out_path: Pathname, git: Git::Base).void } - def initialize(src_file_path, out_path, git) + sig { params(src_file_path: Pathname, out_path: Pathname, git: Git::Base, config: Bhook::Config).void } + def initialize(src_file_path, out_path, git, config) L.debug "Reading: #{src_file_path}" @md = T.let(File.read(src_file_path), String) @src_file_path = src_file_path @out_path = out_path - src_file_date, src_file_sha = git.lib.send(:command, 'log', - '-n 1', - '--pretty=format:%ad|%h', - '--date=short', - '--', - @src_file_path).split('|') + @git = git + @config = config + src_file_date, src_file_sha = load_git_file_metadata @src_file_date = T.let(src_file_date, T.nilable(String)) @src_file_sha = T.let(src_file_sha, T.nilable(String)) end sig { params(theme: Bhook::Theme).void } def write!(theme) out_file_name = @src_file_path.basename.sub(/\.md$/, '.html') out_file_path = @out_path.join(out_file_name) + file_url = @config.website_url_for(@src_file_path, @src_file_sha) L.debug "Processing: #{@src_file_sha || 'unversioned'} #{@src_file_path}" - rendered_page = theme.render_page(@md, @src_file_sha, @src_file_date) + rendered_page = theme.render_page(@md, @src_file_sha, @src_file_date, file_url) L.debug "Writing: #{@src_file_sha} #{out_file_path}" File.write(out_file_path, rendered_page) end sig { returns(String) } def to_s @src_file_path.to_s + end + + private + + sig { returns(T::Array[String]) } + def load_git_file_metadata + @git.lib.send(:command, 'log', + '-n 1', + '--pretty=format:%ad|%H', + '--date=short', + '--', + @src_file_path).split('|') end end end