Skip to content

Commit 1df6780

Browse files
authored
Printable cheat sheet (#2074)
## Changes - Provides the shiny new Cheat Sheet as a printable PDF ## Context This was mentioned [as a wish](#2049 (comment)). Here it is in action: - https://dscho.github.io/git-scm.com/cheat-sheet.pdf - (linked from https://dscho.github.io/git-scm.com/cheat-sheet via the <img alt="pdf-link" width=16px src="https://dscho.github.io/git-scm.com/images/pdf.png" /> icon)
2 parents 67c948e + 70d379f commit 1df6780

File tree

10 files changed

+305
-13
lines changed

10 files changed

+305
-13
lines changed

.github/actions/deploy-to-github-pages/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ runs:
8888
npm install node-html-parser &&
8989
node ./script/graphviz-ssr.js
9090
91+
- name: offer PDF version of the cheat sheet
92+
shell: bash
93+
run: |
94+
npm install @playwright/test &&
95+
node script/html-to-pdf.js -i public/cheat-sheet.html
96+
9197
- name: run Pagefind ${{ env.PAGEFIND_VERSION }} to build the search index
9298
shell: bash
9399
run: npx -y pagefind@${{ env.PAGEFIND_VERSION }} --site public --write-playground

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ jobs:
3838
npm install node-html-parser &&
3939
node ./script/graphviz-ssr.js
4040
41+
- name: Install @playwright/test
42+
run: npm install @playwright/test
43+
- name: offer PDF version of the cheat sheet
44+
run: node script/html-to-pdf.js -i public/cheat-sheet.html
45+
4146
- name: run Pagefind ${{ env.PAGEFIND_VERSION }} to build the search index
4247
run: npx -y pagefind@${{ env.PAGEFIND_VERSION }} --site public --write-playground
4348

@@ -83,8 +88,6 @@ jobs:
8388
output: lychee.md
8489
jobSummary: true
8590

86-
- name: Install @playwright/test
87-
run: npm install @playwright/test
8891
- name: Run Playwright tests
8992
id: playwright
9093
env:

assets/js/application.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ $(document).ready(function() {
3737
Downloads.init();
3838
DownloadBox.init();
3939
PostelizeAnchor.init();
40+
Print.init();
4041
});
4142

4243
function onPopState(fn) {
@@ -650,7 +651,7 @@ var DarkMode = {
650651
|| (!prefersDarkScheme && currentTheme === "dark")) {
651652
button.attr("src", `${baseURLPrefix}images/light-mode.svg`);
652653
}
653-
button.css("display", "block");
654+
button.addClass('active');
654655

655656
button.on('click', function(e) {
656657
e.preventDefault();
@@ -807,3 +808,24 @@ var Graphviz = {
807808
});
808809
}
809810
}
811+
812+
var Print = {
813+
init: function() {
814+
Print.tagline = $("#tagline");
815+
Print.scrollToTop = $("#scrollToTop");
816+
window.matchMedia("print").addListener((mediaQueryList) => {
817+
Print.toggle(mediaQueryList.matches);
818+
});
819+
},
820+
toggle: function(enable) {
821+
if (enable) {
822+
Print.taglineBackup = Print.tagline.html();
823+
Print.tagline.html("--print-out");
824+
Print.scrollToTopDisplay = Print.scrollToTop.attr("display");
825+
Print.scrollToTop.attr("display", "none");
826+
} else {
827+
Print.tagline.html(Print.taglineBackup || "--as-git-as-it-gets");
828+
Print.scrollToTop.attr("display", Print.scrollToTopDisplay);
829+
}
830+
}
831+
}

assets/sass/application.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ $baseurl: "{{ .Site.BaseURL }}{{ if (and (ne .Site.BaseURL "/") (ne .Site.BaseUR
3030
@import 'cheat-sheet';
3131
@import 'dark-mode';
3232
@import 'git-turns-20';
33+
@import 'print';
3334

3435
code {
3536
display: inline;
@@ -63,3 +64,7 @@ pre {
6364
align-self: center;
6465
margin: 5px;
6566
}
67+
68+
#dark-mode-button.active {
69+
display: block;
70+
}

assets/sass/cheat-sheet.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
border-radius: 10px;
1010
border: 1px solid var(--callout-color);
1111
display: flex;
12-
font-size: 1rem;
12+
font-size: 1em;
1313
flex-direction: column;
1414
gap: 5px;
1515

1616
p {
17-
font-size: 1rem;
17+
font-size: 1em;
1818
margin: 0 8px;
1919
}
2020

2121
h3 {
2222
color: var(--font-color);
2323
line-height: 1em;
24-
font-size: 1.1rem;
24+
font-size: 1.1em;
2525
margin-bottom: 8px;
2626
font-weight: 500;
2727
}
@@ -71,7 +71,7 @@
7171
grid-column: 1/3;
7272

7373
margin-top: 0;
74-
font-size: 1.2rem;
74+
font-size: 1.2em;
7575
font-weight: 700;
7676
line-height: 1.2;
7777
color: var(--orange);
File renamed without changes.
File renamed without changes.

assets/sass/print.scss

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
@media print {
2+
.inner {
3+
// The `position` of the `inner` class is defined as `relative`, which
4+
// causes funny issues when printing, for example tens of empty pages in
5+
// the middle. Let's suppress that.
6+
position: inherit;
7+
8+
width: inherit;
9+
margin-bottom: 0;
10+
}
11+
12+
#main {
13+
margin-bottom: 0;
14+
15+
/* Improve readability */
16+
line-height: 1.4;
17+
text-align: justify;
18+
19+
/* Ensure it uses full page width */
20+
width: 100%;
21+
border: none;
22+
padding: 0;
23+
}
24+
25+
footer {
26+
display: none;
27+
}
28+
29+
aside, .sidebar-btn, #search-container, #reference-version, #dark-mode-button, .site-source {
30+
display: none;
31+
}
32+
33+
section {
34+
break-inside: avoid-page;
35+
}
36+
37+
div#main {
38+
box-decoration-break: clone;
39+
}
40+
41+
.pdf-link, #dark-mode-button {
42+
display: none !important;
43+
}
44+
45+
.cheat-sheet {
46+
font-size: 8pt;
47+
48+
section {
49+
border: 1px solid black;
50+
display: block;
51+
gap: 0;
52+
margin-bottom: 8px;
53+
padding: 8px;
54+
55+
.item {
56+
background: none;
57+
border: none;
58+
59+
h3 {
60+
margin-bottom: 0;
61+
}
62+
63+
code {
64+
background: none;
65+
line-height: inherit;
66+
padding: 1px;
67+
display: block;
68+
margin-bottom: 2px;
69+
}
70+
}
71+
}
72+
.commit-reference {
73+
background: none;
74+
border-left: 1px solid black;
75+
76+
dl {
77+
gap: inherit;
78+
79+
dt,dt::before,dd {
80+
line-height: inherit;
81+
font-size: 0.7em !important;
82+
}
83+
}
84+
}
85+
86+
p {
87+
font-size: inherit;
88+
line-height: inherit;
89+
margin: 1px;
90+
}
91+
}
92+
}
93+
94+
@media print and (min-width: 231mm) {
95+
div#content {
96+
width: 297mm;
97+
}
98+
99+
header {
100+
padding: 0;
101+
#logo img {
102+
max-height: 23px;
103+
width: auto;
104+
height: auto;
105+
}
106+
}
107+
108+
/* landscape orientation */
109+
@page {
110+
size: A4 landscape;
111+
width: 297mm;
112+
height: 210mm;
113+
margin: 1cm;
114+
}
115+
116+
.cheat-sheet {
117+
/* Multi-column layout */
118+
column-count: 4;
119+
column-gap: 1em;
120+
margin-top: 20px;
121+
122+
h1 {
123+
column-span: all;
124+
position: absolute;
125+
top: -10px;
126+
width: 100%;
127+
font-size: 16px;
128+
text-align: center;
129+
}
130+
131+
div.item {
132+
display: block;
133+
width: 100%;
134+
padding: 1px;
135+
margin-bottom: 1px;
136+
break-inside: avoid;
137+
138+
label {
139+
margin-top: 2px;
140+
}
141+
}
142+
143+
/* Manual column break controls */
144+
.print-break-before {
145+
break-before: column;
146+
}
147+
}
148+
}
149+
150+
div#main .pdf-link img {
151+
float: right;
152+
height: 36px;
153+
}

