Last active
October 17, 2019 06:56
-
-
Save sanderploegsma/785a0fbee47148ea245678ce944f3216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.plugins = [ | |
{ | |
resolve: `gatsby-source-graphql`, | |
options: { | |
typeName: `WordPressNL`, | |
fieldName: `wordpressNL`, | |
url: `example.com/graphql` | |
} | |
}, | |
{ | |
resolve: `gatsby-source-graphql`, | |
options: { | |
typeName: `WordPressEN`, | |
fieldName: `wordpressEN`, | |
url: `example.com/en/graphql` | |
} | |
}, | |
// ... other languages | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const pageTemplate = path.resolve("gatsby-page-template.js"); | |
const pagesQuery = ` | |
query Pages { | |
wordpressNL { | |
pages { | |
nodes { | |
id | |
slug | |
} | |
} | |
} | |
wordpressEN { | |
pages { | |
nodes { | |
id | |
slug | |
} | |
} | |
} | |
# ... other languages | |
} | |
`; | |
const createLocalizedPages = (createPage, pages, language) => | |
pages.forEach(({ id, slug }) => createPage({ | |
path: `/${language}/${slug}`, | |
component: pageTemplate, | |
context: { | |
id, | |
language | |
} | |
})); | |
exports.createPages = async ({ graphql, actions }) => { | |
const { createPage } = actions; | |
const result = await graphql(pagesQuery); | |
createLocalizedPages(createPage, result.data.wordpressNL.pages.nodes, "nl"); | |
createLocalizedPages(createPage, result.data.wordpressEN.pages.nodes, "en"); | |
// ... other languages | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { graphql } from "gatsby"; | |
const Page = ({ data }) => { | |
const page = data.wordpressNL.page || data.wordpressEN.page; // ... other languages | |
return ( | |
<div> | |
<h1>{page.title}</h1> | |
<p>{page.description}</p> | |
</div> | |
); | |
}; | |
export const query = graphql` | |
query Page($id: String!) { | |
wordpressNL { | |
page(id: $id) { | |
title | |
description | |
} | |
} | |
wordpressEN { | |
page(id: $id) { | |
title | |
description | |
} | |
} | |
# ... other languages | |
} | |
`; | |
export default Page; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment