Skip to content

Commit

Permalink
Merge pull request #20 from carlaiau/grid-component
Browse files Browse the repository at this point in the history
Grid component, ability to add grid to advanced-countries template
  • Loading branch information
carlaiau authored Apr 1, 2020
2 parents 72f400a + 02f185f commit 340751b
Show file tree
Hide file tree
Showing 17 changed files with 655 additions and 784 deletions.
49 changes: 28 additions & 21 deletions client/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,18 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
}
`);

if (result.errors) {
if (result.errors)
reporter.panic('error loading docs', result.errors);
}


const countries = result.data.allCountriesJson.nodes;

countries.forEach(c => {
if(c.name != "United States" && c.name != "Canada" && c.name != 'Australia' && c.name != "China"){ // Custom Structure
actions.createPage({
path: '/' + c.name.toLowerCase().replace(/\s+/g, "-"),
component: require.resolve('./src/templates/country-template.js'),
context: {
country: c.name,
},
});
}
});


const advanced_country_pages = [

const advanced_countries = [
{
slug: 'australia',
name: 'Australia',
checkedAreas: ['New South Wales', 'Victoria', 'Queensland']
checkedAreas: ['New South Wales', 'Victoria', 'Queensland'],
show_grid: true,
hide_deaths: true
},
{
slug: 'china',
Expand All @@ -53,7 +41,9 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
slug: 'canada',
name: 'Canada',
checkedAreas: ['Ontario', 'Saskatchewan', 'Quebec', 'British Columbia'],
area_label: "province or territory"
area_label: "province or territory",
show_grid: true

},
{
slug: 'united-states',
Expand All @@ -62,14 +52,31 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
}
]

advanced_country_pages.forEach( p => {
// Create basic page for each country not in the advanced countries array
countries.filter(c => {
return ! advanced_countries.map(adv_c => adv_c.name).includes(c.name)
})
.forEach(c => {
actions.createPage({
path: '/' + c.name.toLowerCase().replace(/\s+/g, "-"),
component: require.resolve('./src/templates/country-template.js'),
context: {
country: c.name,
},
});
});

advanced_countries.forEach( p => {
actions.createPage({
path: '/' + p.slug,
component: require.resolve('./src/templates/advanced-country-template.js'),
context: p // Each countries object gets passed in as context object
});
})

// Create Index Page
actions.createPage({path: '/', component: require.resolve('./src/templates/index-template.js') });




Expand Down
Loading

0 comments on commit 340751b

Please sign in to comment.