Skip to content

Automatically convert markdown resume to pdf #3

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: blog
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ validation-report.json

# Folders to ignore
node_modules

tmp
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ gem "jekyll"
gem "jekyll-gist"
gem "jekyll-paginate"
gem "jekyll-seo-tag"

gem 'rake'
gem 'docker-api'
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
colorator (1.1.0)
concurrent-ruby (1.1.6)
docker-api (2.0.0)
excon (>= 0.47.0)
multi_json
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
eventmachine (1.2.7)
excon (0.76.0)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
ffi (1.13.1)
Expand Down Expand Up @@ -49,13 +53,15 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.4.0)
multi_json (1.15.0)
multipart-post (2.1.1)
octokit (4.18.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (4.0.5)
rake (13.0.1)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
Expand All @@ -75,10 +81,12 @@ PLATFORMS
ruby

DEPENDENCIES
docker-api
jekyll
jekyll-gist
jekyll-paginate
jekyll-seo-tag
rake

BUNDLED WITH
2.1.4
78 changes: 78 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
require 'rake'
require 'docker'

MARKDOWN_RESUME_IMAGE_NAME = 'there4/markdown-resume'
RESUME_TYPES = %w[
pdf
html
]

namespace :resume do
task :clean do |_t, args|
dirs = [
'tmp',
'assets/resumes'
]

dirs.each do |dir|
dir_name = File.join(Dir.pwd, dir)
unless File.directory?(dir_name)
FileUtils.mkdir_p(dir_name)
end
end
end

# remove jekyll related content and write to tmp/ dir
task :write_temp_resume do |_t, args|
f = File.read('resume.md')
resume = f.partition("<!-- JEKYLL-REMOVE-END -->").last

File.write('tmp/resume.md', resume)
end

task :pull_image do |_t, args|
puts "Pulling image, #{MARKDOWN_RESUME_IMAGE_NAME} ..."
Docker::Image.create(
'fromImage' => MARKDOWN_RESUME_IMAGE_NAME,
)
end

desc 'Build resume from markdown. Example - rake resume:build[html]'
task :build, [:type] => [:clean, :write_temp_resume, :pull_image] do |_t, args|
type = args[:type] || 'pdf'

unless RESUME_TYPES.include?(type)
raise "#{type} is not a supported resume type, try one of these: #{RESUME_TYPES.join(',')}"
end

puts "Building resume from markdown file ..."
container = Docker::Container.create(
'Cmd' => [
'md2resume',
type,
'tmp/resume.md',
'assets/resumes/'
],
'Image' => MARKDOWN_RESUME_IMAGE_NAME,
'Volumes' => {
Dir.pwd => { '/resume' => 'rw' },
},
'HostConfig' => {
'Binds' => ["#{Dir.pwd}:/resume"],
},
)

container.start
result = container.wait['StatusCode']

if !result.zero?
raise "Got bad status code when building resume: #{result}"
end

puts "Deleting container ..."
container.delete(:force => true)

puts "Done. You can find your #{type} resume in /assets/resumes"
end
end

Binary file added assets/resumes/resume.pdf
Binary file not shown.