forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 2
/
client-context.ts
26 lines (20 loc) · 1009 Bytes
/
client-context.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { cache } from 'react';
import type { ClientSharedServerContext } from '@/types';
import { assignClientContext } from './util/assignClientContext';
// This allows us to have Server-Side Context's of the shared "contextual" data
// which includes the frontmatter, the current pathname from the dynamic segments
// and the current headings of the current markdown context
export const getClientContext = cache(() => {
const serverSharedContext = assignClientContext({});
return serverSharedContext;
});
// This is used by the dynamic router to define on the request
// the current set of information we use (shared)
export const setClientContext = (data: Partial<ClientSharedServerContext>) => {
const _data = assignClientContext(data);
getClientContext().frontmatter = _data.frontmatter;
getClientContext().pathname = _data.pathname;
getClientContext().headings = _data.headings;
getClientContext().readingTime = _data.readingTime;
getClientContext().filename = _data.filename;
};