Skip to content

Commit 75a504b

Browse files
committed
Add cover image to the top of a post.
1 parent 1e2337f commit 75a504b

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

.changeset/better-dots-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'hexo-theme-cupertino': minor
3+
---
4+
5+
Add cover image to the top of a post.

layout/post.ejs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
<%- partial('_partial/categories') %>
77
<% } else { %>
88
<article class="post">
9+
<% if (page.cover_image) { %>
10+
<div class="cover">
11+
<img src="<%= page.cover_image %>" alt="<%= page.cover_image_alt %>" class="cover-img" data-pagefind-meta="image[src], image_alt[alt]" />
12+
</div>
13+
<% } %>
914
<div class="meta">
1015
<% if (page.categories && page.categories.length) { %>
1116
<div class="categories<%= theme.uppercase_categories ? ' text-uppercase' : '' %>">

source/css/post.scss

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
body {
2+
margin-top: 0;
3+
}
4+
15
.post {
26
margin-bottom: 64px;
37
}
@@ -45,6 +49,45 @@
4549
@include meta('.title', '.date', '.categories');
4650

4751
.post {
52+
& > .cover {
53+
max-width: 100%;
54+
overflow: clip visible;
55+
56+
& > .cover-img {
57+
--h: 300px;
58+
mask-image: linear-gradient(to bottom, #000, transparent);
59+
mask-composite: destination-in;
60+
height: var(--h);
61+
margin-bottom: calc(var(--h) * -0.6);
62+
object-fit: cover;
63+
64+
@supports (animation-timeline: scroll()) {
65+
--range: calc(var(--h) * 3);
66+
--offset-coefficient: 0.4;
67+
68+
@keyframes cover-exit {
69+
0% {
70+
}
71+
72+
100% {
73+
opacity: 0;
74+
scale: 1.2;
75+
margin-top: calc(var(--range) * var(--offset-coefficient));
76+
margin-bottom: calc(var(--range) * -1 * var(--offset-coefficient));
77+
filter: var(--filter-blur);
78+
}
79+
}
80+
81+
will-change: filter, margin-top, margin-bottom, opacity, scale;
82+
animation-name: cover-exit;
83+
animation-timing-function: linear;
84+
animation-fill-mode: both;
85+
animation-timeline: scroll();
86+
animation-range: 0 var(--range);
87+
}
88+
}
89+
}
90+
4891
$content: '& > .content';
4992

5093
#{$content} {

0 commit comments

Comments
 (0)