fix: cover as public-path string (Sveltia uploads) + render cover in article
This commit is contained in:
+11
-10
@@ -6,16 +6,17 @@ import { glob } from 'astro/loaders';
|
|||||||
// renders them to static HTML at build time.
|
// renders them to static HTML at build time.
|
||||||
const news = defineCollection({
|
const news = defineCollection({
|
||||||
loader: glob({ pattern: '**/*.md', base: './src/content/news' }),
|
loader: glob({ pattern: '**/*.md', base: './src/content/news' }),
|
||||||
schema: ({ image }) =>
|
schema: z.object({
|
||||||
z.object({
|
title: z.string(),
|
||||||
title: z.string(),
|
description: z.string(),
|
||||||
description: z.string(),
|
date: z.coerce.date(),
|
||||||
date: z.coerce.date(),
|
category: z.string().default('news'),
|
||||||
category: z.string().default('news'),
|
author: z.string().default('CTAO'),
|
||||||
author: z.string().default('CTAO'),
|
// Public-path string, e.g. "/uploads/foo.jpg" — Sveltia uploads media to
|
||||||
cover: image().optional(),
|
// public/uploads, which Astro's image() helper can't validate (src/ only).
|
||||||
draft: z.boolean().default(false),
|
cover: z.string().optional(),
|
||||||
}),
|
draft: z.boolean().default(false),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const collections = { news };
|
export const collections = { news };
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const fmt = (d) => new Intl.DateTimeFormat('pl-PL', { dateStyle: 'long' }).forma
|
|||||||
<a class="back" href="/">← Wszystkie newsy</a>
|
<a class="back" href="/">← Wszystkie newsy</a>
|
||||||
<h1>{post.data.title}</h1>
|
<h1>{post.data.title}</h1>
|
||||||
<div class="meta">{post.data.category} · {post.data.author} · {fmt(post.data.date)}</div>
|
<div class="meta">{post.data.category} · {post.data.author} · {fmt(post.data.date)}</div>
|
||||||
|
{post.data.cover && <img class="cover" src={post.data.cover} alt="" />}
|
||||||
<div class="prose">
|
<div class="prose">
|
||||||
<Content />
|
<Content />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ img { max-width: 100%; height: auto; display: block; }
|
|||||||
line-height: 1.15; letter-spacing: -0.02em;
|
line-height: 1.15; letter-spacing: -0.02em;
|
||||||
}
|
}
|
||||||
.article .meta { color: var(--muted); font-size: 0.9rem; margin-bottom: 28px; }
|
.article .meta { color: var(--muted); font-size: 0.9rem; margin-bottom: 28px; }
|
||||||
|
.article .cover { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 28px; }
|
||||||
.prose h2 { margin: 34px 0 10px; font-size: 1.45rem; letter-spacing: -0.01em; }
|
.prose h2 { margin: 34px 0 10px; font-size: 1.45rem; letter-spacing: -0.01em; }
|
||||||
.prose h3 { margin: 26px 0 8px; font-size: 1.15rem; }
|
.prose h3 { margin: 26px 0 8px; font-size: 1.15rem; }
|
||||||
.prose p { margin: 0 0 16px; }
|
.prose p { margin: 0 0 16px; }
|
||||||
|
|||||||
Reference in New Issue
Block a user