From fbe97ac6348725a7aee9322b41a2e1f20425c443 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sun, 11 Jan 2026 13:39:50 +0900 Subject: [PATCH] #93 --- frontend/src/components/WikiBody.tsx | 8 +++----- frontend/src/lib/remark-wiki-autolink.ts | 4 ++-- frontend/src/pages/wiki/WikiDetailPage.tsx | 2 ++ frontend/src/pages/wiki/WikiEditPage.tsx | 8 +++++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/WikiBody.tsx b/frontend/src/components/WikiBody.tsx index 32ce119..0cb5cef 100644 --- a/frontend/src/components/WikiBody.tsx +++ b/frontend/src/components/WikiBody.tsx @@ -36,12 +36,10 @@ const mdComponents = { h1: ({ children }) => {children} { const [pageNames, setPageNames] = useState ([]) - const remarkPlugins = useMemo (() => [remarkWikiAutoLink (pageNames)], [pageNames]) + const remarkPlugins = useMemo ( + () => [() => remarkWikiAutoLink (pageNames), remarkGFM], [pageNames]) useEffect (() => { - if (!(body)) - return - void (async () => { try { @@ -54,7 +52,7 @@ export default (({ title, body }: Props) => { setPageNames ([]) } }) () - }, [body]) + }, []) return ( diff --git a/frontend/src/lib/remark-wiki-autolink.ts b/frontend/src/lib/remark-wiki-autolink.ts index 15a7c29..a37772b 100644 --- a/frontend/src/lib/remark-wiki-autolink.ts +++ b/frontend/src/lib/remark-wiki-autolink.ts @@ -4,7 +4,7 @@ const escapeForRegExp = (s: string) => s.replace (/[.*+?^${}()|[\]\\]/g, '\\$&') export default (pageNames: string[], basePath = '/wiki'): ((tree: Root) => void) => { - const names = pageNames.sort ((a, b) => b.length - a.length) + const names = [...pageNames].sort ((a, b) => b.length - a.length) if (names.length === 0) { @@ -46,7 +46,7 @@ export default (pageNames: string[], basePath = '/wiki'): ((tree: Root) => void) if (start > last) parts.push ({ type: 'text', value: value.slice (last, start) }) - const name = m[0] + const name = m[1] parts.push ({ type: 'link', url: `${ basePath }/${ encodeURIComponent (name) }`, title: null, diff --git a/frontend/src/pages/wiki/WikiDetailPage.tsx b/frontend/src/pages/wiki/WikiDetailPage.tsx index b5ebd79..6a68656 100644 --- a/frontend/src/pages/wiki/WikiDetailPage.tsx +++ b/frontend/src/pages/wiki/WikiDetailPage.tsx @@ -36,6 +36,7 @@ export default () => { if (/^\d+$/.test (title)) { void (async () => { + setWikiPage (undefined) try { const res = await axios.get (`${ API_BASE_URL }/wiki/${ title }`) @@ -52,6 +53,7 @@ export default () => { } void (async () => { + setWikiPage (undefined) try { const res = await axios.get ( diff --git a/frontend/src/pages/wiki/WikiEditPage.tsx b/frontend/src/pages/wiki/WikiEditPage.tsx index e142d2e..2bda3be 100644 --- a/frontend/src/pages/wiki/WikiEditPage.tsx +++ b/frontend/src/pages/wiki/WikiEditPage.tsx @@ -12,6 +12,8 @@ import Forbidden from '@/pages/Forbidden' import 'react-markdown-editor-lite/lib/index.css' +import type { FC } from 'react' + import type { User, WikiPage } from '@/types' const mdParser = new MarkdownIt @@ -19,7 +21,7 @@ const mdParser = new MarkdownIt type Props = { user: User | null } -export default ({ user }: Props) => { +export default (({ user }: Props) => { if (!(['admin', 'member'].some (r => user?.role === r))) return @@ -93,9 +95,9 @@ export default ({ user }: Props) => { {/* 送信 */} )} ) -} +}) satisfies FC