Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions .github/workflows/build-pdf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Build and Release PDF

on:
push:
tags:
- 'v*'
- 'release*'
workflow_dispatch:

permissions:
contents: write

jobs:
build-pdf:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
run: |
# Install pandoc
wget -q https://github.com/jgm/pandoc/releases/download/3.1.11/pandoc-3.1.11-1-amd64.deb
sudo dpkg -i pandoc-3.1.11-1-amd64.deb
rm pandoc-3.1.11-1-amd64.deb

# Install TeX Live with XeLaTeX and Chinese support
sudo apt-get update
sudo apt-get install -y \
texlive-xetex \
texlive-lang-chinese \
texlive-fonts-recommended \
texlive-fonts-extra \
fonts-noto-cjk \
fonts-noto-cjk-extra

# Verify installations
pandoc --version
xelatex --version

- name: Build PDF
run: |
chmod +x bin/pdf bin/preprocess-epub.py
mkdir -p output output/temp

# Preprocess Markdown files
python3 bin/preprocess-epub.py content/zh output/temp

# Generate PDF with CI-specific fonts (Noto CJK)
pandoc -o output/ddia.pdf \
--metadata-file=metadata.yaml \
-H bin/header-ci.tex \
--toc \
--toc-depth=2 \
--top-level-division=chapter \
--file-scope=true \
--pdf-engine=xelatex \
-V geometry:margin=1in \
-V linestretch=1.5 \
output/temp/_index.md \
output/temp/preface.md \
output/temp/part-i.md \
output/temp/ch1.md \
output/temp/ch2.md \
output/temp/ch3.md \
output/temp/ch4.md \
output/temp/part-ii.md \
output/temp/ch5.md \
output/temp/ch6.md \
output/temp/ch7.md \
output/temp/ch8.md \
output/temp/ch9.md \
output/temp/part-iii.md \
output/temp/ch10.md \
output/temp/ch11.md \
output/temp/ch12.md \
output/temp/ch13.md \
output/temp/ch14.md \
output/temp/colophon.md \
output/temp/glossary.md

rm -rf output/temp

if [ ! -f "output/ddia.pdf" ]; then
echo "Error: PDF file was not created"
exit 1
fi

ls -lh output/ddia.pdf
file output/ddia.pdf

- name: Upload PDF artifact
uses: actions/upload-artifact@v4
with:
name: ddia-pdf
path: output/ddia.pdf
retention-days: 30

- name: Create/Update Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: output/ddia.pdf
name: ${{ github.ref_name }}
body: |
## 《设计数据密集型应用》PDF 版本

此版本为自动生成的 PDF 电子书。

### 文件信息
- 文件名: `ddia.pdf`
- 生成时间: ${{ github.event.head_commit.timestamp }}
- 标签: ${{ github.ref_name }}

### 依赖工具
- Pandoc 3.1.11
- XeLaTeX (TeX Live)
- 中文字体: Noto CJK

### 本地生成
如需本地生成 PDF,请确保安装以下依赖:
```bash
# macOS
brew install pandoc
brew install --cask mactex

# Ubuntu/Debian
sudo apt install pandoc texlive-xetex texlive-lang-chinese

# 生成 PDF
make pdf
```
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ public/
CLAUDE.md
content/cn/
zh.md
en.md
en.md
.venv
AGENTS.md

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ translate:
epub:
bin/epub

.PHONY: default doc translate
pdf:
bin/pdf

.PHONY: default doc translate epub pdf
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@

