Created
October 17, 2019 07:04
-
-
Save sanderploegsma/4f11ccef1b94c3b72836d384ea9960e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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($language: String!) { | |
wordpress(language: $language) { | |
pages { | |
nodes { | |
id | |
slug | |
} | |
} | |
} | |
} | |
`; | |
const languages = ["nl", "en"]; | |
exports.createPages = async ({ graphql, actions }) => { | |
const { createPage } = actions; | |
for (const language of languages) { | |
const result = await graphql(pagesQuery, { language }); | |
for (const { id, slug } of result.wordpress.pages.nodes) { | |
createPage({ | |
path: `/${language}/${slug}`, | |
component: pageTemplate, | |
context: { | |
id, | |
language | |
} | |
}) | |
} | |
} | |
}; |
This file contains hidden or 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 { title, description } = data.wordpress.page; | |
return ( | |
<div> | |
<h1>{title}</h1> | |
<p>{description}</p> | |
</div> | |
); | |
}; | |
export const query = graphql` | |
query Page($id: String!, $language: String!) { | |
wordpress(language: $language) { | |
page(id: $id) { | |
title | |
description | |
} | |
} | |
} | |
`; | |
export default Page; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment