This is the repo for swyx's blog - Blog content is created in github issues, then posted on swyx.io as blog pages! Comment/watch to follow along my blog within GitHub
source: devto
devToUrl: "https://dev.to/swyx/essential-plugins-for-gatsby-remark-a62"
devToReactions: 13
devToReadingTime: 6
devToPublishedAt: "2020-03-16T03:43:23.026Z"
devToViewsCount: 202
title: Essential Plugins for Gatsby Remark
published: true
description: Gatsby-Remark is one of those fun plugins that have their own plugins - but there are a lot of them. Here's a list I wrote down a few months ago of plugins I think everyone should use.
category: note
tags: Tech, React, Gatsby
slug: gatsby-remark-essential-plugins
displayed_publish_date: "2020-03-14"
canonical_url: https://www.swyx.io/writing/gatsby-remark-essential-plugins
Gatsby-Remark is one of those fun plugins that have their own plugins - but there are a lot of them! (Because Remark has a lot of plugins)
Here's a list of plugins I think everyone should use, and what they do.
Adds GitHub-style hover links to headers in your markdown files when they’re rendered.
This one is first because it is SO important to user experience. I link to anchor tags all the time (using the Display Anchors browser extension), and it is a pain to try to link to a specific part of a long blog post with a header that doesn't have an ID or a handy link for the user to copy! So remark-autolink-headings adds the ID and link tags:
# Lorem ipsum 😪
## dolor—sit—amet
### consectetur & adipisicing
#### elit
##### elit
The Gatsby version of this plugin also adds some nice hover styling with a nicer link icon, which you can see in the Kitchen Sink demo. Note that GitHub works like this by default.
This quite frankly was a straight up design flaw in Markdown and I flatly refuse to write any Markdown content without these enhancements.
Adds syntax highlighting to code blocks in markdown files using PrismJS.
This one is key for developer blogs. As a developer, you can pry syntax highlighting from my cold, dead, carpal tunnel ridden hands. Please don't make me read your blog without syntax highlighting.
Note, however, that PrismJS highlighting is done clientside, which will add ~19kb to your JS bundle so that you can do dynamic highlighting (i.e. if you need your reader to edit code and the highlighting to change accordingly). If you only need static highlighting, then you could look into only doing it at build time and sending no JS down the wire. I have used shiki from the Vue ecosystem, but gatsby-remark-shiki seems less popular.
However, this tradeoff is not free, because the syntax highlighted HTML that gets generated is bulkier, and you lose some very nice features like line highlighting, hence I continue to recommend Prism.js.
Copies local files linked to/from Markdown (.md|.markdown) files to the root directory (i.e., public folder).
This one is important because it lets you colocate your markdown with other resources, for example static files and images, instead of splitting them up into a "content" folder and a "static" and a "images" folder - resulting in an append-only folder of jumbled content where you don't know what belongs to what.
Processes images in markdown so they can be used in the production build.
We all know and love the benefits of Gatsby Image. Related to the above, when you reference an image from your markdown, you don't just want to load a simple image, you want to run it through Gatsby Sharp image processing to take advantage of the blur-up performance benefits.
Adds the target and rel attributes to external links in markdown.
This one is pretty simple - by default, Markdown links just translate to <a href="https://mylink.com"> links which cause people to navigate off your site. For some people this is desired behavior, but if you want Remark to automatically add target="_blank" and rel="nofollow noopener noreferrer" (for security), then this plugin does that for you.
gatsby-remark-social-cards iterates over your markdown files and automatically generates graphical representations of the frontmatter data! It’s highly customizable and can help increase your click rates.
As I blogged recently, OG Images are your site's calling card. Plain and simple, people read your social cards way more than your post content, so it ought to be appealing and informative instead of repetitive.
This plugin is well tested and has every feature you could want to transform Markdown frontmatter to your social unfurl card of choice.
Gatsby Remark plugin to embed well known services by their URL.
I'll just let them explain:
Trying to embed well known services (like CodePen, CodeSandbox, GIPHY, Instagram, Lichess, Pinterest, Slides, SoundCloud, Spotify, Streamable, Twitter or YouTube) into your Gatsby website can be hard, since you have to know how this needs to be done for all of these different services.
gatsby-remark-embedder tries to solve this problem for you by letting you just copy-paste the link to the pen/player/sandbox/tweet/video you want to embed right from within your browser onto a separate line (surrounded by empty lines) and replace it with the proper embed-code.
It's been a pleasure watching this plugin grow - the maintainer Michael is pretty diligent about adding more and more content types like SoundCloud and CodePen. These are simple components that we should not have to rewrite every time, and help make our blogposts a lot more interactive so that people don't have to leave our site to enjoy non-simple-text content.
Conclusion
You can create really great reading experiences with these plugins, and get a lot of mileage out of remark. They seem like relatively conservative choices which, should you have to move on from Gatsby or Remark in future, you could adapt and make work again without heavy rewriting of content. This is the promise of Markdown, after all.
I do wish more of these were framework agnostic, because all this work going into gatsby-remark plugins could have just been remark plugins and therefore usable by others. But of course there are some Gatsby specific concerns and opportunities that these plugins can take advantage of. But I worry that the community is unneccesarily splintered as a result.
What other Gatsby Remark plugins do you particularly like? Let me know in replies/comments!
source: devto devToUrl: "https://dev.to/swyx/essential-plugins-for-gatsby-remark-a62" devToReactions: 13 devToReadingTime: 6 devToPublishedAt: "2020-03-16T03:43:23.026Z" devToViewsCount: 202 title: Essential Plugins for Gatsby Remark published: true description: Gatsby-Remark is one of those fun plugins that have their own plugins - but there are a lot of them. Here's a list I wrote down a few months ago of plugins I think everyone should use. category: note tags: Tech, React, Gatsby slug: gatsby-remark-essential-plugins displayed_publish_date: "2020-03-14" canonical_url: https://www.swyx.io/writing/gatsby-remark-essential-plugins
Gatsby-Remark is one of those fun plugins that have their own plugins - but there are a lot of them! (Because Remark has a lot of plugins)
Here's a list of plugins I think everyone should use, and what they do.
Bottom Line Up Front
I'd recommend a
gatsby-config.js
that looks like:(Note I've omitted all options for these plugin-plugins, but you're probably going to want to specify some options for some of these)
Plugins
gatsby-remark-autolink-headers
This one is first because it is SO important to user experience. I link to anchor tags all the time (using the Display Anchors browser extension), and it is a pain to try to link to a specific part of a long blog post with a header that doesn't have an ID or a handy link for the user to copy! So remark-autolink-headings adds the ID and link tags:
to
The Gatsby version of this plugin also adds some nice hover styling with a nicer link icon, which you can see in the Kitchen Sink demo. Note that GitHub works like this by default.
This quite frankly was a straight up design flaw in Markdown and I flatly refuse to write any Markdown content without these enhancements.
gatsby-remark-prismjs
This one is key for developer blogs. As a developer, you can pry syntax highlighting from my cold, dead, carpal tunnel ridden hands. Please don't make me read your blog without syntax highlighting.
Note, however, that PrismJS highlighting is done clientside, which will add ~19kb to your JS bundle so that you can do dynamic highlighting (i.e. if you need your reader to edit code and the highlighting to change accordingly). If you only need static highlighting, then you could look into only doing it at build time and sending no JS down the wire. I have used
shiki
from the Vue ecosystem, but gatsby-remark-shiki seems less popular.However, this tradeoff is not free, because the syntax highlighted HTML that gets generated is bulkier, and you lose some very nice features like line highlighting, hence I continue to recommend Prism.js.
gatsby-remark-copy-linked-file
This one is important because it lets you colocate your markdown with other resources, for example static files and images, instead of splitting them up into a "content" folder and a "static" and a "images" folder - resulting in an append-only folder of jumbled content where you don't know what belongs to what.
So instead of this:
You get:
And Gatsby copies files out to the appropriate folder at build time.
gatsby-remark-images
We all know and love the benefits of Gatsby Image. Related to the above, when you reference an image from your markdown, you don't just want to load a simple image, you want to run it through Gatsby Sharp image processing to take advantage of the blur-up performance benefits.
gatsby-remark-external-links
This one is pretty simple - by default, Markdown links just translate to
<a href="https://mylink.com">
links which cause people to navigate off your site. For some people this is desired behavior, but if you want Remark to automatically addtarget="_blank"
andrel="nofollow noopener noreferrer"
(for security), then this plugin does that for you.gatsby-remark-numbered-footnotes
Footnotes are great! They let you add extra context without cluttering your message. You can write footnotes in Markdown like so:
And it looks like this (note I don't have this setup on my personal site yet):
This is normal body copy.[^also] It includes a couple footnotes.[^thing]
[^also]: This is a footnote.
[^thing]: This is another footnote.
Pretty nice to read!
gatsby-remark-social-cards
As I blogged recently, OG Images are your site's calling card. Plain and simple, people read your social cards way more than your post content, so it ought to be appealing and informative instead of repetitive.
This plugin is well tested and has every feature you could want to transform Markdown frontmatter to your social unfurl card of choice.
gatsby-remark-embedder
I'll just let them explain:
It's been a pleasure watching this plugin grow - the maintainer Michael is pretty diligent about adding more and more content types like SoundCloud and CodePen. These are simple components that we should not have to rewrite every time, and help make our blogposts a lot more interactive so that people don't have to leave our site to enjoy non-simple-text content.
Conclusion
You can create really great reading experiences with these plugins, and get a lot of mileage out of remark. They seem like relatively conservative choices which, should you have to move on from Gatsby or Remark in future, you could adapt and make work again without heavy rewriting of content. This is the promise of Markdown, after all.
I do wish more of these were framework agnostic, because all this work going into
gatsby-remark
plugins could have just beenremark
plugins and therefore usable by others. But of course there are some Gatsby specific concerns and opportunities that these plugins can take advantage of. But I worry that the community is unneccesarily splintered as a result.What other Gatsby Remark plugins do you particularly like? Let me know in replies/comments!