Giter Club home page Giter Club logo

simonhalimonov.com's Introduction

type-coverage

This is a personal site and blog. Built on GatsbyJS, TS and a headless WordPress CMS.

This project is open source to educate and simplify the development process of future sites that use GatsbyJS and WordPress. The goal is to fully support these key features:

  • ๐Ÿ”ฅ Fast load speeds. Under 1s on mobile and desktop.
  • ๐Ÿ’ฏ High Lighthouse scores. Almost 100 on mobile and desktop.
  • ๐Ÿ“ Minimal and precise layout for easy customizations
  • ๐ŸŒ Multilingual support via i18n (Work in progress)
  • ๐Ÿ“ Editor-friendly setup with accurate previews
  • ๐Ÿค– SEO optimised site
  • โœ… Accessibility optimised site (Work in progress)
  • ๐Ÿ”ƒ Programmatic page creation
  • โญ๏ธ Gutenberg support (Work in progress)
  • ๐Ÿ‘ WordPress theme optimised for headless
  • ๐Ÿ’ฏ High TypeScript coverage and high type safety

Note: Some features are still work in progress.

Setup

Configure all environment variables and have your WordPress installation running ().

  1. Install all dependencies npm i or yarn
  2. Add environment variables
  3. Run development environment npm start or yarn start

Using the environment variables

GATSBY_WORDPRESS_URL_PATH the domain or IP to the WordPress installation

GATSBY_WORDPRESS_URL_PROTOCOL the HTTP protocol used

GATSBY_INSTAGRAM_SOURCE the name of the instagram account

GATSBY_TWITTER_SOURCE the name of the twitter account

GATSBY_GOOGLE_ANALYTICS the Google Analytics tracking id

WordPress Setup

You can read about how to setup a free WordPress site on GCP in my post.

  • Create a single post and page
    • Post
      • Add a tag (required)
      • Add featured image (required)
    • Page
      • Add featured image (required)
  • Settings
    • Use permalinks with post name (required)
    • Set a page as the front page (required)
    • Create a menu (required)
      • The first menu item will be used for the logo
      • All other menu items will be generated dynamically
  • Install the theme (required)
    • It will do following things:
      • It modifies REST API
      • It disables the WP frontend
      • It reroutes all pages to the REST API
  • Install plugins and activate them (required)
    • Polylang (required)
      • Configure a main language that reflect the gatsby-config.js
      • This site uses en_US as the default language
      • The secondary language is de_DE
      • Configure a menu for both languages
    • Polylang REST API (required)
    • WP REST API MENU (required)
    • WP Webhooks (optional)
      • Trigger a webhook on Vercel or Netlify for a redeploy
    • ACF (optional)

Setting up a cheap WordPress CMS

With a cloud provider, you can easily host a WordPress CMS installation for free with this setup. You can read how to setup a WordPress CMS on GCP here.

I recommend AWS or GCP, as they have very good free tiers. The lowest virtual machine instance should be enough. They also have 1-click install setups.


Features

i18n support

This project supports Polylang via REST API. Note: Full i18n support is a work in progress

Static, programatic and dynamic content

Static content is written directly in the codebase. Add pages in /src/pages/ to create new static content.

Programatic content is created during build time. This uses GatsbyJS source plugins to fetch data and translating that data into static HTML files.

Dynamic content is created on the client side. In GatsbyJS you can use a custom router to create dynamic pages. The preview feature uses this to show a preview of the revision of post/page.

HTML Parsing to custom React components

Content from WordPress is being parsed, converted to JSX and then rendered to HTML. This enables full control in the frontend to create rich interactive experiences with all features of React. Gutenberg Blocks translate into custom React components in the HMTL.tsx file.

Posts, Tags, Categories and Pages

Use posts, tags, categories and pages in WordPress to build your site.

Full TS support in Gatsby

This project aims to have a high type safety to reduce possible issues. Currently it has 92.43% type coverage. You can check the type coverage by running npm types or yarn types. This was possible due to this GitHub Gist and the credits mentioned in there.

Simple WordPress Template support

Use the default template attribute from wordpress to choose the file that will be used for the page template.

Page templates can be found in src/templates/... and the mapping happen in src/gatsby/node/index.ts.

Preview pages in the Gatsby frontend

Previews are being rendered in the Gatsby frontend by fetching the data from a modified WordPress REST API. The modified REST API exposes the latest revisions of the post. This means that you don't have to deal with nonce and other authentication strategies. By default all revisions are only available with an authenticated REST API. I did this, because it was a pain in the ass to get it properly working.

Custom WordPress Theme for a headless installation

This project uses a custom theme to deactivate most of the regular frontend of WordPress.


Folder structure

