Skip to content

Commit 4137cb3

Browse files
committed
update Gemfile Rakefile for build book
1 parent 9d08623 commit 4137cb3

File tree

3 files changed

+163
-41
lines changed

3 files changed

+163
-41
lines changed

Gemfile

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
source 'https://rubygems.org'
22

3-
gem 'rake'
4-
gem 'asciidoctor', '1.5.6.1'
3+
gem 'rake', '13.0.3'
4+
gem 'asciidoctor', '2.0.12'
55

6-
gem 'json'
7-
gem 'awesome_print'
6+
gem 'json', '2.5.1'
7+
gem 'awesome_print', '1.9.2'
88

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

14-
gem 'coderay'
15-
gem 'pygments.rb'
16-
gem 'thread_safe'
17-
gem 'epubcheck'
18-
gem 'kindlegen'
14+
gem 'coderay', '1.1.3'
15+
gem 'pygments.rb', '2.2.0'
16+
gem 'thread_safe', '0.3.6'
17+
gem 'epubcheck-ruby', '4.2.5.0'
18+
gem 'html-proofer', '3.18.8'

README.asc

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,46 @@
1414

1515
== 책 생성 방법
1616

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

2022
----
2123
$ bundle install
24+
$ asciidoctor-pdf-cjk-kai_gen_gothic-install
2225
$ bundle exec rake book:build
2326
Converting to HTML...
2427
-- HTML output at progit.html
2528
Converting to EPub...
2629
-- Epub output at progit.epub
27-
Converting to Mobi (kf8)...
28-
-- Mobi output at progit.mobi
2930
Converting to PDF...
3031
-- PDF output at progit.pdf
3132
----
3233

34+
모든 형식의 e-book을 생성하지 않고 특정 형식(HTML, EPUB, PDF)만을 생성할 수도 있습니다.
35+
다음 명령은 HTML, EPUB, PDF 필요한 내용만을 생성하는 명령입니다:
36+
37+
HTML 형식 e-book을 생성하려면:
38+
39+
----
40+
$ bundle exec rake book:build_html
41+
----
42+
43+
EPUB 형식 e-book을 생성하려면:
44+
45+
----
46+
$ bundle exec rake book:build_epub
47+
----
48+
49+
PDF 형식 e-book을 생성하려면:
50+
51+
----
52+
$ bundle exec rake book:build_pdf
53+
----
54+
55+
현재 한글 PDF 빌드에 대한 문제를 #114 에서 해결하고 있습니다.
56+
3357
== 새로 이슈 만들기
3458

3559
새로 이슈를 만들기 전에 버그 관리 시스템에 비슷한 이슈가 이미 등록되었는지 먼저 확인해보시기 바랍니다.

Rakefile

Lines changed: 124 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,138 @@
11
namespace :book do
2-
desc 'build basic book formats'
3-
task :build do
2+
def exec_or_raise(command)
3+
puts `#{command}`
4+
if (! $?.success?)
5+
raise "'#{command}' failed"
6+
end
7+
end
48

