Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 55 additions & 35 deletions src/content/config.js → src/content.config.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
// 1. Import utilities from `astro:content`
import { z, defineCollection, reference } from 'astro:content';
import { defineCollection } from "astro:content";
import { glob } from "astro/loaders";
import { z } from "astro/zod";

// 2. Define a `type` and `schema` for each collection
const strings = defineCollection({
type: 'data', // v2.5.0 and later
loader: glob({
base: "./src/content/strings",
pattern: "**/*.json",
}),
schema: z.object({
header: z.object({
apps: z.string(),
blog: z.string(),
team: z.string(),
about: z.string()
about: z.string(),
}),
hero: z.object({
title: z.string(),
subtitle: z.string(),
donate: z.string()
donate: z.string(),
}),
profile: z.object({
title: z.string(),
subtitle: z.string(),
about: z.object({
description: z.string()
description: z.string(),
}),
vision: z.object({
title: z.string(),
text: z.string()
text: z.string(),
}),
mission: z.object({
title: z.string(),
text: z.string()
})
text: z.string(),
}),
}),
donation: z.object({
title: z.string(),
Expand All @@ -40,7 +43,7 @@ const strings = defineCollection({
description: z.string(),
hint: z.string(),
label: z.string(),
close: z.string()
close: z.string(),
}),
contributors: z.object({
title: z.string(),
Expand All @@ -51,48 +54,65 @@ const strings = defineCollection({
description: z.string(),
}),
footer: z.object({
copyright: z.string()
})
copyright: z.string(),
}),
}),
});

const apps = defineCollection({
type: "data",
schema: ({ image }) => z.object({
isDraft: z.boolean(),
title: z.string(),
description: z.string(),
featuresTitle: z.string(),
features: z.array(z.string()),
img: image(),
})
})
loader: glob({
base: "./src/content/apps",
pattern: "**/*.json",
}),
schema: ({ image }) =>
z.object({
isDraft: z.boolean(),
title: z.string(),
description: z.string(),
featuresTitle: z.string(),
features: z.array(z.string()),
img: image(),
}),
});

const links = defineCollection({
type: "data",
loader: glob({
base: "./src/content/links",
pattern: "**/*.json",
}),
schema: z.object({
github: z.string().url(),
play: z.string().url().optional(),
fdroid: z.string().url().optional()
})
})
github: z.url(),
play: z.url().optional(),
fdroid: z.url().optional(),
}),
});

const blog = defineCollection({
type: "content",
loader: glob({
base: "./src/content/blog",
pattern: "**/*.{md,mdx}",
}),
schema: ({ image }) =>
z.object({
isDraft: z.boolean(),
title: z.string(),
summary: z.string(),
tags: z.array(z.string()).optional(),
author: z.string().default("Anonymous"),
date: z.date(),
updatedAt: z.date().optional(),
image: z.object({ src: image(), alt: z.string() }).optional(),
date: z.coerce.date(),
updatedAt: z.coerce.date().optional(),
image: z
.object({
src: image(),
alt: z.string(),
})
.optional(),
}),
});

// 3. Export a single `collections` object to register your collection(s)
export const collections = {
strings, apps, links, blog
strings,
apps,
links,
blog,
};
6 changes: 3 additions & 3 deletions src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
import Layout from "../../layouts/Layout.astro";
import DateFormat from "../../components/DateFormat.astro";
import { getCollection } from "astro:content";
import { getCollection, render } from "astro:content";
import type { CollectionEntry } from "astro:content";
import { Image } from "astro:assets";

export async function getStaticPaths() {
const blog = await getCollection("blog");
return blog.map((post) => ({
params: { slug: post.slug },
params: { slug: post.id },
props: { post },
}));
}
Expand All @@ -20,7 +20,7 @@ interface Props {
const { post } = Astro.props;

const { title, summary, author, date, image, tags } = post.data;
const { Content } = await post.render();
const { Content } = await render(post);
---

<Layout title="Fossify | Blog posts" lang="en" dir="ltr">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/blog/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const posts = blogPosts
<h1>Latest blog posts</h1>
{
posts.map((post) => (
<a href={post.slug}>
<a href={`/blog/${post.id}`}>
<BlogPostCard post={post} />
</a>
))
Expand Down
Loading