Pages Router 의 getServerSideProps 에서 getServerSideSitemapLegacy 에 필드 목록을 넘기면 사이트맵 XML 문자열을 만들고, withXMLResponseLegacy 가 응답에 Content-Type: text/xml 을 걸고 그 문자열을 쓰고 끝낸다. 요청마다 서버에서 사이트맵을 만든다.

-- SSR 에서 XML 사이트맵을 만든다 (next-sitemap, Pages Router)
-- withXMLResponseLegacy 는 next-sitemap 소스(src/ssr/response.ts)의 동작 그대로다
getServerSideProps ctx = getServerSideSitemapLegacy ctx fields   -- 필드 목록 → XML 문자열
  >>= withXMLResponseLegacy ctx

withXMLResponseLegacy ctx content = do
  setHeader (res ctx) "Content-Type" "text/xml"
  write (res ctx) content
  end (res ctx)

출처

`#410`