Gatsby - Cookbook

This cookbook contains recipes that demonstrate how to solve common problems while working with Gatsby.

commit fcbf3ea · authored · amended · 2 min read

Gatsby - Cookbook

I 💟 Gatsby. This article contains some recipes which will be useful if you are into Gatsby for your next static site. Recipes are,

Using Google fonts in Gatsby

Import the font css on your site main css file.

Using gatsby-plugin-prefetch-google-fonts.

  • Install the plugin gatsby-plugin-prefetch-google-fonts
Terminal window
yarn add gatsby-plugin-prefetch-google-fonts
  • Modify gatsby-config.js. Inside the plugins array, add
{
resolve: `gatsby-plugin-prefetch-google-fonts`,
options: {
fonts: [
{
family: `Oswald`,
subsets: [`latin`],
},
{
family: `Open Sans`,
variants: [`400`, `700`]
},
],
},
}

You can change the font family and variants or number of fonts in the above configuration according to your website needs.

Using icons like Font Awesome in Gatsby

Using react-icons.

Add it to your packages.

Terminal window
npm install react-icons --save

And in your react component

import { FaBeer } from "react-icons/fa";
class Question extends React.Component {
render() {
return (
<h3>
{" "}
Lets go for a <FaBeer />?{" "}
</h3>
);
}
}

Disqus integration in a Gatsby website

Since Gatsby is built on top of React, we can use the React package for Disqus.

Terminal window
yarn add disqus-react

And in your post component

import { DiscussionEmbed } from "disqus-react";

Define the Disqus configuration like

const disqusConfig = {
shortname: `yourDisqusShortName`,
config: { identifier: slug, title },
};

Here identifier is the unique id for your post, it can be anything.

And now you can render the Disqus section by adding

<DiscussionEmbed {...disqusConfig} />

More recipes will be added as I explore Gatsby.

local graph · open full graph

"Gatsby - Cookbook" is connected to the topics Gatsby, Cookbook, React and related to 6 other entries. Best FREE Form Provider for Static Websites Best FREE Form Provider for… Azure DevOps - GatsbyJs Build Pipeline Azure DevOps - GatsbyJs Bui… GatsbyJS - Add Google AdSense GatsbyJS - Add Google AdSen… Gatsby - See All Generated Pages Gatsby - See All Generated … Microsoft SQL Server Guy Trying Oracle Database Microsoft SQL Server Guy Tr… Docker: Cookbook Docker: Cookbook Gatsby #gatsby Cookbook #cookbook React #react Gatsby - Cookbook

comments

loading discussion…