Skip to content

How to pass in Markdown file as argument? #1252

Answered by remcohaszing
hbhutta asked this question in Q&A
Discussion options

You must be logged in to vote

Adding onto @ChristianMurphy’s answer, I recommend using Vite and MDX. It’s the closest to what you have currently.

The only configuration you need is:

// vite.config.js
import { defineConfig } from 'vite'
import mdx from '@mdx-js/rollup'

export default defineConfig({
  plugins: [
    mdx()
  ]
})

That should allow you to import and render your markdown file like this.

import React from "react";
import BlogPost from "../path/to/post.md";

export default function Blogs() {
  return (
    <BlogPost />
  )
}

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@remcohaszing
Comment options

@hbhutta
Comment options

@ChristianMurphy
Comment options

@remcohaszing
Comment options

Answer selected by hbhutta
@hbhutta
Comment options

@ChristianMurphy
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants