diff --git a/frontend/src/b/TodayPage.tsx b/frontend/src/b/TodayPage.tsx index 1d6a926..7e66dd7 100644 --- a/frontend/src/b/TodayPage.tsx +++ b/frontend/src/b/TodayPage.tsx @@ -30,7 +30,7 @@ import { usePinnedLike } from './pinnedLike' import { ShortsRail } from './Shorts' import { FeedComposer, NearTalks, TalkGroup } from './talk' import { topicName, useTalkGroups, useTodayMyTalks } from './talkState' -import { useRegion } from './regionContext' +import { useLandingAbout, useRegion } from './regionContext' import { useSheet } from './sheetContext' import { useSky } from './skyContext' import { DayShareCard, DayShareGrid, GakShareCard, type DayShare } from './shareCards' @@ -577,6 +577,7 @@ function SeasonBand({ news }: { news: BandArticle[] }) { export function TodayPage() { const { region } = useRegion() + const about = useLandingAbout() const feed = useQuery(getFeedOptions({ query: { region: region.code } })) const today = useQuery(getWeatherTodayOptions({ query: { region: region.code } })) const { preview } = useSky() @@ -682,6 +683,13 @@ export function TodayPage() { {feed.isSuccess && spreadLeft} {feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => {node})} + {about && ( +
+ )} ) } diff --git a/frontend/src/b/region.tsx b/frontend/src/b/region.tsx index 5f4130a..f49c986 100644 --- a/frontend/src/b/region.tsx +++ b/frontend/src/b/region.tsx @@ -5,18 +5,12 @@ import { nearestRegion } from '@nalssigak/shared/api/client/sdk.gen' import type { RegionData } from '@nalssigak/shared/api/client/types.gen' import { track } from '../lib/analytics' import { IS_TOSS, tossLocation } from '../lib/platform' -import { DEFAULT_REGION, ownPage, RegionContext, type LocateStatus } from './regionContext' +import { DEFAULT_REGION, ownPage, pageOf, RegionContext, type LocateStatus } from './regionContext' const KEY = 'nalssigak.b.region' type RegionPage = (typeof regionPages)[number] -/** /today/gyeonggi/seongnam, /tomorrow/gyeonggi/seongnam/bundang 같은 지역 페이지 주소면 그 페이지 */ -function pageOf(pathname: string): RegionPage | undefined { - const path = pathname.match(/^\/(?:today|tomorrow)\/([a-z]+\/[a-z]+(?:\/[a-z]+)?)\/?$/)?.[1] - return path ? regionPages.find((p) => p.path === path) : undefined -} - /** 지역 페이지 안의 구: 구로 나뉜 시는 r 이 그 시 안이면 r, 아니면 시청이 있는 구 */ function regionIn(page: RegionPage, r?: RegionData | null): RegionData { return page.regions.find((g) => g.code === r?.code) ?? page.regions.find((g) => g.code === page.main)! diff --git a/frontend/src/b/regionContext.ts b/frontend/src/b/regionContext.ts index cf2f4a5..5ee0226 100644 --- a/frontend/src/b/regionContext.ts +++ b/frontend/src/b/regionContext.ts @@ -1,4 +1,5 @@ import { createContext, use } from 'react' +import { useLocation } from 'react-router' import type { RegionData } from '@nalssigak/shared/api/client/types.gen' import regionPages from '../../seo/region.json' @@ -11,6 +12,21 @@ export { DEFAULT_REGION } from '@nalssigak/shared/lib' /** 구 하나만 보여 주는 지역 페이지: 일반 시군구, 또는 구로 나뉜 시의 구 페이지 */ export const ownPage = (code: string) => regionPages.find((p) => p.regions.length === 1 && p.regions[0].code === code) +/** /today/gyeonggi/seongnam, /tomorrow/gyeonggi/seongnam/bundang 같은 지역 페이지 주소면 그 페이지 */ +export function pageOf(pathname: string) { + const path = pathname.match(/^\/(?:today|tomorrow)\/([a-z]+\/[a-z]+(?:\/[a-z]+)?)\/?$/)?.[1] + return path ? regionPages.find((p) => p.path === path) : undefined +} + +/** 지역 페이지로 들어오면 서버가 채운 소개 글(#root 안)을 앱이 덮기 전에 잡아 둔다. 구글은 JS 실행 뒤 화면으로 색인한다 */ +const landingAbout = pageOf(location.pathname) ? { path: location.pathname, html: document.querySelector('#root > main')?.innerHTML ?? '' } : null + +/** 들어온 지역 페이지에 그대로 있을 때만 그 소개 글 */ +export function useLandingAbout(): string | null { + const { pathname } = useLocation() + return landingAbout?.html && landingAbout.path === pathname ? landingAbout.html : null +} + export const RegionContext = createContext(null) export function useRegion() {