自製ePub電子書技巧分享;亞馬遜Kindle的輔助工具
2022-8-14 17:39:6 Author: jdev.tw(查看原文) 阅读量:45 收藏

Kindle要停用MOBI與AZW格式,轉用更通用的ePub格式了。如果你跟我一樣經常自製電子書的話,可以參考我的製作步驟,以簡化產生ePub電子書的操作流程:

  1. 用EmEditor將下載的文字檔(.txt)轉換為Markdown格式
  2. 用pandoc命令將Markdown文字檔轉換成.epub格式
  3. 用blat命令將.epub檔寄至Kindle的電子信箱 (可使用如Outlook/Thunderbird等郵件軟體取代)


先手動執行,等有空時再寫個程式簡化整個操作流程吧。

1. 準備

1.1. 安裝要使用的命令行工具

  1. 下載並安裝EmEditor,你也可以使用自己慣用的文字編輯器,用來將章節標題加上Markdown的標題井號
    1. 下載並安裝簡轉繁外掛
    2. 下載並安裝繁轉簡外掛
  2. 下載並安裝Pandoc– a universal document converter
  3. 下載並安裝Blat – Windows Command Line SMTP Mailer Files (可使用如Outlook/Thunderbird等郵件軟體取代)

1.2. Blat設定 (Optional)

用下列命令設定blat指令要連線的SMTP主機與登入帳號、密碼:

[!TIP] 命令
blat -install SMTP主機 電子信箱 5 -u 登入帳號 -pw 登入密碼

  • 例如:blat -install mycompany.com [email protected] 5 -u myname -pw mypassword
  • 5是重試次數

2. 文字檔轉換成Markdown格式

  1. 將文字檔另存成==UTF-8不帶BOM==格式
  2. 全選後點擊【簡轉繁】或【繁轉簡】按鈕
  3. 執行EmEditor的巨集,透過正則運算式轉換將章節標題加上井號

範例如下:

document.selection.Replace("^第(.*)章(.*)", "第$1章 $2",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)章(.*),(.*)", "第$1章 $2·$3",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)章(.*),(.*)集", "第$1章 $2·$3",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)卷 (.*) 第(.*)章 (.*)","## 第$1卷 $2 第$3章 $4",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)卷(.*)第(.*)章(.*)","## 第$1卷 $2 第$3章 $4",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)卷 (.*)","# 第$1卷 $2",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^卷(.*) (.*) (.*)章 (.*)", "## 第$1卷 $2 第$3章 $4",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^正文 第(.*)章 (.*)","## 第$1章 $2",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)章 (.*),(.*)","## 第$1章 $2·$3",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)章 (.*),(.*)","## 第$1章 $2·$3",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)章 (.*)","## 第$1章 $2",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)章:(.*)","## 第$1章 $2",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)集 (.*)","## 第$1集 $2",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^正文 第(.*)節 (.*)","## 第$1節 $2",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^正文 第(.*)章(.*)","## 第$1章 $2",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^第(.*)節 (.*)","## 第$1節 $2",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("^===第(.*)===","## 第$1",eeFindNext | eeFindSaveHistory | eeReplaceAll | eeFindReplaceRegExp);

3. 用Pandoc將Markdown轉換成.epub

[!TIP] 命令
pandoc 書名.txt -f markdown –toc –metadata title=”書名” –metadata author=”作者名” –metadata lang=”zh-Hant” –css style.css -o 書名.epub

3.1. 選項說明

  • –toc:(可省略) 產生目錄,有此參數時會在正文前面多出章節的超鏈接頁面,Kindle的【前往】才有資料可跳到特定章節
  • –metadata lang:(可省略) 無此參數時預設是”en-US”,指定”zh-hant”(繁體中文)或”zh-hans”(簡體中文)時,Kindle字型選單才會出現【黑体】、【圆体】、【宋体】、【楷体】等中文字型選項
  • –css style.css:(可省略) 指定樣式檔,可自行定義Kindle裡內容的呈現樣式

3.2. style.css範例

html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: "黑体", "圆体", "宋体", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", serif;
    margin: auto;
    text-align: justify;
    font-size: 16px;
    line-height: 1.0;
}

h1 { text-align: left; }
h2 { text-align: left; }
h3 { text-align: left; }
h4 { text-align: left; }
h5 { text-align: left; }
h6 { text-align: left; }

h1.title {
    margin-top: 150px;
    font-size: 20pt;
    text-align: center;
}

p.author {
    text-align: center;
    font-size:18pt;
}

ol.toc {
    padding: 0;
    margin: 1em 0;
    padding: 0 0 0 2em;
}

ul.toc ul, ol.toc ol {
    margin: .3em 0;
}

li { margin: 0; padding: 0 5px; }

code {
    font-family: monospace;
    background-color: rgb(247, 247, 247);
}

pre {
    font-family: monospace;;
    padding: 16px;
    overflow: auto;
    font-size: 80%;
    line-height: 1.45;
    border-radius: 3px;
    background-color: rgb(247, 247, 247);
}

3.3. 觀察.epub檔

.epub是壓縮檔,可以用7-Zip等壓縮工具查看其內容。

4. 用blat傳送檔案

因為GMail等網站都有傳送信件最大25MB的限制,因此blat設定時最好使用平常使用的公司SMTP主機。

[!TIP] 命令
blat – -to Kindle電子信箱 -s “主旨” -body “內文” -log blat.log -force8bit -charset utf-8 -unicode -attach “書名.epub”
type blat.log

4.1. 選項說明

  • -log:執行時blat顯示的中文書名變問號,但導向到檔案再輸出則正常
  • -force8bit:無此參數時,amazon.com無法產生文件;若書名沒有中文時可不加此參數

5. 相關鏈接

6. 教學影片

##

您可能也會有興趣的類似文章


文章来源: https://jdev.tw/blog/7313/create-epub-for-kindle
如有侵权请联系:admin#unsafe.sh