|
|
2 месяцев назад | |
|---|---|---|
| .. | ||
| README.md | 2 месяцев назад | |
| pipeline.md | 2 месяцев назад | |
Distilled from reference examples m16 (source blog 11 posts -> 70-page PDF). Cowork multi-pass pipeline: fetch -> clean DOM -> per-article render -> 2-pass TOC -> merge. This route is fundamentally a pipeline, not a single HTML file.
Cowork multi-pass pipeline (not a single HTML, no single skeleton).
| Stage | Tool | Purpose |
|---|---|---|
| 1. Fetch | Playwright | Pull each source page (networkidle + 1.5 s settle for lazy loads). |
| 2. Per-article DOM cleanup | Playwright page.evaluate |
Inject hide CSS to strip nav / footer / cookie / related-posts / share / sticky elements. |
| 3. Per-article render | Playwright page.pdf() |
One PDF per article (do NOT merge HTML). |
| 4. Collect metadata | pdfinfo | Page count per article -> page-offset map for the TOC. |
| 5. TOC pass 1 | reportlab canvas | Render the TOC with mock page numbers; measure its own page count. |
| 6. Merge pass 1 | pypdf | Concatenate [TOC + article 1..N]; recompute the true start page of each article. |
| 7. TOC pass 2 | reportlab canvas | Re-render the TOC with the real page numbers. |
| 8. Merge pass 2 | pypdf | Final PDF + outline bookmarks + /Link annotations. |
| 9. (Optional) trim trailing blanks | pypdf | Detect per-article trailing pages that are >= 90% blank; drop them and re-balance offsets. |
Why cowork instead of merging HTML in one shot: 11 articles use different Webflow templates with conflicting CSS cascades. Rendering each article in isolation preserves its font hierarchy without cross-contamination.
page-break-before) ->
colophon (optional).@font-face woff2 -> convert to TTF ->
inline as data: URIs; font-family cascade with fallbacks;
critical: await document.fonts.ready before rendering.font-family: Menlo, Consolas, monospace;
background: #f5f5f5; padding: 12px; whitespace: pre-wrap.max-width: 100%; height: auto. Wait for img.complete
before rendering.See pipeline.md (cowork pipeline pseudocode + per-article
HTML stub + TOC rendering spec).
Quick start:
# This route has no "copy a single skeleton" path — you must walk the pipeline.
# 1. Prepare posts_list.json: [{url, title, date, author, category, slug}, ...]
# 2. Run fetch + clean DOM + per-article render (python + playwright).
# 3. Render TOC with reportlab, merge with pypdf.
# Full details in pipeline.md.
await document.fonts.ready Chromium
substitutes system fonts (Times / Helvetica) and breaks the visual.
Always await custom fonts.wait_for_timeout(1500-2000) so all images settle..is-cc / [class*='icon']
in deeply nested layouts; broad selectors like [class*='form_']
accidentally hit .hero_blog_post_details_form and collapse the
metadata block. Use an explicit KEEP whitelist + force
display: flex for the wanted nodes.svg, [class*='icon'] { max-width: 64px; max-height: 64px; }.c.showPage() once you exceed SAFE_PAGE_H./Dest indirect
reference with both pdfinfo and pypdf outline.--order=chrono|reverse, --group-by=category|date.Required:
COMPILATION_TITLESOURCE_WEBFONT_FAMILY (auto-discover from source @font-face, or
getComputedStyle(body).fontFamily).posts_list.json ([{url, title, date, author, slug, category}]).N_ARTICLES (5-50 typical).Optional:
Structural invariants:
page-break-before: always per article.img { max-width: 100%; height: auto; } to prevent overflow.Swappable:
page.pdf() margin dict).Diversify every run. The aggregator should inherit the source
site's webfont (auto-detect via getComputedStyle) — do not default
to a stock sans-serif. Re-pick the cover treatment, accent color, and
TOC layout based on the source site's identity (Substack newsletter
warmth vs dev.to monospace vs corporate blog formality). Two digests
from two different blogs should read as separate publications, not
both wearing the m18 default.