Add next-mdx-remote #82

Merged
a3thakra merged 1 commits from adi-next-mdx-remote into main 2 years ago
Collaborator

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 2 years ago
288d423958 Add next-mdx-remote
a3thakra requested review from n3parikh 2 years ago
Poster
Collaborator

@n3parikh ping

@n3parikh ping
n3parikh approved these changes 2 years ago
a3thakra merged commit 44621b2daf into main 2 years ago
a3thakra referenced this issue from a commit 2 years ago

Reviewers

n3parikh approved these changes 2 years ago
continuous-integration/drone/push Build is passing
The pull request has been merged as 44621b2daf.
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: www/www-new#82
Loading…
There is no content yet.