From 036d80631300ba0b507f0a1ea590ab16170a750e Mon Sep 17 00:00:00 2001 From: thiloho <123883702+thiloho@users.noreply.github.com> Date: Tue, 29 Apr 2025 03:19:12 +0200 Subject: [PATCH] Destructure in maps for less duplication --- src/components/Button.astro | 4 ++-- src/components/TableOfContents.astro | 8 ++++---- src/pages/blog/[slug].astro | 10 +++------- src/pages/blog/index.astro | 11 ++++------- src/pages/rss.xml.ts | 8 ++++---- src/pages/tracks.astro | 11 ++--------- 6 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/components/Button.astro b/src/components/Button.astro index d6a950e..494a8c0 100644 --- a/src/components/Button.astro +++ b/src/components/Button.astro @@ -9,8 +9,8 @@ interface Props { const { href, variant = "text", title, class: className = "" } = Astro.props; const baseClasses = - "border-transparent inline-block border-b-2 p-2 cursor-pointer hover:border-neutral-300 hover:bg-neutral-100 hover:dark:border-neutral-600 hover:dark:bg-neutral-700"; -const classes = `${baseClasses} ${variant === "icon" && href ? "inline-grid place-content-center" : ""} ${className}`; + "border-transparent border-b-2 p-2 cursor-pointer hover:border-neutral-300 hover:bg-neutral-100 hover:dark:border-neutral-600 hover:dark:bg-neutral-700"; +const classes = `${baseClasses} ${variant === "icon" && href ? "inline-grid place-content-center" : "inline-block"} ${className}`; --- { diff --git a/src/components/TableOfContents.astro b/src/components/TableOfContents.astro index 49a06fe..6032e37 100644 --- a/src/components/TableOfContents.astro +++ b/src/components/TableOfContents.astro @@ -27,14 +27,14 @@ const { headings } = Astro.props; headings.length ? ( headings .filter(({ depth }) => depth === 2) - .map((heading) => ( + .map(({ slug, text }) => (
  • - {heading.text} + {text}
  • )) diff --git a/src/pages/blog/[slug].astro b/src/pages/blog/[slug].astro index 5991616..18c5757 100644 --- a/src/pages/blog/[slug].astro +++ b/src/pages/blog/[slug].astro @@ -18,16 +18,12 @@ if (!article) { throw new Error(); } +const { title, description, pubDate, modDate } = article.data; + const { Content, headings } = await render(article); --- - + diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index 8b91675..d2cba24 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -15,15 +15,12 @@ const sortedArticles = allArticles.sort((a, b) => { >