Giter Club home page Giter Club logo

astro-wp-v2's Introduction

Astro WordPress Starter Evolution

This project is meant to be a flexible starting point for people interested in using Astro with WordPress as a headless CMS. If you want some additional resources to help get you started, check out the blog post and video linked below.

It's a continuation of the original Astro WordPress Starter

โœ๏ธ Read the step-by-step tutorial ๐Ÿ“น Watch the video

I added an authentication to make things more secure, check the links below.

Requirements

Add a variable to your .env and then hit npm run dev:

GRAPHQL_URL = https://yoursitename.com/graphql

GRAPHQL_PASSWORD = yoursupersecurepassword

Routing and Templates

This starter project leans into the WordPress CMS routing capabilities and uses a getNodeByUri query in WPGraphQL to handle any route path that WordPress knows about. This allows you to handle all WordPress content types using the [...uri].astro component. From there, Astro parses the uri and uses that to call getNodeByURI from api.js to fetch data about that resource from the CMS. Once data is returned, we look at the content type and then dynamically resolve a content template from the templates directory.

Adding Content Types

This project comes with built in support for Post, Page, Tag, and Category types, but could easily be extended for custom post types or other native content types. To add support for a custom post type you would do the following:

  1. Add a GraphQL fragment for your post type to getNodeByURI from api.js
  2. Add an Astro component as a template
  3. Add a case to the switch statement in [...uri].astro to catch the content type and resolve the template

Overriding Default Routing

Since routes using rest parameters in Astro come last in the route priority order, you can easily override this catch-all routing pattern by creating a more specific route to handle a given path.

For example, if you want the path /category/food-trucks to be handled by a different Astro component, you can add a corresponding file to the pages directory to override the default ...uri route.

Menus

By default, the menus were replaced by a custom query of static pages for navigation, default behavior in a clean instalation of WordPress, at least in LocalWP.

Rendering and Serving

This project is using the new hybrid rendering model available in Astro v2. To pre-render any routes you add, make sure to include the following export in your Astro component's frontmatter:

export const prerender = true;

All of the current routes are being pre-rendered to HTML and served using the standalone node adapter. This offers users the flexibility to create additional SSR functionality if desired while still optimizing content pages using pre-rendered HTML.

Headless WordPress Hosting with Atlas

WP Engine's Atlas platform provides a performant and user-friendly hosting platform for headless WordPress and Node-based JavaScript apps. Create a free sandbox account to try the platform, and check out our Astro deployment guide for instruction to deploy to the platform.

Notes

Almost all README from the original project was preserved, after all I just create a different theme, just a shell of the great work done before.

The dates were set to Brazilian Portuguese locale, it's very simple to set to any locale, just use yours with appropriate string, like toLocaleDateString('en-US', options). The options are very easy to understand as well, options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', }.

Quick install

A fresh instance of WordPress with LocalWP, just this WPGraphQL plugin installed.

The env variables could be commented until the authentication is ready.

astro-wp-v2's People

Contributors

teseu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.