How to use the next-mdx-remote/render-to-string function in next-mdx-remote

To help you get started, we’ve selected a few next-mdx-remote examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hashicorp / boundary / website / components / temporary_docs-page / server.js View on Github external
if (existsSync(leafPath)) {
    page = fs.readFileSync(leafPath, 'utf8')
    filePath = leafPath
  } else if (existsSync(indexPath)) {
    page = fs.readFileSync(indexPath, 'utf8')
    filePath = indexPath
  } else {
    // NOTE: if we decide to let docs pages render dynamically, we should replace this
    // error with a straight 404, at least in production.
    throw new Error(
      `We went looking for "${leafPath}" and "${indexPath}" but neither one was found.`
    )
  }

  const { data: frontMatter, content } = matter(page)
  const mdxSource = await renderToString(content, {
    mdxOptions: markdownDefaults({
      resolveIncludes: path.join(process.cwd(), 'content/partials'),
    }),
    components,
  })

  return { mdxSource, frontMatter, filePath: filePath.replace(`${root}/`, '') }
}
github openmultiplayer / web / frontend / src / pages / docs / index.tsx View on Github external
export async function getStaticProps({
  locale,
}: GetStaticPropsContext): Promise> {
  let content: Buffer;
  try {
    content = readFileSync(join("content", locale, "docs.mdx"));
  } catch (e) {
    content = readFileSync(join("content", "en", "docs.mdx"));
  }

  return {
    props: {
      content: await renderToString(content),
    },
  };
}

next-mdx-remote

utilities for loading mdx from any remote source as data, rather than as a local import

MPL-2.0
Latest version published 6 months ago

Package Health Score

78 / 100
Full package analysis