Skip to content

Instantly share code, notes, and snippets.

@Ekwuno
Ekwuno / _middleware.js
Last active May 10, 2022 15:22
Middleware for handling A/B testing in Pages projects with cookies.
const cookieName = "ab-test-homepage"
const newHomepagePathName = "/test"
const abtest = async ({ request, next, env }) => {
const url = new URL(request.url)
// if homepage
if (url.pathname === "/") {
// if cookie ab-test-hp=new
// if no cookie set, pass xy% of traffic and set a cookie value (current|new)
@Ekwuno
Ekwuno / pages.yml
Created April 21, 2022 07:39
GH action for pages
name: GitHub Actions Pages Publish
on: [push]
jobs:
pages-publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup node v16
uses: actions/setup-node@v3
@Ekwuno
Ekwuno / {mdx.slug}.js
Created February 28, 2021 16:01
This version uses Gatsby plugin Image
import React from "react";
import Layout from "../../components/layout";
import { graphql } from "gatsby";
import { MDXRenderer } from "gatsby-plugin-mdx";
import { GatsbyImage, getImage } from "gatsby-plugin-image";
export const query = graphql`
query($slug: String) {
mdx(slug: { eq: $slug }) {
frontmatter {
@Ekwuno
Ekwuno / {Mdx.slug}.js
Created February 26, 2021 21:46
This is the component returns a particular blog post and renders it's content on the screen
import React from "react";
import Layout from "../../components/layout";
import { graphql } from "gatsby";
import { MDXRenderer } from "gatsby-plugin-mdx";
const BlogPosts = ({ data }) => {
return (
<Layout>
<MDXRenderer>{data.mdx.body}</MDXRenderer>
6:34:51 PM: Build ready to start
6:34:53 PM: build-image version: d84c79427e8f83c1ba17bcdd7b3fe38059376b68
6:34:53 PM: build-image tag: v3.6.1
6:34:53 PM: buildbot version: 3f7ff7bbf92b8c2ecf180659ea5b1472b472d308
6:34:53 PM: Fetching cached dependencies
6:34:53 PM: Starting to download cache of 260.7MB
6:34:55 PM: Finished downloading cache in 1.798008079s
6:34:55 PM: Starting to extract cache
6:35:04 PM: Finished extracting cache in 9.117188517s
6:35:04 PM: Finished fetching cache in 11.013865637s

Setup Gatsby-image

gatsby-image is a React component specially designed to work seamlessly with Gatsby’s GraphQL queries. It combines Gatsby’s native image processing capabilities with advanced image loading techniques to easily and completely optimize image loading for your sites. gatsby-image uses gatsby-plugin-sharp to power its image transformations.


Install necessary NPM packages

Add Authentication with Auth0 to a Gatsby site

All the pieces of authentication are possible in Gatsby. Thanks to Auth0, setting it up doesn't have to be so cumbersome!

This setup comes straight from Auth0's official quick start for React.


The first step is installing the official Auth0 SDK for JavaScript from npm.

<CSSTransition
in={this.state.example}
timeout={500}
classNames='example'
unmountOnExit
>
@Ekwuno
Ekwuno / crazy-buttons-base.markdown
Created February 5, 2019 19:21
Crazy Buttons Base