#17 YouTube 対応

This commit is contained in:
2025-08-25 23:30:41 +09:00
parent 34e79e9826
commit b8c2c221ca
4 changed files with 125 additions and 23 deletions
+3 -21
View File
@@ -6,9 +6,8 @@ import { useParams } from 'react-router-dom'
import PostList from '@/components/PostList'
import TagDetailSidebar from '@/components/TagDetailSidebar'
import NicoViewer from '@/components/NicoViewer'
import PostEditForm from '@/components/PostEditForm'
import TwitterEmbed from '@/components/TwitterEmbed'
import PostEmbed from '@/components/PostEmbed'
import TabGroup, { Tab } from '@/components/common/TabGroup'
import MainArea from '@/components/layout/MainArea'
import { Button } from '@/components/ui/button'
@@ -22,27 +21,10 @@ import type { FC } from 'react'
import type { Post, User } from '@/types'
const PostEmbed: FC<{ post: Post }> = ({ post }: { post: Post }) => {
const url = new URL (post.url)
switch (url.hostname.split ('.').slice (-2).join ('.'))
{
case 'nicovideo.jp':
const [videoId] = url.pathname.match (/(?<=\/watch\/)[a-zA-Z0-9]+?(?=\/|$)/)!
return <NicoViewer id={videoId} width={640} height={360}/>
case 'twitter.com':
case 'x.com':
const [userId] = url.pathname.match (/(?<=\/)[^\/]+?(?=\/|$)/)!
const [statusId] = url.pathname.match (/(?<=\/status\/)\d+?(?=\/|$)/)!
return <TwitterEmbed userId={userId} statusId={statusId}/>
default:
return <img src={post.thumbnail} alt={post.url} className="mb-4 w-full"/>
}
}
type Props = { user: User | null }
export default ({ user }: Props) => {
export default (({ user }: Props) => {
const { id } = useParams ()
const [post, setPost] = useState<Post | null> (null)
@@ -142,4 +124,4 @@ export default ({ user }: Props) => {
<TagDetailSidebar post={post}/>
</div>
</div>)
}
}) satisfies FC<Props>