Skip to content

Commit

Permalink
Add part 5 draft and fix some issues in part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikwirth committed Dec 3, 2019
1 parent 3fec19b commit c30efe7
Show file tree
Hide file tree
Showing 4 changed files with 2,583 additions and 2,519 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Try running `gatsby develop` and navigate to `http://localhost:8000/___graphql`.

### Create Pages & Posts

Now let's see, how we can create pages and posts, based on the WordPress data. **First remove the `page-2.js` in your pages folder.** Then, we start with some very simple templates.
Now let's see, how we can create pages and posts, based on the WordPress data. **First remove the `index.js` and `page-2.js` in your pages folder.** Then, we start with some very simple templates.

#### Page Template

Expand Down Expand Up @@ -250,6 +250,7 @@ const GET_PAGES = `
pageId
content
uri
isFrontPage
}
}
}
Expand Down Expand Up @@ -339,9 +340,18 @@ module.exports = async ({ actions, graphql, reporter }, options) => {
await fetchPages({ first: itemsPerPage, after: null }).then((wpPages) => {

wpPages && wpPages.map((page) => {
let pagePath = `/${page.uri}/`

/**
* If the page is the front page, the page path should not be the uri,
* but the root path '/'.
*/
if(page.isFrontPage) {
pagePath = '/'
}

createPage({
path: `/${page.uri}/`,
path: pagePath,
component: pageTemplate,
context: {
page: page,
Expand All @@ -358,6 +368,7 @@ module.exports = async ({ actions, graphql, reporter }, options) => {

- So here we first define our `fetchPages()` function, that will recursively keep on fetching pages (10 at a time) until there is no more to fetch. It adds them to the `allPages` array.
- Then, we map over `wpPages` and call `createPage()`. An action passed down by the `createPagesStatefully()` function given by the Gatsby API ([See docs here](https://www.gatsbyjs.org/docs/node-apis/#createPagesStatefully)).
- We use `page.isFrontPage` to check if we need to adjust the path. For the home page we want the path to be the root path `/` instead of `/home/`.
- In `createPage()` we set the path equal to the uri. This will be creating the slug for the individual page. The **component** gets our `pageTemplate` assigned and finally, we pass the pages data to the context.

**-> See the complete file here: [createPages.js](https://github.com/henrikwirth/gatsby-starter-wordpress-advanced/blob/tutorial/part-2/create/createPages.js)**
Expand Down
28 changes: 28 additions & 0 deletions articles/guide-to-gatsby-wordpress-starter-advanced/5-Images.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
---
published: false
title: "How to handle Images and make use of gatsby-image - Guide to Gatsby WordPress Starter Advanced with Previews, i18n and more"
cover_image: "https://raw.githubusercontent.com/henrikwirth/dev.to/master/articles/guide-to-gatsby-wordpress-starter-advanced/images/05/cover.png"
description: "The Deployment part of a tutorial, explaining how to create an advanced Gatsby site with WordPress as a headless CMS."
tags: gatsby, wordpress, webdev, tutorial
series: "Guide to Gatsby WordPress Starter Advanced"
canonical_url:
---

After the [previous part](https://dev.to/nevernull/deployment-guide-to-gatsby-wordpress-starter-advanced-with-previews-i18n-and-more-2g2o) we are able to deploy our site. Now what about images? Gatsby comes with a super helpful plugin called [gatsby-image](https://www.gatsbyjs.org/packages/gatsby-image/) for image processing at build time.

In this part I will show you, how you can make use of gatsby-images superpowers and deliver your images in a static fashion.

## Table of Contents

## Create Images in WordPress

Let's create some

- WordPress Bilder anlegen
- Featured images
- Post Inline images.
- Gatsby image
- gatsby resolver
- Fallback image?
-



## What's Next :arrow_right:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c30efe7

Please sign in to comment.