content/cheat-sheet/_index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ <h3>Commit all unstaged changes:</h3>
113113
</div>
114114
</section>
115115

116-
<section>
116+
<section class="print-break-before">
117117
<h2 id="move-between-branches">Move Between Branches</h2>
118118
<div class="item">
119119
<h3>Switch branches:</h3>
@@ -181,7 +181,7 @@ <h3>Show a summary of a diff:</h3>
181181
<code>git show &lt;commit&gt; --stat</code>
182182
</div>
183183
</section>
184-
<section class="commit-reference">
184+
<section class="commit-reference print-break-before">
185185
<h2 id="ways-to-refer-to-a-commit">Ways to refer to a commit</h2>
186186
<p class="intro">
187187
Every time we say <code>&lt;commit&gt;</code>, you can use any of these:
@@ -236,7 +236,7 @@ <h3>'Stash' all staged and unstaged changes:</h3>
236236
</div>
237237
</section>
238238

239-
<section>
239+
<section class="print-break-before">
240240
<h2 id="edit-history">Edit History</h2>
241241
<div class="item">
242242
<h3>"Undo" the most recent commit (keep your working directory the same):</h3>
@@ -285,7 +285,7 @@ <h3>Show who last changed each line of a file:</h3>
285285
</div>
286286
</section>
287287

288-
<section>
288+
<section class="print-break-before">
289289
<h2 id="combine-diverged-branches">Combine Diverged Branches</h2>
290290
<div class="item">
291291
<h3>Combine with rebase:</h3>
@@ -695,7 +695,7 @@ <h2 id="add-a-remote">Add a Remote</h2>
695695
</div>
696696
</section>
697697

698-
<section>
698+
<section class="print-break-before">
699699
<h2 id="push-your-changes">Push Your Changes</h2>
700700
<div class="item">
701701
<h3>Push the <code>main</code> branch to the remote <code>origin</code>:</h3>
@@ -757,7 +757,7 @@ <h3>See all possible config options:</h3>
757757
</div>
758758
</section>
759759

760-
<section>
760+
<section class="print-break-before">
761761
<h2 id="important-files">Important Files</h2>
762762
<div class="item">
763763
<h3>Local git config:</h3>

0 commit comments

Comments
 (0)