Skip to content

Commit 413e446

Browse files
authored
Export markdoc object (#50)
* export markdoc object * 0.3.7
1 parent 7b2482a commit 413e446

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@markdoc/next.js",
3-
"version": "0.3.6",
3+
"version": "0.3.7",
44
"author": "Stripe, Inc.",
55
"description": "Markdoc plugin for Next.js",
66
"license": "MIT",

src/loader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ ${
222222
}`
223223
}
224224
${appDir ? nextjsExportsCode : ''}
225+
export const markdoc = {frontmatter};
225226
export default${appDir ? ' async' : ''} function MarkdocComponent(props) {
226227
const markdoc = ${appDir ? 'await getMarkdocData()' : 'props.markdoc'};
227228
// Only execute HMR code in development

tests/__snapshots__/index.test.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export async function getStaticProps(context) {
8282
};
8383
}
8484
85+
export const markdoc = {frontmatter};
8586
export default function MarkdocComponent(props) {
8687
const markdoc = props.markdoc;
8788
// Only execute HMR code in development
@@ -173,6 +174,7 @@ async function getMarkdocData(context = {}) {
173174
174175
export const metadata = frontmatter.nextjs?.metadata;
175176
export const revalidate = frontmatter.nextjs?.revalidate;
177+
export const markdoc = {frontmatter};
176178
export default async function MarkdocComponent(props) {
177179
const markdoc = await getMarkdocData();
178180
// Only execute HMR code in development
@@ -269,6 +271,7 @@ export async function getStaticProps(context) {
269271
};
270272
}
271273
274+
export const markdoc = {frontmatter};
272275
export default function MarkdocComponent(props) {
273276
const markdoc = props.markdoc;
274277
// Only execute HMR code in development

tests/index.test.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ test('file output is correct', async () => {
123123
expect(evaluate(output)).toEqual({
124124
default: expect.any(Function),
125125
getStaticProps: expect.any(Function),
126+
markdoc: {
127+
frontmatter: {
128+
title: 'Custom title',
129+
},
130+
},
126131
});
127132

128133
const data = await page.getStaticProps({});
@@ -158,14 +163,19 @@ test('file output is correct', async () => {
158163
});
159164

160165
test('app router', async () => {
161-
const output = await callLoader(options({ appDir: true }), source);
166+
const output = await callLoader(options({appDir: true}), source);
162167

163168
expect(normalizeOperatingSystemPaths(output)).toMatchSnapshot();
164169

165170
const page = evaluate(output);
166171

167172
expect(evaluate(output)).toEqual({
168173
default: expect.any(Function),
174+
markdoc: {
175+
frontmatter: {
176+
title: 'Custom title',
177+
},
178+
},
169179
});
170180

171181
expect(await page.default({})).toEqual(
@@ -179,11 +189,13 @@ test('app router', async () => {
179189

180190
test('app router metadata', async () => {
181191
const output = await callLoader(
182-
options({ appDir: true }),
192+
options({appDir: true}),
183193
source.replace('---', '---\nmetadata:\n title: Metadata title')
184194
);
185195

186-
expect(output).toContain('export const metadata = frontmatter.nextjs?.metadata;')
196+
expect(output).toContain(
197+
'export const metadata = frontmatter.nextjs?.metadata;'
198+
);
187199
});
188200

189201
test.each([
@@ -248,5 +260,10 @@ test('mode="server"', async () => {
248260
expect(evaluate(output)).toEqual({
249261
default: expect.any(Function),
250262
getServerSideProps: expect.any(Function),
263+
markdoc: {
264+
frontmatter: {
265+
title: 'Custom title',
266+
},
267+
},
251268
});
252269
});

0 commit comments

Comments
 (0)