Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(types): Add missing types in blog #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions templates/blog/src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
import { type CollectionEntry, getCollection } from 'astro:content';
import BlogPost from '../../layouts/BlogPost.astro';
import { type CollectionEntry, getCollection } from "astro:content";
import BlogPost from "../../layouts/BlogPost.astro";

export async function getStaticPaths() {
const posts = await getCollection('blog');
return posts.map((post) => ({
const posts = await getCollection("blog");
return posts.map((post: CollectionEntry<"blog">) => ({
params: { slug: post.slug },
props: post,
}));
}
type Props = CollectionEntry<'blog'>;
type Props = CollectionEntry<"blog">;

const post = Astro.props;
const { Content } = await post.render();
Expand Down
30 changes: 19 additions & 11 deletions templates/blog/src/pages/blog/index.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
import BaseHead from '../../components/BaseHead.astro';
import Header from '../../components/Header.astro';
import Footer from '../../components/Footer.astro';
import { SITE_TITLE, SITE_DESCRIPTION } from '../../consts';
import { getCollection } from 'astro:content';
import FormattedDate from '../../components/FormattedDate.astro';
import BaseHead from "../../components/BaseHead.astro";
import Header from "../../components/Header.astro";
import Footer from "../../components/Footer.astro";
import { SITE_TITLE, SITE_DESCRIPTION } from "../../consts";
import { type CollectionEntry, getCollection } from "astro:content";
import FormattedDate from "../../components/FormattedDate.astro";

const posts = (await getCollection('blog')).sort(
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf(),
const posts = (await getCollection("blog")).sort(
(a: CollectionEntry<"Blog">, b: CollectionEntry<"Blog">) =>
b.data.pubDate.valueOf() - a.data.pubDate.valueOf(),
);
---

Expand Down Expand Up @@ -91,13 +92,20 @@ const posts = (await getCollection('blog')).sort(
<section>
<ul>
{
posts.map((post) => (
posts.map((post: any) => (
<li>
<a href={`/blog/${post.slug}/`}>
<img width={720} height={360} src={post.data.heroImage} alt="" />
<img
width={720}
height={360}
src={post.data.heroImage}
alt=""
/>
<h4 class="title">{post.data.title}</h4>
<p class="date">
<FormattedDate date={post.data.pubDate} />
<FormattedDate
date={post.data.pubDate}
/>
</p>
</a>
</li>
Expand Down