Skip to content

Commit 2fd9252

Browse files
committed
Support cover images and lists
1 parent b64a332 commit 2fd9252

File tree

10 files changed

+54
-24
lines changed

10 files changed

+54
-24
lines changed

astro.config.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
import { defineConfig } from 'astro/config';
33

44
// https://astro.build/config
5-
export default defineConfig({});
5+
export default defineConfig({
6+
image: {
7+
responsiveStyles: true,
8+
layout: 'constrained',
9+
breakpoints: [400, 640, 750, 828, 1080, 1280, 1668, 2048, 2560],
10+
},
11+
});
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
import { render, type CollectionEntry } from 'astro:content'
3-
import formatDate from '../../util/formatDate';
3+
import formatDate from '../util/formatDate';
44
import TagCluster from './TagCluster.astro';
5+
import { Image } from 'astro:assets';
56
67
interface Props {
78
post: CollectionEntry<'blog'>;
@@ -17,6 +18,9 @@ const { Content } = await render(post);
1718
<header>
1819
<h1>{post.data.title}</h1>
1920
<p>{pubDate}</p>
21+
{post.data.cover !== undefined &&
22+
<Image src={post.data.cover} alt={post.data.coverAlt ?? null} />
23+
}
2024
<TagCluster />
2125
</header>
2226
<div class="content">
@@ -25,15 +29,7 @@ const { Content } = await render(post);
2529
</article>
2630

2731
<style lang="scss">
28-
@use '../../styles/_theme' as *;
29-
30-
article {
31-
padding: $space-lg 0;
32-
}
33-
34-
header, .content {
35-
padding-inline: $space-md;
36-
}
32+
@use '../styles/_theme' as *;
3733

3834
header {
3935
margin-bottom: $space-md;
@@ -49,6 +45,11 @@ const { Content } = await render(post);
4945
p {
5046
@include font-technical;
5147
}
48+
49+
img {
50+
padding: 0;
51+
margin: 0;
52+
}
5253
}
5354

5455
.content {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import BearIcon from "../icons/BearIcon.astro";
2+
import BearIcon from "./icons/BearIcon.astro";
33
---
44

55
<header>
@@ -13,7 +13,7 @@ import BearIcon from "../icons/BearIcon.astro";
1313
</header>
1414

1515
<style lang="scss">
16-
@use '../../styles/_theme' as *;
16+
@use '../styles/_theme' as *;
1717

1818
header {
1919
padding: $space-lg $space-md;
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
</ul>
66

77
<style lang="scss">
8-
@use '../../styles/_theme' as *;
8+
@use '../styles/_theme' as *;
99

1010
ul {
11-
padding-inline-start: 0;
11+
padding-inline-start: $space-md;
1212

1313
li {
1414
display: inline-block;
15+
margin: 0;
1516
padding: $space-sm;
17+
1618
border: $border-thickness solid $color-subtle;
1719
border-radius: $border-radius;
18-
box-shadow: 0 $shadow-offset $color-subtle;
20+
box-shadow: 0 $border-thickness $color-subtle;
1921
}
2022
}
2123
</style>

src/content.config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { defineCollection, z } from "astro:content";
1+
import { defineCollection, z, type SchemaContext } from "astro:content";
22

33
import { glob } from 'astro/loaders';
44

55
const blog = defineCollection({
66
loader: glob({ pattern: '**/*.md', base: './src/content/posts' }),
7-
schema: z.object({
7+
schema: ({ image }) => z.strictObject({
88
title: z.string(),
99
pubDate: z.coerce.date(),
10-
})
10+
cover: image().optional(),
11+
coverAlt: z.string().optional(),
12+
}),
1113
});
1214

1315
export const collections = { blog };

src/content/posts/building-a-blog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Suspendisse facilisis, mi ac scelerisque interdum, ligula ex imperdiet felis, a
1111

1212
Nullam consequat, dui in tristique accumsan, lorem nulla eleifend elit, vel volutpat mauris orci a elit. Suspendisse auctor volutpat ex, eu bibendum nisi feugiat vitae. Vestibulum dapibus varius neque, vitae placerat ex tincidunt quis. Nullam vehicula diam non efficitur pretium. Morbi est enim, consequat nec magna interdum, malesuada elementum erat. Vestibulum a elit mauris. Proin a orci et risus fermentum ultrices. Nullam congue convallis lacus et tincidunt.
1313

14+
Eget at nec:
15+
16+
- Ut sem mi, suscipit quis nisi a.
17+
- Orci egestas varius neque.
18+
- Non feugiat turpis eleifend tristique.
19+
1420
Etiam quis massa non massa sagittis accumsan eget at tellus. Quisque non fringilla magna, in tincidunt ligula. Nullam euismod, odio non luctus suscipit, neque quam mollis diam, in consequat augue mauris vitae nunc. Vestibulum consectetur quam ante. Donec vulputate dolor in odio ultricies, ut venenatis lorem luctus. Sed quis tellus risus. Nullam quis mi vitae nibh malesuada blandit. Duis sit amet tortor interdum, sodales est ut, pellentesque mi.
1521

1622
Mauris non enim consectetur, ultrices lacus gravida, imperdiet lacus. Duis eget nulla nec turpis euismod laoreet. Nam tristique sem in elit lacinia tristique. Ut sem mi, suscipit quis nisi a, finibus ultrices eros. Donec sed ultricies est. Nullam volutpat metus sed dui lobortis tincidunt. Pellentesque rutrum maximus libero non luctus. Pellentesque id felis quis lacus varius tempus. Phasellus a est et justo mattis molestie a ac augue. Sed at purus erat. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec dapibus eget nulla eu venenatis.

src/layouts/BaseLayout.astro

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
import LinkFonts from '../components/meta/LinkFonts.astro';
3-
import Header from '../components/sections/Header.astro';
3+
import Header from '../components/Header.astro';
44
import '../styles/_normalise.scss';
55
import '../styles/global.scss';
66
---
@@ -24,3 +24,11 @@ import '../styles/global.scss';
2424
</main>
2525
</body>
2626
</html>
27+
28+
<style lang="scss">
29+
@use '../styles/_theme' as *;
30+
31+
main {
32+
padding: $space-lg 0;
33+
}
34+
</style>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { GetStaticPaths } from "astro";
33
import { getCollection, type CollectionEntry } from "astro:content";
44
import BaseLayout from "../../layouts/BaseLayout.astro";
5-
import BlogPost from "../../components/sections/BlogPost.astro";
5+
import BlogPost from "../../components/BlogPost.astro";
66
77
interface Props {
88
post: CollectionEntry<"blog">;
@@ -11,7 +11,7 @@ interface Props {
1111
export const getStaticPaths: GetStaticPaths = async () => {
1212
const posts = await getCollection("blog");
1313
return posts.map((post) => ({
14-
params: { id: post.id },
14+
params: { slug: post.id },
1515
props: { post },
1616
}));
1717
};

src/styles/_theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ $size-2xl: 2.4rem;
5151
// Decoration
5252

5353
$shadow-offset: 1px;
54-
$shadow-blur: 2px;
54+
$shadow-blur: 6px;
5555

5656
$border-thickness: 1px;
5757
$border-radius: 2px;

src/styles/global.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
font-size: $size-md;
1313
}
1414

15-
h1, h2, h3, h4, h5, h6, p, ul, ol {
15+
h1, h2, h3, h4, h5, h6, p {
16+
padding-inline: $space-md;
1617
@include space-between($space-md);
1718
}
1819

20+
li {
21+
@include space-between($space-sm);
22+
}
23+
1924
h1, h2, h3, h4, h5, h6 {
2025
@include font-display;
2126
font-size: $size-lg;

0 commit comments

Comments
 (0)