mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 07:12:52 +01:00
refactor: improve type safety (#155)
* Fix to make it type safe. * The build is failing, fix it.
This commit is contained in:
committed by
GitHub
parent
f79ee3482d
commit
e9c8930559
@@ -1,27 +1,27 @@
|
||||
---
|
||||
import { getSortedPosts } from '@utils/content-utils'
|
||||
import MainGridLayout from '@layouts/MainGridLayout.astro'
|
||||
import ArchivePanel from '@components/ArchivePanel.astro'
|
||||
import { i18n } from '@i18n/translation'
|
||||
import I18nKey from '@i18n/i18nKey'
|
||||
import { i18n } from '@i18n/translation'
|
||||
import MainGridLayout from '@layouts/MainGridLayout.astro'
|
||||
import { getSortedPosts } from '@utils/content-utils'
|
||||
|
||||
export async function getStaticPaths() {
|
||||
let posts = await getSortedPosts()
|
||||
const posts = await getSortedPosts()
|
||||
|
||||
const allTags = posts.reduce((acc, post) => {
|
||||
// タグを集めるための Set の型を指定
|
||||
const allTags = posts.reduce<Set<string>>((acc, post) => {
|
||||
// biome-ignore lint/complexity/noForEach: <explanation>
|
||||
post.data.tags.forEach(tag => acc.add(tag))
|
||||
return acc
|
||||
}, new Set())
|
||||
|
||||
const allTagsArray = Array.from(allTags)
|
||||
|
||||
return allTagsArray.map(tag => {
|
||||
return {
|
||||
params: {
|
||||
tag: tag,
|
||||
},
|
||||
}
|
||||
})
|
||||
return allTagsArray.map(tag => ({
|
||||
params: {
|
||||
tag: tag,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
const tag = Astro.params.tag as string
|
||||
@@ -29,4 +29,4 @@ const tag = Astro.params.tag as string
|
||||
|
||||
<MainGridLayout title={i18n(I18nKey.archive)} description={i18n(I18nKey.archive)}>
|
||||
<ArchivePanel tags={[tag]}></ArchivePanel>
|
||||
</MainGridLayout>
|
||||
</MainGridLayout>
|
||||
@@ -1,25 +1,31 @@
|
||||
import rss from '@astrojs/rss'
|
||||
import { siteConfig } from '@/config'
|
||||
import sanitizeHtml from 'sanitize-html'
|
||||
import rss from '@astrojs/rss'
|
||||
import { getSortedPosts } from '@utils/content-utils'
|
||||
import type { APIContext } from 'astro'
|
||||
import MarkdownIt from 'markdown-it'
|
||||
import { getSortedPosts } from '@utils/content-utils.ts'
|
||||
import sanitizeHtml from 'sanitize-html'
|
||||
|
||||
const parser = new MarkdownIt()
|
||||
|
||||
export async function GET(context: any) {
|
||||
export async function GET(context: APIContext) {
|
||||
const blog = await getSortedPosts()
|
||||
|
||||
return rss({
|
||||
title: siteConfig.title,
|
||||
description: siteConfig.subtitle || 'No description',
|
||||
site: context.site,
|
||||
items: blog.map(post => ({
|
||||
title: post.data.title,
|
||||
pubDate: post.data.published,
|
||||
description: post.data.description,
|
||||
link: `/posts/${post.slug}/`,
|
||||
content: sanitizeHtml(parser.render(post.body), {
|
||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
|
||||
}),
|
||||
})),
|
||||
site: context.site ?? 'https://fuwari.vercel.app',
|
||||
items: blog.map(post => {
|
||||
const body = typeof post.data.body === 'string' ? post.data.body : ''
|
||||
return {
|
||||
title: post.data.title,
|
||||
pubDate: post.data.published,
|
||||
description: post.data.description || '',
|
||||
link: `/posts/${post.slug}/`,
|
||||
content: sanitizeHtml(parser.render(body), {
|
||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
|
||||
}),
|
||||
}
|
||||
}),
|
||||
customData: `<language>${siteConfig.lang}</language>`,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user