Skip to content

Add RSS to Next.js MDX Blog. How do I convert MDX to HTML? #1295

Discussion options

You must be logged in to vote

This was a little complicated than I thought it would be. Anyways here are the changes I made to get the HTML:

I added resourceQuery: /rss/ to next.config.js like:

next.config.js

{
	resourceQuery: /rss/,
	use: [
		...mdx,
		createLoader(function (src) {
			return this.callback(null, src)
		}),
	],
},

Used the above rss query in getAllPostPreviews.js by adding a new function getAllPosts like:

getAllPostPreviews.js

export function getAllPosts() {
  return importAll(require.context('./pages/?rss', true, /\.mdx$/)).sort((a, b) =>
    dateSortDesc(a.module.meta.date, b.module.meta.date)
  )
}

I exported mdxComponents from Post.js like:

Post.js

export const mdxComponents = {
  ...
}

Finally, ch…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@deadcoder0904
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by deadcoder0904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants