mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-11 23:02:53 +01:00
refactor: improve code quality
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user