Add next-mdx-remote #82

Merged
a3thakra merged 1 commits from adi-next-mdx-remote into main 2021-07-11 16:07:56 -04:00
Owner

Closes #80

Example

// lib/events.ts

import matter from "gray-matter";
import { serialize } from "next-mdx-remote/serialize";

export async function getEvent() {
  // you should use the "fs" nodejs api here
  const fileAfterReading = `
---
title: A title
online: false
location: MC
---

## Alt Tab

Wooohooo
  `.trim();

  const { content, data } = matter(fileAfterReading);
  const serialized = await serialize(content, { scope: data });

  return { serialized, data };
}
// your-page.tsx

import { GetStaticProps } from "next";
import { MDXRemote } from "next-mdx-remote";
import React from "react";
import { getEvent } from "lib/events";

export default function MyPage(props) {
  return (
    <>
      <div>
        {...other stuff}
      </div>
      <MDXRemote {...props.serialized} />
    </>
  );
}

export const getStaticProps: GetStaticProps = async () => {
  const { serialized, data } = await getEvent();

  return {
    props: {
      serialized,
      data,
    },
  };
};

Closes #80 # Example ```ts // lib/events.ts import matter from "gray-matter"; import { serialize } from "next-mdx-remote/serialize"; export async function getEvent() { // you should use the "fs" nodejs api here const fileAfterReading = ` --- title: A title online: false location: MC --- ## Alt Tab Wooohooo `.trim(); const { content, data } = matter(fileAfterReading); const serialized = await serialize(content, { scope: data }); return { serialized, data }; } ``` ```tsx // your-page.tsx import { GetStaticProps } from "next"; import { MDXRemote } from "next-mdx-remote"; import React from "react"; import { getEvent } from "lib/events"; export default function MyPage(props) { return ( <> <div> {...other stuff} </div> <MDXRemote {...props.serialized} /> </> ); } export const getStaticProps: GetStaticProps = async () => { const { serialized, data } = await getEvent(); return { props: { serialized, data, }, }; }; ```
a3thakra added 1 commit 2021-07-05 20:56:30 -04:00
continuous-integration/drone/push Build is passing Details
288d423958
Add next-mdx-remote
a3thakra requested review from n3parikh 2021-07-05 21:00:38 -04:00
Author
Owner

@n3parikh ping

@n3parikh ping
n3parikh approved these changes 2021-07-11 15:55:43 -04:00
a3thakra merged commit 44621b2daf into main 2021-07-11 16:07:56 -04:00
a3thakra referenced this issue from a commit 2021-07-11 16:07:56 -04:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: www/www-new#82
No description provided.