Shared layouts for markdown files in Remix

In the previous article, we added the Typography Tailwind plugin to render each blog nicely.
However, we didn’t have an excellent place to put the prose class for rendering purposes.

We set the prose on the root.tsx file.
This works, but it means we a…


This content originally appeared on DEV Community and was authored by Chris Bongers

In the previous article, we added the Typography Tailwind plugin to render each blog nicely.
However, we didn't have an excellent place to put the prose class for rendering purposes.

We set the prose on the root.tsx file.
This works, but it means we add the prose class to literally every rendered page.

To make it a bit more sustainable, we can use the shared layouts method to create a unique blog layout.

Adding a shared markdown layout

When we set up our markdown files in Remix, we dedicated a blog folder for them.

We can simply create a blog.tsx file in our routes directory to use the shared layout.

This file can be used to render specific layouts for the blog items.

Let's keep it super simple for now:

import { Outlet } from '@remix-run/react';

export default function Blog() {
  return (
    <div className='prose'>
      <h1>Welcome to the blog:</h1>
      <Outlet />
    </div>
  );
}

Each blog item will now have this static heading title and its markdown rendered inside the outlet!

Resulting in the following:

Markdown layout in Remix

The cool part is that this layout can be as extended as you want, and it will be used by all markdown files in the blog directory!

If you are interested, I uploaded the code for this article on this GitHub repo.

Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter


This content originally appeared on DEV Community and was authored by Chris Bongers


Print Share Comment Cite Upload Translate Updates
APA

Chris Bongers | Sciencx (2022-05-13T04:52:41+00:00) Shared layouts for markdown files in Remix. Retrieved from https://www.scien.cx/2022/05/13/shared-layouts-for-markdown-files-in-remix/

MLA
" » Shared layouts for markdown files in Remix." Chris Bongers | Sciencx - Friday May 13, 2022, https://www.scien.cx/2022/05/13/shared-layouts-for-markdown-files-in-remix/
HARVARD
Chris Bongers | Sciencx Friday May 13, 2022 » Shared layouts for markdown files in Remix., viewed ,<https://www.scien.cx/2022/05/13/shared-layouts-for-markdown-files-in-remix/>
VANCOUVER
Chris Bongers | Sciencx - » Shared layouts for markdown files in Remix. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/05/13/shared-layouts-for-markdown-files-in-remix/
CHICAGO
" » Shared layouts for markdown files in Remix." Chris Bongers | Sciencx - Accessed . https://www.scien.cx/2022/05/13/shared-layouts-for-markdown-files-in-remix/
IEEE
" » Shared layouts for markdown files in Remix." Chris Bongers | Sciencx [Online]. Available: https://www.scien.cx/2022/05/13/shared-layouts-for-markdown-files-in-remix/. [Accessed: ]
rf:citation
» Shared layouts for markdown files in Remix | Chris Bongers | Sciencx | https://www.scien.cx/2022/05/13/shared-layouts-for-markdown-files-in-remix/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.