feat: add TypeScript interfaces for blog, category, destination, and tag pages

This commit is contained in:
Thuan Bui
2026-03-19 18:27:26 +07:00
parent f931b542ad
commit f140fb53d3
5 changed files with 54 additions and 6 deletions
+6 -2
View File
@@ -7,7 +7,11 @@ import Destinations from "@/components/ui/Destinations.astro";
import { toR2Url } from "@/utils/r2";
import Picture from "@/components/ui/Picture.astro";
import { getCollection, render } from "astro:content";
import { getCollection, render, type CollectionEntry } from "astro:content";
interface Props {
post: CollectionEntry<"blog">;
}
export async function getStaticPaths() {
const blog = await getCollection("blog");
@@ -17,7 +21,7 @@ export async function getStaticPaths() {
}));
}
const { post } = Astro.props;
const { post } = Astro.props as Props;
const { Content, remarkPluginFrontmatter } = await render(post);
const {
title,
+12 -1
View File
@@ -1,11 +1,22 @@
---
import BaseLayout from "@/layouts/BaseLayout.astro";
import { getCollection } from "astro:content";
import type { CollectionEntry } from "astro:content";
import Headline from "@/components/ui/Headline.astro";
import Pagination from "@/components/ui/Pagination.astro";
import PostItem from "@/components/blog/PostItem.astro";
import { buildPaginatedPaths } from "@/utils/paginate";
interface Props {
page: {
data: CollectionEntry<"blog">[];
total: number;
currentPage: number;
lastPage: number;
url: { prev?: string; next?: string };
};
}
export async function getStaticPaths() {
const blogEntries = await getCollection("blog");
const sortedPosts = blogEntries
@@ -20,7 +31,7 @@ export async function getStaticPaths() {
);
}
const { page } = Astro.props;
const { page } = Astro.props as Props;
const blog = page.data;
const metadata = {
+12 -1
View File
@@ -1,6 +1,7 @@
---
import BaseLayout from "@/layouts/BaseLayout.astro";
import { getCollection } from "astro:content";
import type { CollectionEntry } from "astro:content";
import Headline from "@/components/ui/Headline.astro";
import PostItem from "@/components/blog/PostItem.astro";
import Pagination from "@/components/ui/Pagination.astro";
@@ -11,6 +12,16 @@ import {
} from "@/utils/taxonomy";
import { buildPaginatedPaths } from "@/utils/paginate";
interface Props {
cat: TaxonomyItem;
posts: CollectionEntry<"blog">[];
currentPage: number;
lastPage: number;
total: number;
prevUrl?: string;
nextUrl?: string;
}
export async function getStaticPaths() {
const allPosts = await getCollection("blog");
const posts = allPosts.filter((post) => post.data && post.data.pubDate);
@@ -48,7 +59,7 @@ export async function getStaticPaths() {
}
const { cat, posts, currentPage, lastPage, total, prevUrl, nextUrl } =
Astro.props;
Astro.props as Props;
const page = {
currentPage,
+12 -1
View File
@@ -1,6 +1,7 @@
---
import BaseLayout from "@/layouts/BaseLayout.astro";
import { getCollection } from "astro:content";
import type { CollectionEntry } from "astro:content";
import Headline from "@/components/ui/Headline.astro";
import PostItem from "@/components/blog/PostItem.astro";
import Pagination from "@/components/ui/Pagination.astro";
@@ -11,6 +12,16 @@ import {
} from "@/utils/taxonomy";
import { buildPaginatedPaths } from "@/utils/paginate";
interface Props {
dest: TaxonomyItem;
posts: CollectionEntry<"blog">[];
currentPage: number;
lastPage: number;
total: number;
prevUrl?: string;
nextUrl?: string;
}
export async function getStaticPaths() {
const allPosts = await getCollection("blog");
const posts = allPosts.filter((post) => post.data && post.data.pubDate);
@@ -48,7 +59,7 @@ export async function getStaticPaths() {
}
const { dest, posts, currentPage, lastPage, total, prevUrl, nextUrl } =
Astro.props;
Astro.props as Props;
const page = {
currentPage,
+12 -1
View File
@@ -1,12 +1,23 @@
---
import BaseLayout from "@/layouts/BaseLayout.astro";
import { getCollection } from "astro:content";
import type { CollectionEntry } from "astro:content";
import Headline from "@/components/ui/Headline.astro";
import PostItem from "@/components/blog/PostItem.astro";
import Pagination from "@/components/ui/Pagination.astro";
import { getTaxonomyMap } from "@/utils/taxonomy";
import { buildPaginatedPaths } from "@/utils/paginate";
interface Props {
page: {
data: CollectionEntry<"blog">[];
total: number;
currentPage: number;
lastPage: number;
url: { prev?: string; next?: string };
};
}
export async function getStaticPaths() {
const allPosts = await getCollection("blog");
const posts = allPosts.filter((post) => post.data && post.data.pubDate);
@@ -30,7 +41,7 @@ export async function getStaticPaths() {
});
}
const { page } = Astro.props;
const { page } = Astro.props as Props;
const { tag } = Astro.params;
const tagInfo = getTaxonomyMap("tag").get(tag!);