Skip to content

This is the source code for my GatsbyJS site built from scratch using Tailwindcss and DaisyUI. It a JAM Stack application and the blogs and projects are written in markdown.

License

Notifications You must be signed in to change notification settings

ankitsamaddar/my-portfolio-blog-site-gatsby

Repository files navigation

Gatsby Portfolio with Blog and Projects

πŸš€ A beautifully crafted portfolio site built with GatsbyJS React Framework, Tailwind CSS, and Daisy UI, featuring dynamic content generation, SEO optimizations, and an elegant user interface with dark and light theme. This site includes a blog section, project showcases, a contact form, and advanced SEO features like schema markup and Google Analytics integration. Perfect for developers looking to create a personal or professional online presence.

Table of Contents

Project Overview

This portfolio site is built from scratch using the Gatsby starter template. It includes five main pages: index, projects, blogs, tags, and contact. The site is designed to showcase projects and blogs written in Markdown, processed dynamically by Gatsby's transformer remark plugin.

Project Structure

β”œβ”€β”€ markdown
β”‚   β”œβ”€β”€ blogs
β”‚   β”‚   β”œβ”€β”€ blog2.md
β”‚   β”‚   └── blog1.md
β”‚   └── projects
β”‚       β”œβ”€β”€ project2.md
β”‚       └── project1.md
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ components
β”‚   β”‚   β”œβ”€β”€ breadcrumbs.js
β”‚   β”‚   β”œβ”€β”€ contactForm.js
β”‚   β”‚   β”œβ”€β”€ graphComment.js
β”‚   β”‚   β”œβ”€β”€ header.js
β”‚   β”‚   β”œβ”€β”€ layout.js
β”‚   β”‚   β”œβ”€β”€ projectCarousel.js
β”‚   β”‚   β”œβ”€β”€ SeoComponent.js
β”‚   β”‚   β”œβ”€β”€ socialLinks.js
β”‚   β”‚   └── techIconGrid.js
β”‚   β”œβ”€β”€ pages
β”‚   β”‚   β”œβ”€β”€ 404.js
β”‚   β”‚   β”œβ”€β”€ blogs.js
β”‚   β”‚   β”œβ”€β”€ contact.js
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”œβ”€β”€ projects.js
β”‚   β”‚   └── tags.js
β”‚   β”œβ”€β”€ styles
β”‚   β”‚   └── global.css
β”‚   └── templates
β”‚       β”œβ”€β”€ blog-template.js
β”‚       └── tag-template.js
β”œβ”€β”€ gatsby-browser.js
β”œβ”€β”€ gatsby-config.js
β”œβ”€β”€ gatsby-node.js
β”œβ”€β”€ package.json
β”œβ”€β”€ postcss.config.js
└── tailwind.config.js

Key Features

πŸ“š Dynamic Content Generation

The blog and project contents are written in Markdown and processed by Gatsby's gatsby-transformer-remark plugin to generate dynamic pages.

  • Each Markdown file is parsed into a node of type MarkdownRemark.

  • This plugin adds additional fields to the MarkdownRemark GraphQL type including html, excerpt, headings, etc.

    {
      allMarkdownRemark {
        edges {
          node {
            html
            headings {
              depth
              value
            }
            frontmatter {
              # Assumes you're using title in your frontmatter.
              title
            }
          }
        }
      }
    }
  • Other Gatsby plugins can also enhance the content and add addition fields.

πŸ“Š SEO Optimizations

  • Schema Markup: Added schema markup to each page using the Gatsby Head API for better SEO. For multiple meta tags, use React Fragments.

    export function Head() {
      return (
        <>
          <html lang="en" />
          <body className="my-body-class" />
          <title>Hello World</title>
        </>
      )
    } 
  • SEO Component: A reusable SEO.js React component to manage metadata and schema markup across pages.

  • Schema Markup: schemaMarkup is typically a JSON object in the JSON-LD for structured data, so it can simply be defined as a constant inside the Head component. The JavaScript object then can be passed as a prop to the SEO component.

    export const Head = ({ pageContext }) => {
      const schemaMarkup = {
        "@context": "https://schema.org",
        "@type": "WebPage",
        "name": pageContext.title,
        "description": pageContext.description,
        "url": pageContext.url,
        "image": pageContext.image
        // You can add more fields as needed for your schema markup
      };
    
      return (
        <SEO
          title={pageContext.title}
          description={pageContext.description}
          image={pageContext.image}
          schemaMarkup={schemaMarkup}
        />
      );
    };

πŸ“© Contact Form

  • A custom contactForm.js React component that validates user inputs and sends email via mailto: protocol or uses Web3Forms API to send message.

  • Web3Forms API Integration:

    // src/components/contactForm.js
    import React, { useState } from "react";
    import PhoneInput from "react-phone-number-input";
    const ContactForm = () => {
      // ...
      const accessToken = process.env.GATSBY_REACT_APP_WEB3FORMS_ACCESS_TOKEN // Web3Forms access token
    
      try {
        const response = await fetch("https://api.web3forms.com/submit", {
          method: "POST",
          body: formData,
        })
        //
      }
      return (
        <form....>
          //....
        </form>
      );
    };

🎠 Project Carousel

  • A carousel React component built with react-slick to showcase projects on the homepage.
    //src/components/projectCarousel.js
    import React from "react";
    import Slider from "react-slick";
    import "slick-carousel/slick/slick.css"
    import "slick-carousel/slick/slick-theme.css"
    
    const ProjectCarousel = ({ projects }) => {
      //...
      return (
        <Slider {...settings}>
          //.....
        </Slider>
      );
    };
    
    export default ProjectCarousel;

πŸ“ˆ Google Analytics Integration

  • Integrated Google Analytics 4 (GA4) using gatsby-plugin-google-tagmanager to get web analytics for the page.

  • The plugin dispatches a gatsby-route-change event on every route change, which is captured in GTM by creating a Custom Event Trigger for this event.

    // gatsby-config.js
    module.exports = {
      plugins: [
        {
          resolve: "gatsby-plugin-google-tagmanager",
          options: {
            id: process.env.GATSBY_GOOGLE_TAGMANAGER_ID,
            includeInDevelopment: false,
            enableWebVitalsTracking: true,
          },
        },
        // ....
      ],
    };

πŸ—ΊοΈ Sitemap and Robots.txt

  • Added gatsby-plugin-sitemap and gatsby-plugin-robots-txt for SEO improvements.

    // gatsby-config.js
    module.exports = {
      plugins: [
        `gatsby-plugin-sitemap`,
        `gatsby-plugin-robots-txt`,
        // ...
      ],
    };
  • The sitemap.xml and robots.txt ensure search engines can effectively navigate your site while respecting the crawling rules.

Setup Instructions

  1. Clone the repository:

    git clone https://github.com/yourusername/your-repo.git
  2. Install dependencies:

    npm install
  3. Install gastby-cli:

    npm install -g gatsby-cli
  4. Start the development server:

    gatsby develop
  5. Build the site:

    gatsby build

Deployment

This site is deployed using GitHub Pages. The gh-pages npm package is used to host the public directory after building the site.

gh-pages -d public

Contributing

Contributions are welcome! Please open an issue or pull request if you have any suggestions or find any bugs.

License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.

About

This is the source code for my GatsbyJS site built from scratch using Tailwindcss and DaisyUI. It a JAM Stack application and the blogs and projects are written in markdown.

Topics

Resources

License

Stars

Watchers

Forks