feat(blog): content collection, index, post layout, RSS
Adds the blog system ahead of the launch post: a zod-typed `blog` content collection (content layer glob loader), a card-list index with a calm empty state, the post route/layout with reading time, and an RSS feed — all wired to the existing Base shell and palette. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
7 files changed
+273
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import { defineCollection, z } from 'astro:content';
|
||||
import { glob } from 'astro/loaders';
|
||||
|
||||
const blog = defineCollection({
|
||||
loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: './src/content/blog' }),
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
pubDate: z.coerce.date(),
|
||||
updatedDate: z.coerce.date().optional(),
|
||||
author: z.string().default('Diego Reséndez'),
|
||||
tags: z.array(z.string()).optional(),
|
||||
draft: z.boolean().default(false),
|
||||
heroImage: z.string().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const collections = { blog };
|
||||
Whitespace-only changes.
@@ -0,0 +1,99 @@
|
||||
---
|
||||
import Base from './Base.astro';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
description: string;
|
||||
pubDate: Date;
|
||||
updatedDate?: Date;
|
||||
author: string;
|
||||
tags?: string[];
|
||||
heroImage?: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
const { title, description, pubDate, updatedDate, author, tags, heroImage, body } = Astro.props;
|
||||
|
||||
const dateFormat = new Intl.DateTimeFormat('en-US', { month: 'long', day: 'numeric', year: 'numeric' });
|
||||
|
||||
const wordCount = body.trim().split(/\s+/).filter(Boolean).length;
|
||||
const readingTime = Math.max(1, Math.round(wordCount / 200));
|
||||
---
|
||||
|
||||
<Base title={`${title} — Green Tea. Blog`} description={description} image={heroImage}>
|
||||
<article class="post section">
|
||||
<div class="wrap prose">
|
||||
<p class="post-nav"><a href="/blog/">← Back to the blog</a></p>
|
||||
<h1>{title}</h1>
|
||||
<p class="post-meta">
|
||||
<time datetime={pubDate.toISOString()}>{dateFormat.format(pubDate)}</time>
|
||||
<span aria-hidden="true"> · </span>
|
||||
{author}
|
||||
<span aria-hidden="true"> · </span>
|
||||
{readingTime} min read
|
||||
{
|
||||
updatedDate && (
|
||||
<>
|
||||
<span aria-hidden="true"> · </span>
|
||||
<span>Updated {dateFormat.format(updatedDate)}</span>
|
||||
</>
|
||||
)
|
||||
}
|
||||
</p>
|
||||
{tags && tags.length > 0 && (
|
||||
<p class="post-tags">
|
||||
{tags.map((tag) => <span class="tag">{tag}</span>)}
|
||||
</p>
|
||||
)}
|
||||
<div class="post-body">
|
||||
<slot />
|
||||
</div>
|
||||
<p class="post-back"><a href="/blog/">← Back to the blog</a></p>
|
||||
</div>
|
||||
</article>
|
||||
</Base>
|
||||
|
||||
<style>
|
||||
.post-nav {
|
||||
font-size: 0.9rem;
|
||||
margin: 0 0 1.5em;
|
||||
}
|
||||
|
||||
.post-nav a {
|
||||
color: var(--dim);
|
||||
}
|
||||
|
||||
.post-nav a:hover,
|
||||
.post-nav a:focus-visible {
|
||||
color: var(--matcha);
|
||||
}
|
||||
|
||||
.post-meta {
|
||||
color: var(--dim);
|
||||
font-size: 0.95rem;
|
||||
margin: 0 0 1.5em;
|
||||
}
|
||||
|
||||
.post-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5em;
|
||||
margin: 0 0 1.5em;
|
||||
}
|
||||
|
||||
.tag {
|
||||
display: inline-block;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
color: var(--matcha);
|
||||
background: var(--panel);
|
||||
border-radius: 6px;
|
||||
padding: 0.25em 0.6em;
|
||||
}
|
||||
|
||||
.post-back {
|
||||
margin-top: 3em;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
import { getCollection, render } from 'astro:content';
|
||||
import Post from '../../layouts/Post.astro';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection('blog', ({ data }) => !data.draft);
|
||||
|
||||
return posts.map((post) => ({
|
||||
params: { slug: post.id },
|
||||
props: { post },
|
||||
}));
|
||||
}
|
||||
|
||||
const { post } = Astro.props;
|
||||
const { Content } = await render(post);
|
||||
---
|
||||
|
||||
<Post
|
||||
title={post.data.title}
|
||||
description={post.data.description}
|
||||
pubDate={post.data.pubDate}
|
||||
updatedDate={post.data.updatedDate}
|
||||
author={post.data.author}
|
||||
tags={post.data.tags}
|
||||
heroImage={post.data.heroImage}
|
||||
body={post.body ?? ''}
|
||||
>
|
||||
<Content />
|
||||
</Post>
|
||||
@@ -0,0 +1,99 @@
|
||||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
import Base from '../../layouts/Base.astro';
|
||||
|
||||
const title = 'Blog — Green Tea.';
|
||||
const description = 'Notes on building a zen, opinionated, type-safe HTTP framework.';
|
||||
|
||||
const posts = (await getCollection('blog', ({ data }) => !data.draft)).sort(
|
||||
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
|
||||
);
|
||||
|
||||
const dateFormat = new Intl.DateTimeFormat('en-US', { month: 'long', day: 'numeric', year: 'numeric' });
|
||||
---
|
||||
|
||||
<Base title={title} description={description}>
|
||||
<section class="section">
|
||||
<div class="wrap">
|
||||
<p class="kicker">Blog</p>
|
||||
<h1>From the garden</h1>
|
||||
|
||||
{
|
||||
posts.length === 0 ? (
|
||||
<p class="empty-state">No posts yet.</p>
|
||||
) : (
|
||||
<ul class="post-list">
|
||||
{posts.map((post) => (
|
||||
<li class="post-card">
|
||||
<h2>
|
||||
<a href={`/blog/${post.id}/`}>{post.data.title}</a>
|
||||
</h2>
|
||||
<p class="post-card-meta">
|
||||
<time datetime={post.data.pubDate.toISOString()}>{dateFormat.format(post.data.pubDate)}</time>
|
||||
</p>
|
||||
<p class="post-card-description">{post.data.description}</p>
|
||||
{post.data.tags && post.data.tags.length > 0 && (
|
||||
<p class="post-card-tags">
|
||||
{post.data.tags.map((tag) => (
|
||||
<span class="tag">{tag}</span>
|
||||
))}
|
||||
</p>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
</Base>
|
||||
|
||||
<style>
|
||||
.empty-state {
|
||||
color: var(--dim);
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.post-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2.5rem;
|
||||
max-width: 70ch;
|
||||
}
|
||||
|
||||
.post-card h2 {
|
||||
margin-bottom: 0.3em;
|
||||
}
|
||||
|
||||
.post-card-meta {
|
||||
color: var(--dim);
|
||||
font-size: 0.9rem;
|
||||
margin: 0 0 0.6em;
|
||||
}
|
||||
|
||||
.post-card-description {
|
||||
margin: 0 0 0.6em;
|
||||
}
|
||||
|
||||
.post-card-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.tag {
|
||||
display: inline-block;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
color: var(--matcha);
|
||||
background: var(--panel);
|
||||
border-radius: 6px;
|
||||
padding: 0.25em 0.6em;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,19 @@
|
||||
import rss from '@astrojs/rss';
|
||||
import { getCollection } from 'astro:content';
|
||||
|
||||
export async function GET(context) {
|
||||
const posts = await getCollection('blog', ({ data }) => !data.draft);
|
||||
const sorted = posts.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
|
||||
|
||||
return rss({
|
||||
title: 'Green Tea — Blog',
|
||||
description: 'Notes on building a zen, opinionated, type-safe HTTP framework.',
|
||||
site: context.site,
|
||||
items: sorted.map((post) => ({
|
||||
title: post.data.title,
|
||||
description: post.data.description,
|
||||
pubDate: post.data.pubDate,
|
||||
link: `/blog/${post.id}/`,
|
||||
})),
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user