Skip to content

Commit 266e4bb

Browse files
committed
Update
1 parent df8d94d commit 266e4bb

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

images/exporter-build/Dockerfile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
3636
--mount=type=cache,target=/var/lib/apt,sharing=locked \
3737
set -eux; \
3838
apt-get update; \
39-
# 基础工具
40-
apt-get install -y --no-install-recommends \
39+
apt-get install -y eatmydata; \
40+
eatmydata apt-get install -y \
4141
python3 python3-pip python3-dev \
4242
bash tini tar zstd unzip git ca-certificates curl wget \
4343
liblmdb0 build-essential libffi-dev ghostscript \
@@ -70,10 +70,10 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
7070
libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 \
7171
libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget; \
7272
# 清理
73+
apt-get purge -y --auto-remove eatmydata; \
7374
apt-get clean; \
74-
rm -rf /var/lib/apt/lists/*; \
75-
fc-cache -fv; \
76-
git config --system --add safe.directory '/__w/*'
75+
git config --system --add safe.directory '/__w/*'; \
76+
rm -rf /var/lib/apt/lists/*
7777

7878
WORKDIR /app
7979

@@ -89,9 +89,10 @@ RUN --mount=type=bind,source=.python-version,target=.python-version \
8989
uv sync --locked --no-cache
9090

9191
# 6. 拷贝应用代码
92-
COPY src/ ./src/
93-
COPY scripts/ ./scripts/
94-
COPY templates/ ./templates/
92+
COPY src/ /app/src/
93+
COPY scripts/ /app/scripts/
94+
COPY templates/ /app/templates/
95+
COPY --chmod=755 bin/ /usr/local/bin/
9596

9697
ENTRYPOINT ["/usr/bin/tini", "--"]
97-
CMD ["npm", "start"]
98+
CMD ["export-pdf"]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
set -e
3+
4+
BOOK_NAME="$1"
5+
6+
if [ -z "$BOOK_NAME" ]; then
7+
echo "Usage: export-pdf <book_name>"
8+
exit 1
9+
fi
10+
11+
echo "[Export-PDF] Starting Puppeteer printing..."
12+
node /app/src/index.js "$BOOK_NAME"
13+
14+
echo "[Export-PDF] Generating TeX templates..."
15+
uv run /app/scripts/processor.py "${BOOK_NAME}.json" --plan-only
16+
17+
echo "[Export-PDF] Compiling TeX with LaTeX..."
18+
# Note: We assume latexmk is available in the environment OR this part
19+
# is handled by a separate step in GHA using the texlive-full container.
20+
# According to the workflow, we use the texlive-full container separately.
21+
# So this script might just handle the parts that run in exporter-build.
22+
23+
# If we want it to be a complete wrapper, we'd need latexmk here too.
24+
# But keeping it aligned with the user's 3-step GHA workflow is safer.
25+
26+
echo "[Export-PDF] Finalizing synthesis and bookmarks..."
27+
uv run /app/scripts/processor.py "${BOOK_NAME}.json" --merge
28+
29+
echo "[Export-PDF] Done."

images/exporter-build/scripts/processor.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import fitz
22
import json
33
import os
4-
import sys
5-
import yaml
6-
import subprocess
74
from pathlib import Path
85
from jinja2 import Environment, FileSystemLoader
96

@@ -16,7 +13,9 @@ def __init__(self, book_json_path, output_dir="build"):
1613
with open(self.book_json_path, "r", encoding="utf-8") as f:
1714
self.book_data = json.load(f)
1815

19-
self.jinja_env = Environment(loader=FileSystemLoader("templates"))
16+
# 锚定模板目录到镜像内的绝对路径
17+
template_dir = os.environ.get("TEMPLATES_DIR", "/app/templates")
18+
self.jinja_env = Environment(loader=FileSystemLoader(template_dir))
2019
self.final_doc = fitz.open()
2120
self.page_offset = 0
2221
self.toc_data = []
@@ -33,8 +32,8 @@ def extract_precise_toc(self, doc, offset):
3332
blocks = page.get_text("dict")["blocks"]
3433
for b in blocks:
3534
if "lines" in b:
36-
for l in b["lines"]:
37-
for s in l["spans"]:
35+
for line in b["lines"]:
36+
for s in line["spans"]:
3837
# 粗放式匹配:字体大且粗的可能是标题
3938
if s["size"] > 12:
4039
text = s["text"].strip()

images/exporter-build/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ async function main() {
134134
process.exit(1);
135135
}
136136

137-
const buildDir = path.join(process.cwd(), 'site', 'build');
138137
const siteDir = path.join(process.cwd(), 'site');
138+
const buildDir = path.join(siteDir, 'build');
139139
const tasksFile = path.join(buildDir, `download_${bookName}.json`);
140140

141141
if (!fs.existsSync(tasksFile)) {

0 commit comments

Comments
 (0)