5-
`cp progit.asc progit.asc.bak`
6-
begin
7-
version_string = ENV['TRAVIS_TAG'] || `git describe --tags`.chomp
8-
if version_string.empty?
9-
version_string = '0'
9+
# Variables referenced for build
10+
version_string = ENV['TRAVIS_TAG'] || `git describe --tags`.chomp
11+
if version_string.empty?
12+
version_string = '0'
13+
end
14+
date_string = Time.now.strftime('%Y-%m-%d')
15+
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}'"
16+
header_hash = `git rev-parse --short HEAD`.strip
17+
18+
# Check contributors list
19+
# This checks commit hash stored in the header of list against current HEAD
20+
def check_contrib
21+
if File.exist?('book/contributors.txt')
22+
current_head_hash = `git rev-parse --short HEAD`.strip
23+
header = `head -n 1 book/contributors.txt`.strip
24+
# Match regex, then coerce resulting array to string by join
25+
header_hash = header.scan(/[a-f0-9]{7,}/).join
26+
27+
if header_hash == current_head_hash
28+
puts "Hash on header of contributors list (#{header_hash}) matches the current HEAD (#{current_head_hash})"
29+
else
30+
puts "Hash on header of contributors list (#{header_hash}) does not match the current HEAD (#{current_head_hash}), refreshing"
31+
`rm book/contributors.txt`
32+
# Reenable and invoke task again
33+
Rake::Task['book/contributors.txt'].reenable
34+
Rake::Task['book/contributors.txt'].invoke
1035
end
11-
text = File.read('progit.asc')
12-
new_contents = text.gsub("$$VERSION$$", version_string).gsub("$$DATE$$", Time.now.strftime("%Y-%m-%d"))
13-
File.open("progit.asc", "w") {|file| file.puts new_contents }
36+
end
37+
end
38+
39+
desc 'build basic book formats'
40+
task :build => [:build_html, :build_epub, :build_pdf] do
41+
begin
42+
# Run check
43+
Rake::Task['book:check'].invoke
44+
45+
# Rescue to ignore checking errors
46+
rescue => e
47+
puts e.message
48+
puts 'Error when checking books (ignored)'
49+
end
50+
end
51+
52+
desc 'build basic book formats (for ci)'
53+
task :ci => [:build_html, :build_epub, :build_pdf] do
54+
# Run check, but don't ignore any errors
55+
Rake::Task['book:check'].invoke
56+
end
57+
58+
desc 'generate contributors list'
59+
file 'book/contributors.txt' do
60+
puts 'Generating contributors list'
61+
`echo "Contributors as of #{header_hash}:\n" > book/contributors.txt`
62+
`git shortlog -s | grep -v -E "(Straub|Chacon|dependabot)" | cut -f 2- | column -c 120 >> book/contributors.txt`
63+
end
64+
65+
desc 'build HTML format'
66+
task :build_html => 'book/contributors.txt' do
67+
check_contrib()
68+
69+
puts 'Converting to HTML...'
70+
`bundle exec asciidoctor #{params} -a data-uri progit.asc`
71+
puts ' -- HTML output at progit.html'
72+
73+
end
74+
75+
desc 'build Epub format'
76+
task :build_epub => 'book/contributors.txt' do
77+
check_contrib()
78+
79+
puts 'Converting to EPub...'
80+
`bundle exec asciidoctor-epub3 #{params} progit.asc`
81+
puts ' -- Epub output at progit.epub'
82+
83+
end
1484

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

18-
puts "Converting to HTML..."
19-
`bundle exec asciidoctor progit.asc`
20-
puts " -- HTML output at progit.html"
91+
# puts "Converting to Mobi (kf8)..."
92+
# `bundle exec asciidoctor-epub3 #{params} -a ebook-format=kf8 progit.asc`
93+
# puts " -- Mobi output at progit.mobi"
2194

22-
puts "Converting to EPub..."
23-
`bundle exec asciidoctor-epub3 progit.asc`
24-
puts " -- Epub output at progit.epub"
95+
# FIXME: If asciidoctor-epub3 supports Mobi again, uncomment these lines below
96+
puts "Converting to Mobi isn't supported yet."
97+
puts "For more information see issue #1496 at https://github.com/progit/progit2/issues/1496."
98+
exit(127)
99+
end
100+
101+
desc 'build PDF format'
102+
task :build_pdf => 'book/contributors.txt' do
103+
check_contrib()
25104

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

30-
puts "Converting to PDF... (this one takes a while)"
31-
`bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicKR progit.asc 2>/dev/null`
32-
puts " -- PDF output at progit.pdf"
110+
desc 'Check generated books'
111+
task :check => [:build_html, :build_epub] do
112+
puts 'Checking generated books'
113+
114+
exec_or_raise('htmlproofer --check-html progit.html')
115+
exec_or_raise('epubcheck progit.epub')
116+
end
33117

34-
ensure
35-
`mv progit.asc.bak progit.asc`
118+
desc 'Clean all generated files'
119+
task :clean do
120+
begin
121+
puts 'Removing generated files'
122+
123+
FileList['book/contributors.txt', 'progit.html', 'progit.epub', 'progit.pdf'].each do |file|
124+
rm file
125+
126+
# Rescue if file not found
127+
rescue Errno::ENOENT => e
128+
begin
129+
puts e.message
130+
puts 'Error removing files (ignored)'
131+
end
132+
end
36133
end
37134
end
135+
38136
end
39137

40138
task :default => "book:build"

0 commit comments

Comments
 (0)