From 7141d82dbd4defcc8fd43e9c54c2f91bfa1dd781 Mon Sep 17 00:00:00 2001 From: Sat Naing Date: Mon, 5 Jan 2026 22:56:38 +0700 Subject: [PATCH] refactor: update component props and improve types (#600) - stop exporting component Props - replace interface with type for component Props - enhance dynamic rendering in several components --- src/components/Card.astro | 33 ++++++++++++--------------- src/components/Datetime.astro | 10 ++++---- src/components/EditPost.astro | 4 ++-- src/components/Footer.astro | 12 ++++++---- src/components/Pagination.astro | 4 ++-- src/layouts/AboutLayout.astro | 8 ++----- src/layouts/Layout.astro | 4 ++-- src/layouts/Main.astro | 14 +++--------- src/pages/posts/[...slug]/index.astro | 4 ++-- 9 files changed, 40 insertions(+), 53 deletions(-) diff --git a/src/components/Card.astro b/src/components/Card.astro index 63a38f5..1bf61da 100644 --- a/src/components/Card.astro +++ b/src/components/Card.astro @@ -1,36 +1,31 @@ --- -import { slugifyStr } from "@/utils/slugify"; import type { CollectionEntry } from "astro:content"; +import { slugifyStr } from "@/utils/slugify"; import { getPath } from "@/utils/getPath"; import Datetime from "./Datetime.astro"; -export interface Props extends CollectionEntry<"blog"> { +type Props = { variant?: "h2" | "h3"; -} +} & CollectionEntry<"blog">; -const { variant = "h2", data, id, filePath } = Astro.props; +const { variant: Heading = "h2", id, data, filePath } = Astro.props; -const { title, description, pubDatetime, modDatetime, timezone } = data; - -const headerProps = { - style: { viewTransitionName: slugifyStr(title) }, - class: "text-lg font-medium decoration-dashed hover:underline", -}; +const { title, description, ...props } = data; ---
  • - { - variant === "h2" ? ( -

    {title}

    - ) : ( -

    {title}

    - ) - } + + {title} +
    - +

    {description}

  • diff --git a/src/components/Datetime.astro b/src/components/Datetime.astro index 000dd84..e16834f 100644 --- a/src/components/Datetime.astro +++ b/src/components/Datetime.astro @@ -8,13 +8,13 @@ import { SITE } from "@/config"; dayjs.extend(utc); dayjs.extend(timezone); -export interface Props { +type Props = { class?: string; size?: "sm" | "lg"; - timezone: string | undefined; pubDatetime: string | Date; - modDatetime: string | Date | undefined | null; -} + timezone?: string; + modDatetime?: string | Date | null; +}; const { pubDatetime, @@ -37,7 +37,7 @@ const date = datetime.format("D MMM, YYYY"); // e.g., '22 Mar, 2025'
    diff --git a/src/components/EditPost.astro b/src/components/EditPost.astro index 79d7d5a..fe3726b 100644 --- a/src/components/EditPost.astro +++ b/src/components/EditPost.astro @@ -3,11 +3,11 @@ import type { CollectionEntry } from "astro:content"; import IconEdit from "@/assets/icons/IconEdit.svg"; import { SITE } from "@/config"; -export interface Props { +type Props = { hideEditPost?: CollectionEntry<"blog">["data"]["hideEditPost"]; class?: string; post: CollectionEntry<"blog">; -} +}; const { hideEditPost, post, class: className = "" } = Astro.props; diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 27d9f70..2283c7f 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -1,16 +1,20 @@ --- +import type { HTMLAttributes } from "astro/types"; import Socials from "./Socials.astro"; const currentYear = new Date().getFullYear(); -export interface Props { +type Props = { noMarginTop?: boolean; -} +} & HTMLAttributes<"footer">; -const { noMarginTop = false } = Astro.props; +const { noMarginTop = false, class: className, ...attrs } = Astro.props; --- -