Skip to content

Commit

Permalink
update Gemfile Rakefile for build book
Browse files Browse the repository at this point in the history
  • Loading branch information
lethee committed Apr 3, 2021
1 parent 9d08623 commit 4137cb3
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 41 deletions.
22 changes: 11 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
source 'https://rubygems.org'

gem 'rake'
gem 'asciidoctor', '1.5.6.1'
gem 'rake', '13.0.3'
gem 'asciidoctor', '2.0.12'

gem 'json'
gem 'awesome_print'
gem 'json', '2.5.1'
gem 'awesome_print', '1.9.2'

gem 'asciidoctor-epub3', :git => 'https://github.com/asciidoctor/asciidoctor-epub3'
gem 'asciidoctor-pdf', '1.5.0.alpha.16'
gem 'asciidoctor-epub3', '1.5.0.alpha.19'
gem 'asciidoctor-pdf', '1.5.4'
gem 'asciidoctor-pdf-cjk', '~> 0.1.3'
gem 'asciidoctor-pdf-cjk-kai_gen_gothic', '~> 0.1.1'

gem 'coderay'
gem 'pygments.rb'
gem 'thread_safe'
gem 'epubcheck'
gem 'kindlegen'
gem 'coderay', '1.1.3'
gem 'pygments.rb', '2.2.0'
gem 'thread_safe', '0.3.6'
gem 'epubcheck-ruby', '4.2.5.0'
gem 'html-proofer', '3.18.8'
32 changes: 28 additions & 4 deletions README.asc
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,46 @@

== 책 생성 방법

직접 e-book을 생성하려면 Asciidoctor를 이용합니다.
다음과 같은 명령을 실행하면 _아마도_ HTML, Epub, Mobi, PDF 버전의 책을 생성할 수 있을 것입니다.
아래의 방법이 아니라도 직접 Asciidoctor 도구를 사용하여 e-book을 만들 수도 있습니다.
예전에 Kindle 형식의 e-book인 .mobi 파일을 만들 수 있었지만 현재는 Kindle 형식의 e-book을 생성하지는 않습니다(https://github.com/progit/progit2/issues/1496[관련 1496 이슈]).
다음과 같은 명령을 실행하여 HTML, Epub, PDF 버전의 책을 생성할 수 있습니다.
`asciidoctor-pdf-cjk-kai_gen_gothic-install` 명령은 PDF에 포함시킬 한국어 글꼴을 다운로드 하는 명령입니다.

----
$ bundle install
$ asciidoctor-pdf-cjk-kai_gen_gothic-install
$ bundle exec rake book:build
Converting to HTML...
-- HTML output at progit.html
Converting to EPub...
-- Epub output at progit.epub
Converting to Mobi (kf8)...
-- Mobi output at progit.mobi
Converting to PDF...
-- PDF output at progit.pdf
----

모든 형식의 e-book을 생성하지 않고 특정 형식(HTML, EPUB, PDF)만을 생성할 수도 있습니다.
다음 명령은 HTML, EPUB, PDF 필요한 내용만을 생성하는 명령입니다:

HTML 형식 e-book을 생성하려면:

----
$ bundle exec rake book:build_html
----

EPUB 형식 e-book을 생성하려면:

----
$ bundle exec rake book:build_epub
----

PDF 형식 e-book을 생성하려면:

----
$ bundle exec rake book:build_pdf
----

현재 한글 PDF 빌드에 대한 문제를 #114 에서 해결하고 있습니다.

== 새로 이슈 만들기

새로 이슈를 만들기 전에 버그 관리 시스템에 비슷한 이슈가 이미 등록되었는지 먼저 확인해보시기 바랍니다.
Expand Down
150 changes: 124 additions & 26 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,138 @@
namespace :book do
desc 'build basic book formats'
task :build do
def exec_or_raise(command)
puts `#{command}`
if (! $?.success?)
raise "'#{command}' failed"
end
end

`cp progit.asc progit.asc.bak`
begin
version_string = ENV['TRAVIS_TAG'] || `git describe --tags`.chomp
if version_string.empty?
version_string = '0'
# Variables referenced for build
version_string = ENV['TRAVIS_TAG'] || `git describe --tags`.chomp
if version_string.empty?
version_string = '0'
end
date_string = Time.now.strftime('%Y-%m-%d')
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}'"
header_hash = `git rev-parse --short HEAD`.strip

# Check contributors list
# This checks commit hash stored in the header of list against current HEAD
def check_contrib
if File.exist?('book/contributors.txt')
current_head_hash = `git rev-parse --short HEAD`.strip
header = `head -n 1 book/contributors.txt`.strip
# Match regex, then coerce resulting array to string by join
header_hash = header.scan(/[a-f0-9]{7,}/).join

