Skip to content

Commit 60bc878

Browse files
committed
Print style fixes
1 parent 1e50bf5 commit 60bc878

14 files changed

Lines changed: 408 additions & 189 deletions

File tree

_TODO.md

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
<!-- markdownlint-disable-file -->
22
# TODO
33

4-
## E2E
5-
6-
View Lighthouse report:
7-
8-
xdg-open ".cache/playwright/lighthouse-reports/run Lighthouse audit on homepage-desktop-1774621624366.html"
9-
104
## Print
115

126
1. Add a QR code at the bottom of printed pages so it's easier for someone to navigate to from a printed page. We have a QrCode component.
@@ -25,33 +19,14 @@ A professional print header typically includes only these three elements:
2519

2620
- Brand Identity: A high-contrast version of your logo or the site name in plain text for brand recognition.
2721
- Document Title: The main title of the page (usually the <h1>), ensuring the reader knows exactly what the document is.
28-
- Source URL: A small, plain-text URL so the reader can find the live version later.
29-
30-
__Elements to Remove__
31-
32-
Hide any interactive or screen-specific components using display: none; in your @media print block:
33-
34-
- Navigation Menus: All top-level and dropdown links.
35-
- Search Icons/Bars: These are non-functional on paper.
36-
- Breadcrumbs: While useful on-screen for site hierarchy, they often look like cluttered, disconnected text on paper. Most designers remove them to keep the focus on the primary content.
37-
- Social Media & CTA Buttons & Download CTA: "Sign In" or "Follow Us" buttons are irrelevant in print.
3822

3923
__Expand External Links For Print__
4024

4125
We can't (yet) directly interface with a printed page to explore links, so link URLs should be visible on the printed version of the Web page. To keep the page relatively clean, I prefer to expand only outbound links in articles, and suppress internal ones. If you've used relative URLs on your website for local links, you can easily do this through an attribute selector and `:after` pseudo classes, thus preventing internal links and links around images from being printed:
4226

43-
```css
44-
@media print {
45-
article a {
46-
font-weight: bolder;
47-
text-decoration: none;
48-
}
49-
50-
article a[href^=http]:after {
51-
content:" <" attr(href) "> ";
52-
}
53-
}
54-
```
27+
- Break Lists across pages, the separators between columns are broken too
28+
- Break code blocks across pages
29+
- Callouts are breaking across pages, they shouldn't
5530

5631
## PDF File Generation
5732

src/components/CallToAction/Contact/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const descriptionId = `${idBase}-description`
5050
---
5151

5252
<section
53-
class="cta mx-auto max-w-4xl rounded-lg overflow-hidden relative"
53+
class="cta mx-auto max-w-4xl rounded-lg overflow-hidden relative print:hidden"
5454
aria-labelledby={titleId}
5555
aria-describedby={descriptionId}
5656
>

src/components/CallToAction/Download/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const downloadUrl = `/downloads/${normalizedResource}`
5858
---
5959

6060
<section
61-
class="bg-linear-to-br from-primary/5 to-accent/5 border border-primary/20 rounded-2xl p-6 md:p-8 mb-6"
61+
class="bg-linear-to-br from-primary/5 to-accent/5 border border-primary/20 rounded-2xl p-6 md:p-8 mb-6 print:hidden"
6262
aria-labelledby={titleId}
6363
aria-describedby={descriptionId}
6464
>

src/components/CallToAction/Newsletter/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const {
3131
} = Astro.props
3232
---
3333

