first commit

This commit is contained in:
2026-02-18 14:07:18 +01:00
commit c48218e225
20 changed files with 10641 additions and 0 deletions

11
src/content/config.ts Normal file
View File

@@ -0,0 +1,11 @@
// @ts-ignore
import { defineCollection, z } from 'astro:content';
const posts = defineCollection({
// Type-check frontmatter using a schema
schema: z.object({
title: z.string(),
}),
});
export const collections = { posts };

View File

@@ -0,0 +1,6 @@
---
title: First post
---
First!
You can edit this page in the [Admin UI](/keystatic/collection/posts/item/first-post), or directly in your IDE at `src/content/posts/first-post.mdoc`.

2
src/env.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />

24
src/layouts/Layout.astro Normal file
View File

@@ -0,0 +1,24 @@
---
import '../styles.css'
export interface Props {
title: string;
}
const { title } = Astro.props;
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="description" content="Astro description">
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
<body>
<slot />
</body>
</html>

29
src/pages/index.astro Normal file
View File

@@ -0,0 +1,29 @@
---
import { getCollection } from 'astro:content';
import Layout from '../layouts/Layout.astro';
const posts = await getCollection('posts');
---
<Layout title="Keystatic & Astro's Content Collections">
<div>
<h1>Keystatic ⚡️ + Astro 🚀</h1>
<p>
This homepage shows how to load data from Astro's content collections.
</p>
<p>
<a href="/keystatic">Click here to visit the Admin UI</a>, or the link
below to view a post in the collection.
</p>
<h2>Posts</h2>
<ul>
{
posts.map(post => (
<li>
<a href={`/posts/${post.slug}`}>{post.data.title}</a>
</li>
))
}
</ul>
</div>
</Layout>

View File

@@ -0,0 +1,22 @@
---
import { getCollection, getEntry } from 'astro:content';
import Layout from '../../layouts/Layout.astro';
const { slug } = Astro.params;
if (!slug) throw new Error('Slug not found');
const post = await getEntry('posts', slug);
if (!post) throw new Error('No post found for this slug');
const { Content } = await post.render();
// Generate static pages
export async function getStaticPaths() {
const posts = await getCollection('posts');
return posts.map(post => ({ params: { slug: post.slug } }));
}
---
<Layout title={post.data.title}>
<h1>{post.data.title}</h1>
<Content />
</Layout>

29
src/styles.css Normal file
View File

@@ -0,0 +1,29 @@
html {
max-width: 70ch;
padding: 3rem 1rem;
margin: auto;
line-height: 1.75;
font-size: 1.25rem;
font-family: sans-serif;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 1rem 0 1rem;
}
p,
ul,
ol {
margin-bottom: 1rem;
color: #1d1d1d;
}
img {
height: auto;
max-width: 100%;
}