Skip to content

Commit 30e9d89

Browse files
committed
Update
1 parent 266e4bb commit 30e9d89

7 files changed

Lines changed: 37 additions & 42 deletions

File tree

images/example_workflow.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,20 @@ jobs:
6969
path: site/
7070

7171
- name: Puppeteer - Print Web to PDF
72-
run: |
73-
node /app/src/index.js "${{ matrix.book }}"
72+
run: export-pdf-1-print "${{ matrix.book }}"
7473
env:
7574
CONCURRENCY: 4
7675

7776
- name: Python - Prepare TeX & Planning
78-
run: |
79-
uv run /app/scripts/processor.py "${{ matrix.book }}.json" --plan-only
77+
run: export-pdf-2-plan "${{ matrix.book }}"
8078

8179
- name: LaTeX - Compile Decorations
8280
uses: docker://ghcr.io/rainppr/texlive-full:latest
8381
with:
8482
args: latexmk -xelatex build/*.tex
8583

8684
- name: Python - Final Synthesis & Bookmarks
87-
run: |
88-
uv run /app/scripts/processor.py "${{ matrix.book }}.json" --merge
85+
run: export-pdf-3-merge "${{ matrix.book }}"
8986

9087
- name: Upload Book Product
9188
uses: actions/upload-artifact@v4
@@ -96,7 +93,7 @@ jobs:
9693

9794
export_publish:
9895
name: "Publish: Collect and Release"
99-
needs: export_compile
96+
needs: export_process
10097
runs-on: ubuntu-latest
10198
steps:
10299
- name: Download all compiled PDFs

images/exporter-build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ COPY templates/ /app/templates/
9595
COPY --chmod=755 bin/ /usr/local/bin/
9696

9797
ENTRYPOINT ["/usr/bin/tini", "--"]
98-
CMD ["export-pdf"]
98+
CMD ["export-pdf-1-print"]

images/exporter-build/bin/export-pdf

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -e
3+
if [ -z "$1" ]; then
4+
echo "Usage: export-pdf-1-print <book_name>"
5+
exit 1
6+
fi
7+
node /app/src/index.js "$1"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -e
3+
if [ -z "$1" ]; then
4+
echo "Usage: export-pdf-2-plan <book_name>"
5+
exit 1
6+
fi
7+
uv run /app/scripts/processor.py "site/build/$1.json" --plan-only
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -e
3+
if [ -z "$1" ]; then
4+
echo "Usage: export-pdf-3-merge <book_name>"
5+
exit 1
6+
fi
7+
uv run /app/scripts/processor.py "site/build/$1.json" --merge

images/exporter-build/scripts/processor.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ def extract_precise_toc(self, doc, offset):
3737
# 粗放式匹配:字体大且粗的可能是标题
3838
if s["size"] > 12:
3939
text = s["text"].strip()
40+
# 存入映射,对 key 进行标准化处理(去除空格、处理罕见字符等)
4041
if text:
41-
headings_map[text] = (page_num, s["bbox"][1])
42+
headings_map[text.lower()] = (page_num, s["bbox"][1])
4243

4344
refined_toc = []
4445
for entry in raw_toc:
4546
lvl, title, page, dest = entry
46-
# 尝试匹配文本高度
47-
if title in headings_map:
48-
p_idx, y_coord = headings_map[title]
47+
# 尝试匹配文本高度,使用小写标准化匹配
48+
match_title = title.strip().lower()
49+
if match_title in headings_map:
50+
p_idx, y_coord = headings_map[match_title]
4951
dest = {"kind": fitz.LINK_GOTO, "to": fitz.Point(0, y_coord)}
5052

5153
refined_toc.append([lvl, title, page + offset, dest])
@@ -81,7 +83,11 @@ def process(self):
8183

8284
# 插入内容页
8385
for sub in section["sections"]:
84-
content_path = Path("site/build") / sub["path"]
86+
# 尝试从 JSON 所在目录查找,或者使用绝对 site/build 路径
87+
content_path = self.book_json_path.parent / sub["path"]
88+
if not content_path.exists():
89+
content_path = Path("site/build") / sub["path"]
90+
8591
if content_path.exists():
8692
doc = fitz.open(content_path)
8793
# 提取并偏移章节内的书签

0 commit comments

Comments
 (0)