SanYeCao-blog/src/components/Posts/PostItem.astro

281 lines
5.1 KiB
Text
Raw Normal View History

2026-03-24 17:33:01 +00:00
---
2026-03-25 09:01:09 +00:00
import "@/styles/global.css";
2026-04-13 20:02:21 +00:00
import Remark42Counter from "@/components/Remark42Counter.astro";
2026-04-12 22:42:40 +00:00
import { getLangFromUrl } from "@/i18n";
const lang = getLangFromUrl(Astro.url);
2026-03-24 23:40:19 +00:00
const data = Astro.props;
2026-04-12 22:42:40 +00:00
const tags = data.tags;
2026-03-24 17:33:01 +00:00
---
2026-03-24 23:40:19 +00:00
<li class="post-card">
2026-04-12 22:42:40 +00:00
<div class="post-link">
2026-03-24 23:40:19 +00:00
<div class="post-text">
<a href={data.url} class="post-title-link">
2026-04-15 23:43:42 +00:00
<h2 class="post-title" transition:name={`post-title-${data.postId}`}>
{data.title}
</h2>
2026-04-12 22:42:40 +00:00
</a>
<a href={data.url} class="post-description">
{data.description}
</a>
2026-04-15 23:43:42 +00:00
<div class="tags" transition:name={`post-tags-${data.postId}`}>
2026-04-12 22:42:40 +00:00
{
tags.map((tag: string) => (
<p class="tag">
<a href={`/${lang}/tags/${tag}`}>{tag}</a>
</p>
))
}
</div>
2026-03-25 08:43:02 +00:00
<div class="post-meta-row">
<span class="post-date">{data.date}</span>
<span class="post-stats">
<span class="post-stat">
2026-04-13 20:02:21 +00:00
💬 <Remark42Counter url={data.postPath} />
</span>
2026-03-25 08:43:02 +00:00
</span>
</div>
2026-03-24 23:40:19 +00:00
</div>
2026-04-12 22:42:40 +00:00
<a href={data.url} class="post-image-link">
2026-04-15 23:43:42 +00:00
<img
src={data.img}
alt={data.title}
class="post-image"
loading="lazy"
transition:name={`post-image-${data.postId}`}
/>
2026-04-12 22:42:40 +00:00
</a>
</div>
2026-03-24 17:33:01 +00:00
</li>
2026-03-24 23:40:19 +00:00
<div class="section-divider"></div>
2026-03-24 17:33:01 +00:00
<style>
2026-04-12 22:42:40 +00:00
.tags {
display: flex;
flex-wrap: wrap;
gap: 0.4rem;
margin-top: 0.5rem;
margin-bottom: 0.5rem;
}
.tag {
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
Roboto,
Oxygen,
Ubuntu,
Cantarell,
"Open Sans",
"Helvetica Neue",
sans-serif;
margin: 0;
padding: 0.22em 0.65em;
font-size: 1rem;
line-height: 1.2;
border: 1px dashed #8b6b4a;
border-radius: 0;
background-color: transparent;
}
.tag a {
color: #6f4e37;
text-decoration: none;
font-size: 0.8rem;
font-weight: 500;
}
.tag a:hover {
text-decoration: underline;
}
:global(.dark) .tag {
border-color: #d8c7a1;
}
:global(.dark) .tag a {
color: #e6d8b8;
}
:global(.dark) .tag {
border-color: #d8c7a1;
}
:global(.dark) .tag a {
color: #e6d8b8;
}
2026-03-24 23:40:19 +00:00
.post-card {
list-style: none;
margin: 0 0 1rem 0;
padding-left: 0;
2026-04-11 23:26:38 +00:00
padding-bottom: 0.2rem;
padding-top: 0.2rem;
2026-03-24 23:40:19 +00:00
}
.post-link {
2026-03-24 17:33:01 +00:00
display: flex;
justify-content: space-between;
2026-03-24 23:40:19 +00:00
align-items: stretch;
gap: 1rem;
2026-03-24 17:33:01 +00:00
width: 100%;
text-decoration: none;
}
2026-03-24 23:40:19 +00:00
.post-text {
flex: 1;
min-width: 0;
2026-04-12 22:42:40 +00:00
max-width: 40rem;
2026-03-24 23:40:19 +00:00
display: flex;
flex-direction: column;
justify-content: space-between;
line-height: 1.6;
min-height: calc(1.6em * 4);
}
.post-title-link {
text-decoration: none;
display: block;
}
2026-03-24 23:40:19 +00:00
.post-title {
margin: 0;
2026-04-12 22:57:59 +00:00
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
Roboto,
Oxygen,
Ubuntu,
Cantarell,
"Open Sans",
"Helvetica Neue",
sans-serif;
2026-04-12 20:51:15 +00:00
font-weight: 500;
2026-03-25 09:01:09 +00:00
font-size: 1.34rem;
2026-03-24 23:40:19 +00:00
line-height: 1.6;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
2026-03-25 08:43:02 +00:00
.post-description {
color: black;
2026-04-12 22:42:40 +00:00
text-decoration: none;
2026-03-25 08:43:02 +00:00
font-weight: 400;
2026-04-12 22:42:40 +00:00
font-size: 0.92rem;
2026-04-15 23:43:42 +00:00
/* font-style: italic; */
2026-03-25 08:43:02 +00:00
}
.post-meta-row {
display: flex;
align-items: center;
gap: 0.9rem;
flex-wrap: wrap;
}
2026-03-24 23:40:19 +00:00
.post-date {
color: gray;
font-size: 0.95rem;
2026-03-24 17:33:01 +00:00
white-space: nowrap;
2026-03-24 23:40:19 +00:00
line-height: 1.6;
}
2026-03-25 08:43:02 +00:00
.post-stats {
display: inline-flex;
align-items: center;
gap: 0.7rem;
color: #6f8090;
font-size: 0.92rem;
line-height: 1.6;
white-space: nowrap;
}
.post-stat {
display: inline-flex;
align-items: center;
gap: 0.2rem;
}
2026-03-24 23:40:19 +00:00
.post-image {
2026-04-12 22:42:40 +00:00
width: calc((1.6em * 4) * 16 / 10);
2026-03-24 23:40:19 +00:00
height: calc(1.6em * 4);
2026-04-12 22:42:40 +00:00
aspect-ratio: 16 / 10;
2026-03-24 23:40:19 +00:00
object-fit: cover;
object-position: center;
2026-04-15 23:43:42 +00:00
border: 1.5px #94a0ab dashed;
2026-03-24 23:40:19 +00:00
flex-shrink: 0;
display: block;
}
:global(.dark) .post-description {
color: #e6e6e6;
}
2026-03-25 08:43:02 +00:00
:global(.dark) .post-stats {
color: #aab7c4;
}
2026-04-12 22:42:40 +00:00
@media (max-width: 600px) {
2026-03-24 23:40:19 +00:00
.post-link {
display: grid;
2026-04-12 22:42:40 +00:00
grid-template-columns: 1fr 145px;
grid-template-areas:
"title title"
"desc image"
2026-04-12 22:42:40 +00:00
"tags image"
"meta image";
column-gap: 0.75rem;
row-gap: 0.2rem;
align-items: start;
}
.post-text {
display: contents;
min-height: auto;
}
.post-title-link {
grid-area: title;
}
.post-title {
-webkit-line-clamp: 2;
}
.post-description {
grid-area: desc;
}
.post-meta-row {
grid-area: meta;
gap: 0.7rem;
2026-03-24 23:40:19 +00:00
}
.post-image {
2026-04-15 23:43:42 +00:00
/* border: none; */
2026-04-12 22:42:40 +00:00
grid-area: image;
width: 100%;
height: calc(145px * 10 / 16);
align-self: center;
}
.post-image-link {
grid-area: image;
2026-04-12 22:42:40 +00:00
align-self: center;
display: block;
width: 145px;
text-decoration: none;
2026-03-24 17:33:01 +00:00
}
2026-03-24 23:40:19 +00:00
}
</style>