Skip to content

Commit c3832e4

Browse files
committed
docs: deduplicate built HTML images into a shared image/ tree
The HTML doc build copies every referenced image into each language and topic directory, so the built tree carries the same bytes many times over (238 MB of images, only 30 MB unique). Add docs/src/tools/dedup-images.py: it collapses byte-identical images (SHA-256) into a shared root image/ tree, keeps only translated overrides under <lang>/image/, and rewrites every src and click-to-enlarge href to match. Dry-run by default, idempotent, and self-verifying: after --apply it re-resolves every reference and fails if any is broken. Wire it into the htmldocs build as a final .dedup-images-stamp step. The tool preserves the mtime of every HTML file it rewrites, so a second `make htmldocs` does no work. On the full translated tree this takes the build output from 325 MB to 119 MB (images 238 MB to 30 MB) with all references verified.
1 parent 7565f7a commit c3832e4

2 files changed

Lines changed: 387 additions & 2 deletions

File tree

docs/src/Submakefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ $(DOC_OUT_HTML)/pdf/index.html: $(PDF_TARGETS) ../scripts/make-docs-pdf-index
573573
@mkdir -p $(dir $@)
574574
$(Q)../scripts/make-docs-pdf-index
575575

576-
htmldocs: svgs_made_from_dots .htmldoc-stamp checkref_en
576+
htmldocs: svgs_made_from_dots .htmldoc-stamp .dedup-images-stamp checkref_en
577577

578578
# When translations are enabled, the .adoc files in $(L)/ are produced by
579579
# the translateddocs target (po4a). Teach make how to ask for them: the
@@ -595,6 +595,13 @@ endif
595595
.htmldoc-stamp: .copy-asciidoc-stamp $(DOC_DIR)/.gen_complist-stamp $(HTML_TARGETS) .images-stamp .include-stamp $(DOC_OUT_HTML)/asciidoctor.css $(DOC_OUT_HTML)/rouge-github.css .lang-switcher-stamp
596596
touch $@
597597

598+
# Collapse byte-identical images into a shared image/ tree and rewrite refs.
599+
# Runs last; the tool preserves HTML mtimes so a second `make htmldocs` is a
600+
# no-op.
601+
.dedup-images-stamp: $(DOC_SRCDIR)/tools/dedup-images.py .htmldoc-stamp
602+
$(Q)python3 $(DOC_SRCDIR)/tools/dedup-images.py --html-root $(DOC_OUT_HTML) --apply
603+
@touch $@
604+
598605
# Inject the whole-document sidebar/topbar and grey out missing language-
599606
# switcher entries. Runs last (depends on every HTML target) and is
600607
# idempotent. Gated on BUILD_DOCS_HTML, not translations: the sidebar comes
@@ -705,7 +712,7 @@ checkref_en: $(DOC_DIR)/.checkref-english-stamp
705712
# (w3c-linkchecker disables file:// URIs), so the tree may carry accumulated
706713
# broken links. Report them without breaking the build for now; drop this
707714
# flag once the backlog is cleared so regressions fail the build again.
708-
$(DOC_DIR)/.checkref-english-stamp: $(DOC_TARGETS_HTML_EN) $(DOC_OUT_HTML)/en/index.html $(DOC_OUT_HTML)/en/gcode.html .htmldoc-stamp
715+
$(DOC_DIR)/.checkref-english-stamp: $(DOC_TARGETS_HTML_EN) $(DOC_OUT_HTML)/en/index.html $(DOC_OUT_HTML)/en/gcode.html .htmldoc-stamp .dedup-images-stamp
709716
$(DOC_SRCDIR)/checkref --warn-on-failure English $(filter %.html,$^)
710717
@touch $@
711718

@@ -1313,6 +1320,7 @@ docclean:
13131320
-rm -f $(DOC_SRCDIR)/*/*.html
13141321
-rm -rf $(DOC_FONT_DIR)
13151322
-rm -f .htmldoc-stamp
1323+
-rm -f .dedup-images-stamp
13161324
-rm -f .copy-asciidoc-stamp
13171325
-rm -f .adoc-images-stamp
13181326
-rm -f .html-images-stamp

0 commit comments

Comments
 (0)