このコミットが含まれているのは:
+10
-22
@@ -1,9 +1,10 @@
|
||||
import { isLocaleCode, localeLanguage } from '@/lib/locales'
|
||||
import { localeLanguage } from '@/lib/locales'
|
||||
import { helpKeys } from '@/lib/queryKeys'
|
||||
|
||||
import type { QueryClient } from '@tanstack/react-query'
|
||||
import type { ComponentType } from 'react'
|
||||
|
||||
import type { PagePreparation } from '@/lib/routeLocales'
|
||||
|
||||
type ArticleLanguage = { currentEdition: string; publishedEditions: string[] }
|
||||
|
||||
export type ArticleMeta = {
|
||||
@@ -97,34 +98,21 @@ export const resolveHelpLanguage = (
|
||||
: null
|
||||
|
||||
|
||||
export const matchHelpDetail = (pathname: string): RegExpMatchArray | null => {
|
||||
const matched = pathname.match (/^\/([^/]+)\/help\/([^/]+)\/?$/)
|
||||
return matched?.[2] === 'changes' ? null : matched
|
||||
}
|
||||
|
||||
|
||||
// MDX functions stay in memory; both entries load them before rendering.
|
||||
export const prepareHelpPage = async (client: QueryClient, url: URL): Promise<number> => {
|
||||
const matched = matchHelpDetail (url.pathname)
|
||||
if (matched == null || !(isLocaleCode (matched[1])))
|
||||
export const prepareHelpPage = async (
|
||||
{ client, params, locale, searchParams }: PagePreparation,
|
||||
): Promise<number> => {
|
||||
const identifier = params.identifier
|
||||
if (identifier == null)
|
||||
return 404
|
||||
let identifier: string
|
||||
try
|
||||
{
|
||||
identifier = decodeURIComponent (matched[2])
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 404
|
||||
}
|
||||
const article = await client.fetchQuery ({
|
||||
queryKey: helpKeys.article (identifier),
|
||||
queryFn: () => getHelpArticle (identifier), staleTime: Infinity })
|
||||
const language = resolveHelpLanguage (article, localeLanguage (matched[1]))
|
||||
const language = resolveHelpLanguage (article, localeLanguage (locale))
|
||||
if (language == null)
|
||||
return 404
|
||||
const meta = article!.languages[language]
|
||||
const edition = url.searchParams.get ('edition') ?? meta.currentEdition
|
||||
const edition = searchParams.get ('edition') ?? meta.currentEdition
|
||||
if (!(meta.publishedEditions.includes (edition)) || parseHelpEdition (edition) == null)
|
||||
return 404
|
||||
const content = await client.fetchQuery ({
|
||||
|
||||
@@ -31,7 +31,7 @@ const boolFromQuery = (value: string | null): boolean =>
|
||||
['1', 'true', 'on', 'yes', ''].includes ((value ?? '').toLowerCase ())
|
||||
|
||||
|
||||
const prefetchHelpIndex: Prefetcher = async (qc, url, locale) => {
|
||||
const prefetchHelpIndex: Prefetcher = async (qc, _url, locale) => {
|
||||
await qc.prefetchQuery ({
|
||||
queryKey: helpKeys.index (localeLanguage (locale)),
|
||||
queryFn: () => getHelpSearchEntries (localeLanguage (locale)),
|
||||
@@ -63,7 +63,7 @@ const prefetchHelpShow: Prefetcher = async (qc, url, locale) => {
|
||||
}
|
||||
|
||||
|
||||
const prefetchHelpChanges: Prefetcher = async (qc, url, locale) => {
|
||||
const prefetchHelpChanges: Prefetcher = async (qc, _url, locale) => {
|
||||
await qc.prefetchQuery ({
|
||||
queryKey: helpKeys.changes (localeLanguage (locale)),
|
||||
queryFn: () => getHelpChanges (localeLanguage (locale)),
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
import { matchPath } from 'react-router-dom'
|
||||
|
||||
import { unlocalisedPath } from '@/lib/locales'
|
||||
import type { QueryClient } from '@tanstack/react-query'
|
||||
import type { IndexRouteObject, NonIndexRouteObject, Params } from 'react-router-dom'
|
||||
|
||||
import type { LocaleCode } from '@/lib/locales'
|
||||
|
||||
const PAGE_LOCALES: { path: string; locale: LocaleCode }[] = [
|
||||
{ path: '/gekanator', locale: 'ja' }]
|
||||
export type PagePreparation = {
|
||||
client: QueryClient
|
||||
params: Readonly<Params>
|
||||
locale: LocaleCode
|
||||
searchParams: URLSearchParams }
|
||||
|
||||
export type PageRouteHandle = {
|
||||
ssr?: (request: PagePreparation) => Promise<number>
|
||||
locale?: LocaleCode
|
||||
notFound?: boolean }
|
||||
|
||||
export const requiredPageLocale = (pathname: string): LocaleCode | null =>
|
||||
PAGE_LOCALES.find (page =>
|
||||
matchPath ({ path: page.path, end: true }, unlocalisedPath (pathname)))?.locale ?? null
|
||||
export type PageRoute = { handle?: PageRouteHandle } & (
|
||||
Omit<IndexRouteObject, 'handle'>
|
||||
| (Omit<NonIndexRouteObject, 'handle' | 'children'> & { children?: PageRoute[] }))
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする