Skip to content

add print.css as a separate, lazy-loaded stylesheet#6

Merged
Arty2 merged 2 commits intoclaude/polish-passfrom
claude/print-stylesheet
Apr 29, 2026
Merged

add print.css as a separate, lazy-loaded stylesheet#6
Arty2 merged 2 commits intoclaude/polish-passfrom
claude/print-stylesheet

Conversation

@Arty2
Copy link
Copy Markdown
Owner

@Arty2 Arty2 commented Apr 29, 2026

Why

Stacked on #5. A dedicated print stylesheet — long enough that an inline @media print block inside screen.css would bloat the screen-default sheet, but small enough that a separate file is cheap. Browsers natively defer media-mismatched stylesheets, so print.css is fetched lazily only when the user actually prints (or print-previews). The on-screen page load pays nothing.

A separate sheet also makes overrides trivial: a site author can drop static/styles/custom-print.css next to custom.css without parsing screen.css.

(F1–F4 from the original audit — reading time, OG image dimensions, dark-mode favicon, apple-touch-icon — were dropped per maintainer call.)

What

New file assets/styles/print.css:

Section Rules
Palette Flat HSL channels at :root override every theme; body forced black-on-white
Layout max-width: none + zero margin on body > header, main, body > footer for a single column
Hide chrome .gadgets, .languages, nav, .taxonomy-filter, #search__form, .menu-social, .share; plus a generic [data-print="hide"] escape hatch
Hyperlinks a[href^="http"]::after { content: " (" attr(href) ")" } expands URLs to footnote-style. Same-page anchors and mailto:/tel: stay clean
Page breaks break-after: avoid on h1–h6; break-inside: avoid on figure, pre, blockquote, .alert
Cleanup Drops mix-blend-mode, filter, hover outlines

layouts/partials/head.html: new <link rel="stylesheet" media="print"> emitted alongside the existing screen.css / syntax.css. Goes through the same resources.Get | minify | fingerprint pipeline; emits the integrity attribute exactly like the other sheets.

{{- $printcss := resources.Get "/styles/print.css" | minify | fingerprint }}
<link rel="stylesheet" href="{{ $printcss.RelPermalink }}" integrity="{{ $printcss.Data.Integrity }}" crossorigin="anonymous" media="print">

Test plan

  • cd exampleSite && hugo --gc --minify — clean
  • public/styles/print.min.<hash>.css produced
  • Rendered HTML contains <link rel=stylesheet href=/styles/print.min….css integrity="sha256-…" crossorigin=anonymous media=print> (verified in public/index.html)
  • npx html-validate@^9 --config .github/html-validate.json public/**/*.html — exit 0
  • Manual: DevTools → Network → reload page → print.css shows as lowest priority and (in some browsers) listed but not blocking; Browser Print Preview shows the print rules applied
  • Manual: [data-print="hide"] element disappears in print preview; on-page hyperlinks expand to Anchor text (https://…); figures/pre blocks don't split across pages

Stacking

Base is claude/polish-pass (#5). Once #5 lands, GitHub will automatically retarget this PR to master.


Generated by Claude Code

claude added 2 commits April 29, 2026 04:50
A dedicated `assets/styles/print.css` linked with `media="print"`.
Browsers natively defer non-matching media, so the file is fetched
lazily — only when the user actually prints (or print-previews).
Screen readers and the average page load pay nothing.

A separate sheet (rather than an inline `@media print` block in
`screen.css`) keeps the default stylesheet focused, makes overrides
trivial via a custom `static/styles/custom-print.css`, and lets the
browser drop the rules from memory when not in use.

Rules:
* Flat, ink-saving palette — overrides every theme's HSL channels at
  `:root` and forces `body` to black-on-white.
* Single-column layout — `max-width: none` on `body > header`,
  `main`, `body > footer`.
* Hides chrome with no value on paper: `.gadgets`, `.languages`,
  `nav`, `.taxonomy-filter`, `#search__form`, `.menu-social`,
  `.share`. Generic escape hatch: `[data-print="hide"]`.
* Expands `http(s)` and protocol-relative hyperlinks to footnote-style
  URLs via `a::after { content: " (" attr(href) ")" }` so they survive
  the page. Same-page anchors and `mailto:`/`tel:` stay clean.
* Page-break hints: `break-after: avoid` on h1–h6, `break-inside:
  avoid` on `figure`, `pre`, `blockquote`, `.alert`.
* Drops decorative effects (`mix-blend-mode`, `filter`, hover
  outlines) that print poorly.

Wired through Hugo's existing asset pipeline (`resources.Get | minify
| fingerprint`) with SRI integrity, mirroring how `screen.css` and
`syntax.css` are already loaded.

https://claude.ai/code/session_01LAYiVF9Z1tk1PW3UAZz1Wb
@Arty2 Arty2 merged commit ab744af into claude/polish-pass Apr 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants