-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathNotice.astro
More file actions
78 lines (64 loc) · 1.89 KB
/
Copy pathNotice.astro
File metadata and controls
78 lines (64 loc) · 1.89 KB
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
---
import { getEntry } from "astro:content";
import Markdown from "@components/utils/Markdown.astro";
import type { Lang } from "@components/types";
import { getISODateString, getLocaleDateString } from "../../util";
/**
* `Markdown`の利用例として紹介されています.
* このコンポーネントを利用しなくなる場合は,`src/components/README.md`を編集して,
* 別の利用例を紹介するようにしてください.
*
* 利用ページ:
* - https://utelecon.adm.u-tokyo.ac.jp/
* - https://utelecon.adm.u-tokyo.ac.jp/notice/
*/
export interface Props {
lang: Lang;
strip?: boolean;
localize?: boolean;
}
interface NoticeContent {
date: Date;
content: string;
id: string;
}
const { lang, strip, localize } = Astro.props;
const { data: noticesWithId } = await getEntry("notices", "notice")!;
const contents: NoticeContent[] = [];
for (const notice of noticesWithId) {
const content = notice.content[lang] ?? notice.content.ja;
if (!content) continue;
if (!strip || contents.length < (notice.important ? 12 : 8)) {
contents.push({ date: notice.date, content, id: notice.id });
}
}
---
<ul class:list={["date_list", {localized: localize}]}>
{
contents.map(({ date, content, id }) => (
<li id={id}>
<span class="date">{localize ? getLocaleDateString(date, lang, "long") : getISODateString(date)}</span>{
}<span class="title"><Markdown content={content} /></span>
</li>
))
}
</ul>
<script>
const target = document.getElementById(location.hash.slice(1));
if (target) target.classList.add("listitem-highlight");
</script>
<style lang="scss">
@use "@styles/color";
.date {
display: inline-block;
width: 6rem;
color: color.$heading-color;
margin-right: 5px;
:where(.date_list).localized & {
width: auto;
}
}
.listitem-highlight {
background-color: yellow;
}
</style>