1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
---
import Date from "@components/organisms/Date.astro";
import KeywordsList from "@components/organisms/KeywordsList.astro";
import {
getFirstUserID,
getLastUpdate,
getTranslationOriginal,
isMicro,
isTranslation,
} from "@lib/collection/helpers";
import type { CollectionEntry } from "astro:content";
interface Props {
posts: CollectionEntry<"blog">[];
small?: boolean;
dateOptions?: Intl.DateTimeFormatOptions;
}
const {
posts,
small = false,
dateOptions = { year: "numeric", month: "long", day: "numeric" },
} = Astro.props;
---
<ol class:list={{ "remove-nums": !small }}>
{
await Promise.all(
posts.map(
async (post) => {
const { id, data } = post;
const { title, lang } = data;
const description = isMicro(post)
? post.rendered?.html
: ("description" in data ? data.description : undefined);
const keywords = isTranslation(post)
? await getTranslationOriginal(post).then((x) =>
x?.data?.keywords
)
: ("keywords" in data ? data.keywords : undefined);
const { name, email, entity } = await getFirstUserID(post);
const display = name ?? email ?? entity;
return (
<li>
<article
itemprop="blogPost"
itemscope
itemtype="https://schema.org/BlogPosting"
>
<h3>
<a href={`/blog/read/${id}`} itemprop="headline name">{title}</a>
</h3>
{
description && (
<div itemprop="abstract">
{
isMicro(post)
? <Fragment set:html={description} />
: description.split("\n\n").map((
paragraph,
) => <p class:list={{ small }}>{paragraph}</p>)
}
</div>
)
}
<footer class="small">
<Date
date={getLastUpdate(post)}
locales={lang}
options={dateOptions}
itemprop="dateModified"
/><span
itemprop="author"
itemscope
itemtype="https://schema.org/Person"
><span itemprop="alternateName">{display}</span></span>
{Array.isArray(keywords) && <KeywordsList {keywords} />}
</footer>
</article>
</li>
);
},
),
)
}
</ol>
<style>
ol {
margin-inline-start: calc(var(--size-7) * 1em);
margin-block: calc(var(--size-7) * 1em);
& > li {
margin-block-start: calc(var(--size-2) * 1em);
& > article {
padding-inline-end: calc(var(--size-9) * 1em);
& > [itemprop="abstract"] > p:not(:first-of-type) {
margin-block-start: 1.5em;
}
& > footer {
display: flex;
flex-direction: column;
gap: calc(var(--size-1) * 1em);
}
}
}
& > li:not(:first-of-type) {
border-block-start: 1px solid var(--color-dark);
}
}
ol.remove-nums {
margin-inline-start: 0;
& > li {
margin-inline-end: calc(var(--size-7) * 1em);
& > article {
padding-inline-end: 0;
}
}
}
@media (width >= 40rem) {
ol > li > article > footer {
flex-direction: row;
align-items: center;
justify-content: space-between;
}
}
</style>
|