refactor: improve type safety (#155)

* Fix to make it type safe.

* The build is failing, fix it.
This commit is contained in:
Katsuyuki Karasawa
2024-08-28 01:19:26 +09:00
committed by GitHub
parent f79ee3482d
commit e9c8930559
10 changed files with 489 additions and 133 deletions

View File

@@ -1,9 +1,9 @@
---
import { UNCATEGORIZED } from '@constants/constants'
import I18nKey from '../i18n/i18nKey'
import { i18n } from '../i18n/translation'
import { getSortedPosts } from '../utils/content-utils'
import { getPostUrlBySlug } from '../utils/url-utils'
import { i18n } from '../i18n/translation'
import I18nKey from '../i18n/i18nKey'
import { UNCATEGORIZED } from '@constants/constants'
interface Props {
keyword?: string
@@ -30,7 +30,7 @@ if (Array.isArray(categories) && categories.length > 0) {
)
}
const groups: { year: number; posts: typeof posts }[] = (function () {
const groups: { year: number; posts: typeof posts }[] = (() => {
const groupedPosts = posts.reduce(
(grouped: { [year: number]: typeof posts }, post) => {
const year = post.data.published.getFullYear()
@@ -45,8 +45,8 @@ const groups: { year: number; posts: typeof posts }[] = (function () {
// convert the object to an array
const groupedPostsArray = Object.keys(groupedPosts).map(key => ({
year: parseInt(key),
posts: groupedPosts[parseInt(key)],
year: Number.parseInt(key),
posts: groupedPosts[Number.parseInt(key)],
}))
// sort years by latest first