refactor: improve code quality

This commit is contained in:
saicaca
2024-07-21 15:47:49 +08:00
parent 743d8dd9c2
commit 003c644146
20 changed files with 76 additions and 69 deletions

View File

@@ -6,9 +6,9 @@ import I18nKey from "../i18n/i18nKey";
import {UNCATEGORIZED} from "@constants/constants";
interface Props {
keyword: string;
tags: string[];
categories: string[];
keyword?: string;
tags?: string[];
categories?: string[];
}
const { keyword, tags, categories} = Astro.props;
@@ -27,8 +27,8 @@ if (Array.isArray(categories) && categories.length > 0) {
);
}
const groups = function () {
const groupedPosts = posts.reduce((grouped, post) => {
const groups: {year: number, posts: typeof posts}[] = function () {
const groupedPosts = posts.reduce((grouped: {[year: number]: typeof posts}, post) => {
const year = post.data.published.getFullYear()
if (!grouped[year]) {
grouped[year] = []
@@ -39,8 +39,8 @@ const groups = function () {
// convert the object to an array
const groupedPostsArray = Object.keys(groupedPosts).map(key => ({
year: key,
posts: groupedPosts[key]
year: parseInt(key),
posts: groupedPosts[parseInt(key)]
}))
// sort years by latest first