Switching from Raw Remark to Unified ecosystem
Better Styling Blog Styling
Overall Approach
As mentioned last week, my goal this week is to get the blog to play nicely with Tailwind, which means figuring out how I can apply Tailwind's utility classes to the html generated from the markdown files that make up each blog post.
As it turns out, it's fairly straightforward, we just need change the code in lib/getPostData.ts to change from using remark to using the unified ecosystem and some pre-existing rehype plugins.
Switching From Remark To Unified
The first step is changing from Remark html to the Unified ecosystem and changing how we parse the markdown.
- Install
unified,remark-parse,remark-rehype,rehype-formatandrehype-stringifyusing NPM or Yarn. - Change the
getPostDatafunction to use theunifiedecosystem, and chain each plugin, then end with aprocessof the content that we retrieved from the Markdown blog post. - Install the
rehype-add-classesplugin Rehype Add Classes - Create an object that maps the html elements to css classes, and add a final
use, passing therehype-add-classesplugin and the object to the call - Update the
purgeoption intailwind.config.jsto look inlib/posts.tsfor Tailwind classes that are being used