./src
โ”œโ”€โ”€ components # React components folder
โ”‚   โ”œโ”€โ”€ AnimateWords
โ”‚   โ”‚   โ””โ”€โ”€ AnimateWords.tsx
โ”‚   โ”œโ”€โ”€ Footer
โ”‚   โ”‚   โ””โ”€โ”€ index.tsx
โ”‚   โ”œโ”€โ”€ GridHelper # Grid overlay
โ”‚   โ”‚   โ””โ”€โ”€ GridHelper.tsx
โ”‚   โ”œโ”€โ”€ HTML
โ”‚   โ”‚   โ””โ”€โ”€ HTML.tsx
โ”‚   โ”œโ”€โ”€ Header
โ”‚   โ”‚   โ””โ”€โ”€ index.tsx
โ”‚   โ”œโ”€โ”€ Image
โ”‚   โ”‚   โ””โ”€โ”€ Image.tsx
โ”‚   โ”œโ”€โ”€ Instagram
โ”‚   โ”‚   โ””โ”€โ”€ index.tsx
โ”‚   โ”œโ”€โ”€ InviewMotion
โ”‚   โ”‚   โ””โ”€โ”€ InviewMotion.tsx
โ”‚   โ”œโ”€โ”€ Layout # Common layout components
โ”‚   โ”‚   โ”œโ”€โ”€ PageTitleAnimation.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ Section.tsx
โ”‚   โ”‚   โ””โ”€โ”€ index.tsx # Global layout wrapper
โ”‚   โ”œโ”€โ”€ Layouts # Shared grid layouts
โ”‚   โ”‚   โ””โ”€โ”€ ContentWithSidebar.tsx
โ”‚   โ”œโ”€โ”€ Logo
โ”‚   โ”‚   โ””โ”€โ”€ Logo.tsx
โ”‚   โ”œโ”€โ”€ SEO # Component used for SEO
โ”‚   โ”‚   โ””โ”€โ”€ index.tsx
โ”‚   โ”œโ”€โ”€ SocialSidebar
โ”‚   โ”‚   โ””โ”€โ”€ SocialSidebar.tsx
โ”‚   โ”œโ”€โ”€ Transition # Component used for page transitions
โ”‚   โ”‚   โ””โ”€โ”€ Transition.tsx
โ”‚   โ”œโ”€โ”€ Twitter
โ”‚   โ”‚   โ””โ”€โ”€ index.tsx
โ”‚   โ”œโ”€โ”€ Typography # Folder for typography components
โ”‚   โ”‚   โ”œโ”€โ”€ H.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ P.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ S.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ XL.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ XS.tsx
โ”‚   โ”‚   โ””โ”€โ”€ index.tsx # Barrel file
โ”‚   โ””โ”€โ”€ WorkSlider
โ”‚       โ””โ”€โ”€ WorkSlider.tsx
โ”œโ”€โ”€ contracts # TypeScript definitions
โ”‚   โ”œโ”€โ”€ page.ts
โ”‚   โ”œโ”€โ”€ post.ts
โ”‚   โ”œโ”€โ”€ preview.ts
โ”‚   โ”œโ”€โ”€ templates.ts
โ”‚   โ””โ”€โ”€ util.ts
โ”œโ”€โ”€ gatsby # Internal GatsbyJS code
โ”‚   โ”œโ”€โ”€ config
โ”‚   โ”‚   โ””โ”€โ”€ index.ts
โ”‚   โ”œโ”€โ”€ node
โ”‚   โ”‚   โ””โ”€โ”€ index.ts
โ”‚   โ”œโ”€โ”€ shouldUpdateScroll.js
โ”‚   โ””โ”€โ”€ wrapPageElement.js
โ”œโ”€โ”€ gatsby-plugin-theme-ui
โ”‚   โ””โ”€โ”€ index.js # Theme settings
โ”œโ”€โ”€ images
โ”‚   โ”œโ”€โ”€ leaf-01.png # folder
โ”‚   ...
โ”œโ”€โ”€ pages # Static pages
โ”‚   โ”œโ”€โ”€ 404.tsx # Custom 404 page
โ”‚   โ”œโ”€โ”€ kitchensink.tsx # Page to test WordPress Gutenberg Blocks
โ”‚   โ””โ”€โ”€ preview.tsx # Page used for previews
โ”œโ”€โ”€ templates
โ”‚   โ”œโ”€โ”€ Blog # All post related page templates
โ”‚   โ”‚   โ”œโ”€โ”€ BlogCategoryPosts.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ BlogPost.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ BlogPostTeaser.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ BlogPosts.tsx
โ”‚   โ”‚   โ””โ”€โ”€ BlogTagPosts.tsx
โ”‚   โ””โ”€โ”€ Page # All custom page templates
โ”‚       โ”œโ”€โ”€ CoverPage.tsx
โ”‚       โ”œโ”€โ”€ DefaultPage.tsx
โ”‚       โ”œโ”€โ”€ FullWidthPage.tsx
โ”‚       โ”œโ”€โ”€ HomePage.tsx # Page used for the homepage
โ”‚       โ”œโ”€โ”€ WorkIndex.tsx # Page used to display all work projects
โ”‚       โ””โ”€โ”€ WorkIndexTeaser.tsx # Component used in WorkIndex page
โ””โ”€โ”€ utils # Utility function folder
    โ”œโ”€โ”€ index.ts
    โ””โ”€โ”€ useInterval.tsx

Missing Features and To-Do's

  • Add WordPress Theme to repository
    • Add instructions for local development
    • Add instructions for deployment
  • Add i18n support
    • Static pages
    • Footer
    • Overview pages
  • Add draft preview support
  • Add support for more essential Gutenberg Blocks

Credits

This is based on a version of Gatsby Wordpress Typescript Blog Boilerplate by sagar7993. It is heavily modified from the original.

The WordPress theme is based on Postlight's Headless WordPress + React Starter Kit by Postlight. It was modified by including revisions in the REST API response and adding some page templates.

GatsbyJS + TypeScript was possible because of this GitHub Gist and the credits mentioned in there.

simonhalimonov.com's People

Contributors

simulieren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

simonhalimonov.com's Issues

Theme file?

I tried using the Postlight Headless Wordpress theme you pointed to, but seems like it's missing the stuff you mention on README.md. Would you upload the theme file to the repository?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.