Skip to content

Commit 1ffb074

Browse files
Add print styles (#624)
1 parent 9986b83 commit 1ffb074

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

web/src/layouts/BaseLayout.astro

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { siteInfo } from "#constants/site-info";
88
import "../styles/base.css";
99
import "../styles/reset.css";
1010
import "../styles/theme.css";
11+
import "../styles/print.css";
1112
1213
export interface Props {
1314
title: string;
@@ -86,5 +87,13 @@ const pageTitle = Astro.url.pathname === "/" ? title : `${title} · Namesake`;
8687
<slot />
8788
</main>
8889
<Footer />
90+
<script>
91+
// Print media lazy-loading bypass
92+
window.addEventListener('beforeprint', () => {
93+
document.querySelectorAll('img[loading]').forEach(img => {
94+
img.removeAttribute('loading');
95+
});
96+
});
97+
</script>
8998
</body>
9099
</html>

web/src/styles/print.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* These styles are only used when printing the page. */
2+
/* biome-ignore-all lint/complexity/noImportantStyles: print styles should always override site styles */
3+
4+
@media print {
5+
html,
6+
body {
7+
background-color: none;
8+
}
9+
10+
body > *:not(main) {
11+
display: none !important;
12+
}
13+
14+
body::before,
15+
body::after {
16+
display: none;
17+
}
18+
19+
.rough-annotation {
20+
display: none; /* Would display in odd location due to loading delay. */
21+
}
22+
23+
details::details-content {
24+
height: auto !important;
25+
content-visibility: visible !important;
26+
opacity: 1 !important;
27+
}
28+
29+
a[href]:not([href^="#"])::after {
30+
content: " (" attr(href) ")";
31+
}
32+
33+
abbr[title]::after {
34+
content: " (" attr(title) ")";
35+
}
36+
}

0 commit comments

Comments
 (0)