34-
<newsletter-form class="cta block">
34+
<newsletter-form class="cta block print:hidden">
3535
{variant === 'article' && (
3636
<ArticleNewsletter
3737
title={title}

src/components/Carousel/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const carouselRegionRole = carouselRegionLabelledBy ? 'region' : undefined
9191
<carousel-slider
9292
data-carousel
9393
data-carousel-navigation-mode={navigationMode}
94-
class="block"
94+
class="block print:hidden"
9595
>
9696
<section class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
9797
{title && (

src/components/Content/Layout/index.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const isDeepDive = section === 'Deep Dive Articles'
5757
{
5858
article.data.cover && (
5959
<div
60-
class="relative w-full overflow-hidden mb-8"
60+
class="print-hero-image relative mb-8 w-full overflow-hidden"
6161
style="aspect-ratio: 1564 / 670;"
6262
slot="hero-image"
6363
>
@@ -79,7 +79,7 @@ const isDeepDive = section === 'Deep Dive Articles'
7979
}
8080

8181
{/** SLOT: after-content */}
82-
<section slot="after-content">
82+
<section class="print:hidden" slot="after-content">
8383
<WebMentions url={`https://www.webstackbuilders.com${path}`} />
8484
{!isDeepDive && (
8585
<div class="flex flex-col gap-6">
@@ -94,7 +94,7 @@ const isDeepDive = section === 'Deep Dive Articles'
9494

9595
{/** SLOT: related-content */}
9696
<section
97-
class="border-t border-trim pt-8 mt-12"
97+
class="border-t border-trim pt-8 mt-12 print:hidden"
9898
aria-labelledby="article-related-title"
9999
slot="related-content"
100100
>

src/components/QrCode/__tests__/index.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ describe('QrCode (Astro)', () => {
2626
const renderedHtml = await renderQrCode()
2727
const document = new JSDOM(renderedHtml).window.document
2828

29-
const root = document.querySelector<HTMLElement>('[data-qr-code]')
29+
const root = document.querySelector<HTMLElement>('figure[data-qr-code]')
3030
const svg = root?.querySelector('svg')
31+
const caption = root?.querySelector('figcaption')
3132

3233
expect(root).toBeTruthy()
3334
expect(root?.className).toContain('hidden')
3435
expect(root?.getAttribute('aria-label')).toContain('https://example.com/articles/demo')
3536
expect(svg).toBeTruthy()
3637
expect(svg?.querySelector('#logo-group')).toBeTruthy()
38+
expect(caption?.textContent).toContain('https://example.com/articles/demo')
3739
})
3840

3941
test('omits the hidden class when isHidden is false and respects a custom data prop', async () => {
@@ -43,10 +45,12 @@ describe('QrCode (Astro)', () => {
4345
})
4446
const document = new JSDOM(renderedHtml).window.document
4547

46-
const root = document.querySelector<HTMLElement>('[data-qr-code]')
48+
const root = document.querySelector<HTMLElement>('figure[data-qr-code]')
49+
const caption = root?.querySelector('figcaption')
4750

4851
expect(root).toBeTruthy()
4952
expect(root?.className).not.toContain('hidden')
5053
expect(root?.getAttribute('aria-label')).toContain('https://example.com/contact')
54+
expect(caption?.textContent).toContain('https://example.com/contact')
5155
})
5256
})

src/components/QrCode/index.astro

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ const qrData = data ?? new URL(Astro.url.pathname, Astro.site ?? Astro.url).toSt
1111
const qrSvg = await renderQrCodeSvg({ data: qrData })
1212
---
1313

14-
<div
14+
15+
<figure
1516
class:list={[
16-
'not-prose mx-auto my-8 w-fit print:block print:break-inside-avoid',
17+
'not-prose mx-auto my-8 flex w-fit flex-col items-center print:block print:break-inside-avoid',
1718
isHidden && 'hidden',
1819
]}
1920
data-qr-code
2021
role="img"
2122
aria-label={`QR code for ${qrData}`}
2223
>
2324
<Fragment set:html={qrSvg} />
24-
</div>
25+
<figcaption class="mt-3 max-w-60 break-all text-center text-sm text-content">
26+
{qrData}
27+
</figcaption>
28+
</figure>

src/components/Social/Shares/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const shareHeadingId = `${iconBankId}-heading`
5959
</div>
6060

6161
<section
62-
class="rounded-lg bg-page-offset flex flex-col md:flex-row items-start md:items-center p-6 mx-6"
62+
class="rounded-lg bg-page-offset flex flex-col md:flex-row items-start md:items-center p-6 mx-6 print:hidden"
6363
>
6464
<div class="h-full w-full sm:border-r sm:border-trim sm:w-auto sm:shrink-0 sm:pr-12">
6565
<h2

src/components/WebMentions/index.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const iconBankId = `webmentions-icon-bank-${Math.random().toString(36).slice(2)}
3434
</div>
3535

3636
<web-mentions
37+
class="print:hidden"
3738
url={url}
3839
show-facepile={showFacepile}
3940
facepile-limit={facepileLimit}

0 commit comments

Comments
 (0)