blob: b0164bb36d0f9dd4f2fbd7a070f75b43b28cf9be (
plain)
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
|
---
import type { CollectionEntry } from "astro:content";
import {
getFlagEmojiFromLocale,
getLanguageNameFromLocale,
} from "../utils/lang";
import { getEntries } from "astro:content";
interface Props {
lang: string;
translations?: CollectionEntry<"blog">["data"]["translations"];
}
const { lang } = Astro.props;
const translations = await getEntries(Astro.props.translations ?? []).then(
(translations) =>
translations.sort((x, y) => x.data.lang.localeCompare(y.data.lang)),
);
---
{
/* TODO: What about <https://schema.org/translationOfWork> and <https://schema.org/translator>? */
}
{
translations.length > 0 && (
<aside>
<nav>
<p>Traduções:</p>
<ul class="translations">
{
translations.map(async (
{ data, collection, id },
) => {
const active = lang.localeCompare(data.lang) === 0;
return (
<li
itemprop={active ? undefined : "workTranslation"}
itemscope={!active}
itemtype={active ? undefined : "http://schema.org/BlogPosting"}
itemid={active
? undefined
: new URL(`${collection}/read/${id}`, Astro.site).href}
>
<a
href={`/${collection}/read/${id}`}
class:list={[{ active }]}
rel={active ? undefined : "alternate"}
hreflang={active ? undefined : data.lang}
type="text/html"
title={data.title}
><span class="emoji">{getFlagEmojiFromLocale(data.lang)}</span>
{getLanguageNameFromLocale(data.lang)} (<span
itemprop="inLanguage"
>{data.lang}</span>)</a>
</li>
);
})
}
</ul>
</nav>
</aside>
)
}
<style>
.translations {
list-style-type: none;
padding-inline-start: 0;
}
.translations > li {
display: inline;
}
.translations > li > a > .emoji {
text-decoration: none;
font-family: var(--ff-icons);
}
.translations > li > a.active {
font-weight: bolder;
text-decoration: underline;
color: var(--color-active);
}
nav:has(.translations) {
display: flex;
gap: 1rem;
}
nav:has(.translations) > * {
font-size: smaller;
}
.translations > li:not(:first-child)::before {
content: "|";
margin-inline: 0.5em;
}
@media print {
aside {
display: none;
}
}
</style>
|