Skip to content

Commit 52f5ee9

Browse files
committed
perf: calculate heading font size dynamically (#983)
1 parent b3c4d74 commit 52f5ee9

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

_includes/related-posts.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ <h3 class="pt-2 mb-4 ms-1" data-toc-skip>
8686
<a href="{{ post.url | relative_url }}" class="card post-preview h-100">
8787
<div class="card-body">
8888
{% include datetime.html date=post.date class="small" lang=include.lang %}
89-
<h3 class="pt-0 my-2" data-toc-skip>{{ post.title }}</h3>
89+
<h4 class="pt-0 my-2" data-toc-skip>{{ post.title }}</h4>
9090
<div class="text-muted small">
9191
<p>
9292
{% include no-linenos.html content=post.content %}

_sass/addon/commons.scss

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,27 @@ body {
3939

4040
/* --- Typography --- */
4141

42-
h1 {
43-
@extend %heading;
44-
45-
font-size: 1.9rem;
46-
}
47-
48-
h2 {
49-
@extend %heading;
50-
@extend %section;
51-
@extend %anchor;
52-
53-
font-size: 1.5rem;
54-
}
55-
56-
h3 {
57-
@extend %heading;
58-
@extend %section;
59-
@extend %anchor;
60-
61-
font-size: 1.2rem;
62-
}
42+
@for $i from 1 through 5 {
43+
h#{$i} {
44+
@extend %heading;
6345

64-
h4 {
65-
@extend %heading;
66-
@extend %section;
67-
@extend %anchor;
46+
@if $i > 1 {
47+
@extend %section;
48+
@extend %anchor;
49+
}
6850

69-
font-size: 1.15rem;
70-
}
51+
@if $i < 5 {
52+
$factor: 0.18rem;
7153

72-
h5 {
73-
@extend %heading;
74-
@extend %section;
75-
@extend %anchor;
54+
@if $i == 1 {
55+
$factor: 0.23rem;
56+
}
7657

77-
font-size: 1.1rem;
58+
font-size: 1rem + (5 - $i) * $factor;
59+
} @else {
60+
font-size: 1rem;
61+
}
62+
}
7863
}
7964

8065
a {

_sass/layout/post.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ h1 + .post-meta {
348348
}
349349

350350
.card {
351-
h3 {
351+
h4 {
352352
@extend %text-color;
353353
@extend %text-clip;
354354
}

0 commit comments

Comments
 (0)