Skip to content

Commit

Permalink
Merge pull request #164 from OUCC/blog/admin/error-message
Browse files Browse the repository at this point in the history
エラーメッセージを表示
  • Loading branch information
miyaji255 authored Dec 16, 2024
2 parents e3eaa2c + 0ab2967 commit a668d8f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/content/_blog-statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ const statistics = lazy(async () => {
for (const { id, time } of categoryStatistics[category])
(result[id] ??= { score: 0, time }).score += 2

for (const { id: slug, time } of tags.flatMap(
({ id }) => tagStatistics[id]!,
))
for (const { id: slug, time } of tags.flatMap(({ id }) => {
const tag = tagStatistics[id]
if (!tag) throw new Error(`Tag ${id} not found`)
return tag
}))
(result[slug] ??= { score: 0, time }).score += 1

delete result[id]
Expand All @@ -85,12 +87,18 @@ const statistics = lazy(async () => {

export async function getBlogStatistics(slug: BlogId) {
const { blogStatistics } = await statistics()
return blogStatistics[slug]!
const blog = blogStatistics[slug]
if (!blog) throw new Error(`Blog ${slug} not found`)
return blog
}

export async function getTagStatistics(): Promise<TagStatistics>
export async function getTagStatistics(id: TagId): Promise<TagStatistics[TagId]>
export async function getTagStatistics(id?: TagId) {
const { tagStatistics } = await statistics()
return id === undefined ? tagStatistics : tagStatistics[id]!
if (id === undefined) return tagStatistics

const tag = tagStatistics[id]
if (!tag) throw new Error(`Tag ${id} not found`)
return tag
}

0 comments on commit a668d8f

Please sign in to comment.