gradle asciidoc 使用
备注:
次文档参考github 例子
1.环境准备
node npm (yarn) java KindleGen
备注: 具体的安装可以参考网上相关文档,KindleGen 下载地址:https://www.amazon.com/gp/feature.html?docId=1000765211
2. 代码&&运行
a. git clone code
git clone https://github.com/mraible/infoq-mini-book.git
修改build.sh 中 KindleGen 位置比如我的在 /opt/kind/kindlegen
b. build
./build.sh //epub html
./generate-pdf.sh pdf
3. 构建结果
build
└── asciidoc
├── epub3
│ └── images
└── html5
└── images
4. 效果
5. 代码结构解析
备注: 主要说明asciidoc 代码
src/docs 主要是文档以及需要的图片资源
└── asciidoc
├── chapters
├── images
└── styles
├── epub
│ └── fonts
└── pdf
└── fonts
build.gradle gradle 构建 task
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0'
classpath 'com.bluepapa32:gradle-watch-plugin:0.1.5'
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
classpath 'org.asciidoctor:asciidoctorj-epub3:1.5.0-alpha.7'
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16'
classpath 'org.jruby:jruby-complete:9.1.12.0'
}
}
apply plugin: 'java'
apply plugin: 'org.asciidoctor.convert'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'com.bluepapa32.watch'
version = '4.1.0-SNAPSHOT'
asciidoctorj {
version = '1.5.6'
}
import org.asciidoctor.gradle.AsciidoctorTask
def attrs = ['sourcedir' : '../../../main/webapp',
'source-highlighter': 'coderay',
'epub3-stylesdir' : './styles/epub',
// NOTE don't include leading ./ because it messes up paths in the epub files
'imagesdir' : 'images',
'toc' : 'left',
'icons' : 'font',
'sectanchors' : '',
'idprefix' : '',
'idseparator' : '-']
tasks.withType(AsciidoctorTask) { task ->
attributes attrs
sources {
include 'index.adoc'
}
}
task html(type: AsciidoctorTask, description: 'Generates single page HTML') {
backends 'html5'
}
// NOTE please use ./generate-pdf.sh instead of this task for now
task prepress(type: AsciidoctorTask, description: 'Generates PDF for prepress printing') {
attributes attrs + ['media' : 'prepress', 'pdfmarks': '', 'pdf-theme': 'infoq-prepress']
attrs.remove('source-highlighter')
requires file('src/main/ruby/asciidoctor-pdf-extensions.rb')
backends 'pdf'
outputDir "$buildDir/asciidoc/pdf-prepress"
separateOutputDirs false
}
// NOTE please use ./generate-pdf.sh screen instead of this task for now
task pdf(type: AsciidoctorTask, description: 'Generates PDF') {
attributes attrs + ['pdfmarks': '']
requires file('src/main/ruby/asciidoctor-pdf-extensions.rb')
backends 'pdf'
}
task epub(type: AsciidoctorTask, description: 'Generates EPUB3') {
backends 'epub3'
}
task mobi(type: AsciidoctorTask, description: 'Generates MOBI') {
backends 'epub3'
attrs.put('ebook-format', 'kf8')
attributes attrs
}
pdf.shouldRunAfter html
epub.shouldRunAfter pdf
//task all(dependsOn: ['html', 'pdf', 'epub', 'mobi'])
task all(dependsOn: ['html', 'epub', 'mobi'])
defaultTasks 'all'
watch {
asciidoc {
files fileTree(dir: 'src/docs/asciidoc', include: '**/*.adoc')
tasks 'asciidoctor'
}
}
6. 参考资料
https://www.amazon.com/gp/feature.html?docId=1000765211
http://asciidoctor.org/docs/asciidoctor-gradle-plugin/
https://github.com/asciidoctor/asciidoctor-maven-plugin