The Node.js® Website
at main 1.0 kB view raw
1import { cache } from 'react'; 2 3import type { ClientSharedServerContext } from '@/types'; 4 5import { assignClientContext } from './util/assignClientContext'; 6 7// This allows us to have Server-Side Context's of the shared "contextual" data 8// which includes the frontmatter, the current pathname from the dynamic segments 9// and the current headings of the current markdown context 10export const getClientContext = cache(() => { 11 const serverSharedContext = assignClientContext({}); 12 13 return serverSharedContext; 14}); 15 16// This is used by the dynamic router to define on the request 17// the current set of information we use (shared) 18export const setClientContext = (data: Partial<ClientSharedServerContext>) => { 19 const _data = assignClientContext(data); 20 21 getClientContext().frontmatter = _data.frontmatter; 22 getClientContext().pathname = _data.pathname; 23 getClientContext().headings = _data.headings; 24 getClientContext().readingTime = _data.readingTime; 25 getClientContext().filename = _data.filename; 26};