if header_hash == current_head_hash
puts "Hash on header of contributors list (#{header_hash}) matches the current HEAD (#{current_head_hash})"
else
puts "Hash on header of contributors list (#{header_hash}) does not match the current HEAD (#{current_head_hash}), refreshing"
`rm book/contributors.txt`
# Reenable and invoke task again
Rake::Task['book/contributors.txt'].reenable
Rake::Task['book/contributors.txt'].invoke
end
text = File.read('progit.asc')
new_contents = text.gsub("$$VERSION$$", version_string).gsub("$$DATE$$", Time.now.strftime("%Y-%m-%d"))
File.open("progit.asc", "w") {|file| file.puts new_contents }
end
end

desc 'build basic book formats'
task :build => [:build_html, :build_epub, :build_pdf] do
begin
# Run check
Rake::Task['book:check'].invoke

# Rescue to ignore checking errors
rescue => e
puts e.message
puts 'Error when checking books (ignored)'
end
end

desc 'build basic book formats (for ci)'
task :ci => [:build_html, :build_epub, :build_pdf] do
# Run check, but don't ignore any errors
Rake::Task['book:check'].invoke
end

desc 'generate contributors list'
file 'book/contributors.txt' do
puts 'Generating contributors list'
`echo "Contributors as of #{header_hash}:\n" > book/contributors.txt`
`git shortlog -s | grep -v -E "(Straub|Chacon|dependabot)" | cut -f 2- | column -c 120 >> book/contributors.txt`
end

desc 'build HTML format'
task :build_html => 'book/contributors.txt' do
check_contrib()

puts 'Converting to HTML...'
`bundle exec asciidoctor #{params} -a data-uri progit.asc`
puts ' -- HTML output at progit.html'

end

desc 'build Epub format'
task :build_epub => 'book/contributors.txt' do
check_contrib()

puts 'Converting to EPub...'
`bundle exec asciidoctor-epub3 #{params} progit.asc`
puts ' -- Epub output at progit.epub'

end

puts "Generating contributors list"
`git shortlog -s | grep -v -E "(Straub|Chacon)" | cut -f 2- | column -c 120 > book/contributors.txt`
desc 'build Mobi format'
task :build_mobi => 'book/contributors.txt' do
# Commented out the .mobi file creation because the kindlegen dependency is not available.
# For more information on this see: #1496.
# This is a (hopefully) temporary fix until upstream asciidoctor-epub3 is fixed and we can offer .mobi files again.

puts "Converting to HTML..."
`bundle exec asciidoctor progit.asc`
puts " -- HTML output at progit.html"
# puts "Converting to Mobi (kf8)..."
# `bundle exec asciidoctor-epub3 #{params} -a ebook-format=kf8 progit.asc`
# puts " -- Mobi output at progit.mobi"

puts "Converting to EPub..."
`bundle exec asciidoctor-epub3 progit.asc`
puts " -- Epub output at progit.epub"
# FIXME: If asciidoctor-epub3 supports Mobi again, uncomment these lines below
puts "Converting to Mobi isn't supported yet."
puts "For more information see issue #1496 at https://github.com/progit/progit2/issues/1496."
exit(127)
end

desc 'build PDF format'
task :build_pdf => 'book/contributors.txt' do
check_contrib()

puts "Converting to Mobi (kf8)..."
`bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc`
puts " -- Mobi output at progit.mobi"
puts 'Converting to PDF... (this one takes a while)'
`bundle exec asciidoctor-pdf #{params} -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicKR progit.asc `
puts ' -- PDF output at progit.pdf'
end

puts "Converting to PDF... (this one takes a while)"
`bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicKR progit.asc 2>/dev/null`
puts " -- PDF output at progit.pdf"
desc 'Check generated books'
task :check => [:build_html, :build_epub] do
puts 'Checking generated books'

exec_or_raise('htmlproofer --check-html progit.html')
exec_or_raise('epubcheck progit.epub')
end

ensure
`mv progit.asc.bak progit.asc`
desc 'Clean all generated files'
task :clean do
begin
puts 'Removing generated files'

FileList['book/contributors.txt', 'progit.html', 'progit.epub', 'progit.pdf'].each do |file|
rm file

# Rescue if file not found
rescue Errno::ENOENT => e
begin
puts e.message
puts 'Error removing files (ignored)'
end
end
end
end

end

task :default => "book:build"

0 comments on commit 4137cb3

Please sign in to comment.