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

posted on   荣锋亮  阅读(1659)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示