Skip to content

Commit 7e03e22

Browse files
committed
add bg_color
1 parent 097e486 commit 7e03e22

File tree

5 files changed

+73
-28
lines changed

5 files changed

+73
-28
lines changed

contents/articles/2024/12-21_kick-off-party-report/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ categories:
66
image: ./image.jpg
77
author: snakamura
88
fit: contain
9+
bg_color: "#00693E"
910
---
1011

1112
ut.code(); では 2024 年 12 月 21 日にプロジェクト発足会を行いました。

contents/articles/2025/03-24_joint-welcome-session/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
title: 東大エンジニア系サークル合同新歓を開催します
33
image: ./thumbnail.png
44
categories:
5-
- event
5+
- event
66
author: ykobayashi
77
date: 2025-03-24
8+
fit: contain
9+
bg_color: "#A5FFD3"
810
---
911

1012
## 📌 イベント概要

contents/articles/README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,35 @@
22

33
## frontmatter
44

5-
| キー | 必須 | 説明 |
6-
| ------------- | ---- | ---|
7-
| `title` || 記事タイトル|
8-
| `date` || **記事を書いた** 日。|
9-
| `image` || イメージ画像 |
10-
| `fit` | | (画像) object-fit。 default = "cover" |
11-
| `position` | | (画像) object-position。 (縦軸上から 横軸左から)。default = "50% 50%" |
12-
| `categories` | | 何なんだろうね。 |
13-
| `author`| | 著者の id |
14-
15-
## 画像
16-
17-
縦横比 3:5 に crop されます。
5+
### base
6+
7+
- title: string
8+
- 記事タイトル。
9+
10+
- date: Date
11+
- **記事を書いた**日。
12+
13+
- author: string & keyof Member
14+
- 著者。
15+
16+
- categories: string[]
17+
- 何なんだろうね。
18+
19+
### image 系
20+
21+
- image: path
22+
- タイトル画像。記事一覧とトップで使うよ。
23+
- 縦横比 3:5 に crop されるよ。
24+
25+
- fit?: "cover" | "contain" | fill" | "none" = "cover"
26+
- `object-fit`
27+
- Astro のビルド段階で Sharp に渡されるよ。
28+
- <https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit>
29+
30+
- position?: "center" | "left" | "right" | "top" | "bottom"
31+
- `object-position`
32+
- Astro のビルド段階で Sharp に渡されるよ。
33+
34+
- bg_color?: string
35+
- ロード中や画像の漏れたところに見せる背景色。
36+
- 設定しないと DaisyUI の `skeleton` を使うよ。

src/components/ArticleList.astro

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ const articlesWithExcerpts = await Promise.all(
5656
const imageWidth = baseW * (isFeatured ? 2 : 1);
5757
const imageHeight = baseW * (3 / 5) * (isFeatured ? 2 : 1);
5858

59+
console.log(article.data.bg_color);
60+
5961
article.data.fit ??= "cover";
6062
article.data.position ??= "center";
61-
console.log(article.data);
6263

6364
const additionalProps = isFeatured
6465
? {
@@ -90,10 +91,18 @@ const articlesWithExcerpts = await Promise.all(
9091
fit={article.data.fit}
9192
src={article.data.image}
9293
class:list={[
93-
"skeleton min-h-0 w-full rounded-xl",
94+
"min-h-0 w-full rounded-xl",
95+
!article.data["bg_color"] && "skeleton",
9496
additionalProps.imageClassName,
9597
]}
96-
style={`aspect-ratio: 5 / 3; object-fit: ${article.data.fit}; object-position: ${article.data.position}`}
98+
style={`
99+
aspect-ratio: 5 / 3;
100+
object-fit: ${article.data.fit};
101+
${
102+
article.data.bg_color
103+
? `background-color: ${article.data.bg_color}`
104+
: ""
105+
}`}
97106
/>
98107
<div class="mt-4 p-1">
99108
<time class="block text-sm text-gray-500">

src/schema.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,31 @@ export type Member = z.infer<ReturnType<typeof CreateMemberSchema>>;
77
export type Project = z.infer<ReturnType<typeof CreateProjectSchema>>;
88

99
export const CreateArticleSchema = ({ image }: { image: ImageFunction }) =>
10-
z.object({
11-
date: z
12-
.date()
13-
.transform((date) => new TZDate(date).withTimeZone("Asia/Tokyo")),
14-
title: z.string(),
15-
fit: z.string().optional(),
16-
position: z.string().optional(),
17-
image: image(),
18-
categories: z.array(z.string()).optional(),
19-
author: reference("members").optional(),
20-
});
10+
z
11+
.object({
12+
// base
13+
title: z.string(),
14+
date: z
15+
.date()
16+
.transform((date) => new TZDate(date).withTimeZone("Asia/Tokyo")),
17+
author: reference("members").optional(),
18+
categories: z.array(z.string()).optional(),
19+
// 画像系
20+
image: image(),
21+
fit: z.enum(["cover", "contain", "fill", "none"]).optional(),
22+
position: z.enum(["center", "top", "bottom", "left", "right"]).optional(),
23+
bg_color: z.string().optional(),
24+
})
25+
.refine(
26+
(self) => {
27+
const bad = self.fit === "contain" && self.bg_color === undefined;
28+
return !bad;
29+
},
30+
{
31+
message: "fit: contain の場合、 bg_color を指定する必要があります",
32+
path: ["bg_color"],
33+
},
34+
);
2135

2236
export const CreateProjectSchema = ({ image }: { image: ImageFunction }) =>
2337
z.object({

0 commit comments

Comments
 (0)