**阅读**:访问 [https://ddia.vonng.com](https://ddia.vonng.com) 阅读本书在线版本,或使用 [hugo](https://gohugo.io/documentation/) / [hextra](https://imfing.github.io/hextra/zh-cn/) 主题自行构建。

**下载**:可以使用以下命令生成 PDF 电子书:

```bash
# 安装依赖
brew install pandoc
brew install poppler # 用于 pdftotext

# 生成 PDF
make pdf
```

生成的 PDF 文件位于 `output/ddia.pdf`

> [!NOTE]
> [**DDIA 第二版**](https://ddia.vonng.com) 正在翻译中(翻译至至第十章),欢迎阅览并提出您的宝贵意见![点击此处阅览第一版](https://ddia.vonng.com/v1)。

Expand Down
31 changes: 31 additions & 0 deletions bin/header-ci.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
% Chinese support with xeCJK
\usepackage{xeCJK}
\setCJKmainfont{Noto Serif CJK SC}
\setCJKsansfont{Noto Sans CJK SC}

% Enable Chinese line breaking
\XeTeXlinebreaklocale "zh"

% Paragraph settings
\usepackage{parskip}
\setlength{\parindent}{2em}
\usepackage{ragged2e}

% Chinese punctuation style
\punctstyle{quanjiao}

% Cover page
\AtBeginDocument{%
\thispagestyle{empty}
\begin{center}
\vspace*{0.4\textheight}
{\Huge\bfseries 设计数据密集型应用}
\vspace{1cm}
{\LARGE 第二版}
\vspace{2cm}
{\Large Martin Kleppmann}
\vspace{0.5cm}
{\large 冯若航 译}
\end{center}
\clearpage
}
31 changes: 31 additions & 0 deletions bin/header.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
% Chinese support with xeCJK
\usepackage{xeCJK}
\setCJKmainfont{PingFang SC}
\setCJKsansfont{Heiti SC}

% Enable Chinese line breaking
\XeTeXlinebreaklocale "zh"

% Paragraph settings
\usepackage{parskip}
\setlength{\parindent}{2em}
\usepackage{ragged2e}

% Chinese punctuation style
\punctstyle{quanjiao}

% Cover page
\AtBeginDocument{%
\thispagestyle{empty}
\begin{center}
\vspace*{0.4\textheight}
{\Huge\bfseries 设计数据密集型应用}
\vspace{1cm}
{\LARGE 第二版}
\vspace{2cm}
{\Large Martin Kleppmann}
\vspace{0.5cm}
{\large 冯若航 译}
\end{center}
\clearpage
}
108 changes: 108 additions & 0 deletions bin/pdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash

set -e

# Check for required dependencies
check_dependencies() {
local missing_deps=()

if ! command -v pandoc &> /dev/null; then
missing_deps+=("pandoc")
fi

if ! command -v xelatex &> /dev/null; then
# Try lualatex as fallback
if ! command -v lualatex &> /dev/null; then
missing_deps+=("xelatex or lualatex (LaTeX engine)")
fi
fi

if [ ${#missing_deps[@]} -ne 0 ]; then
echo "Error: Missing required dependencies:"
for dep in "${missing_deps[@]}"; do
echo " - $dep"
done
echo ""
echo "Installation:"
echo " macOS: brew install pandoc"
echo " macOS: brew install --cask mactex"
echo ""
echo " Linux: apt install pandoc texlive-xetex"
exit 1
fi
}

check_dependencies

# Detect available PDF engine
if command -v xelatex &> /dev/null; then
PDF_ENGINE="xelatex"
elif command -v lualatex &> /dev/null; then
PDF_ENGINE="lualatex"
else
echo "Error: No suitable PDF engine found"
exit 1
fi

SCRIPT_DIR=$(dirname "$0")
INPUT_DIR=$(cd "$(dirname "$SCRIPT_DIR")" && pwd)
OUTPUT_DIR="$INPUT_DIR/output"
TEMP_DIR="$OUTPUT_DIR/temp"

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
mkdir -p "$TEMP_DIR"

# Preprocess Markdown files to convert Hugo shortcodes
echo "Preprocessing Markdown files..."
python3 "${SCRIPT_DIR}/preprocess-epub.py" "${INPUT_DIR}/content/zh" "$TEMP_DIR"

convert_to_pdf() {
# Convert all Markdown files into a single PDF book
OUTPUT_BOOK="$OUTPUT_DIR/ddia.pdf"
rm -f "$OUTPUT_BOOK"
echo "Converting all Markdown files into $OUTPUT_BOOK..."

local meta_file=${INPUT_DIR}/metadata.yaml
local header_file=${SCRIPT_DIR}/header.tex

# Use xelatex for Chinese support with custom header
pandoc -o "$OUTPUT_BOOK" \
--metadata-file="$meta_file" \
-H "$header_file" \
--toc \
--toc-depth=2 \
--top-level-division=chapter \
--file-scope=true \
--pdf-engine="$PDF_ENGINE" \
-V geometry:margin=1in \
-V linestretch=1.5 \
"${TEMP_DIR}"/_index.md \
"${TEMP_DIR}"/preface.md \
"${TEMP_DIR}"/part-i.md \
"${TEMP_DIR}"/ch1.md \
"${TEMP_DIR}"/ch2.md \
"${TEMP_DIR}"/ch3.md \
"${TEMP_DIR}"/ch4.md \
"${TEMP_DIR}"/part-ii.md \
"${TEMP_DIR}"/ch5.md \
"${TEMP_DIR}"/ch6.md \
"${TEMP_DIR}"/ch7.md \
"${TEMP_DIR}"/ch8.md \
"${TEMP_DIR}"/ch9.md \
"${TEMP_DIR}"/part-iii.md \
"${TEMP_DIR}"/ch10.md \
"${TEMP_DIR}"/ch11.md \
"${TEMP_DIR}"/ch12.md \
"${TEMP_DIR}"/ch13.md \
"${TEMP_DIR}"/ch14.md \
"${TEMP_DIR}"/colophon.md \
"${TEMP_DIR}"/glossary.md

echo "PDF book created at $OUTPUT_BOOK."
}

convert_to_pdf

# Clean up temporary files
rm -rf "$TEMP_DIR"
Loading