...
 
Commits (12)
nodejs 12.13.0
nodejs 12.13.0
......@@ -2,6 +2,9 @@ const path = require(`path`);
const { createFilePath } = require(`gatsby-source-filesystem`);
const titleCase = require('title-case').titleCase;
const uniq = require('lodash').uniq;
const includes = require('lodash').includes;
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
......@@ -54,69 +57,67 @@ exports.createPages = async ({ graphql, actions }) => {
}
`);
await asyncForEach(result.data.allMarkdownRemark.edges, async ({ node }) => {
const {
frontmatter,
fields: { slug },
html,
} = node;
const linkResult = await graphql(`
query {
allLinksYaml(
filter: {categories: {in: ["${slug.replace(/^\/|\/$/g, '')}"]}}
sort: {fields: title, order: ASC}
) {
edges {
node {
title
url
description
const allLinksQuery = await graphql(`
query {
allDataYaml {
edges {
node {
links {
categories
charity_url
countries
description
featured
tags
title
type
url
}
}
}
}
`);
}
`);
const allLinks = allLinksQuery.data.allDataYaml.edges[0].node.links;
const links = linkResult.data.allLinksYaml.edges.map(edge => edge.node);
await asyncForEach(result.data.allMarkdownRemark.edges, async ({ node }) => {
const {
frontmatter,
fields: { slug },
html,
} = node;
const sanitizedSlug = slug.replace(/^\/|\/$/g, '');
const linksForThisCategory = allLinks.filter(link =>
includes(link.categories, sanitizedSlug)
);
createPage({
path: slug,
component: path.resolve(`./src/templates/category.jsx`),
context: { category: frontmatter, html, links, slug },
context: {
category: frontmatter,
html,
links: linksForThisCategory,
slug,
},
});
});
const allTags = await graphql(`
{
allLinksYaml {
tags: distinct(field: tags)
}
}
`);
let allTags = [];
await asyncForEach(allTags.data.allLinksYaml.tags, async tag => {
const linksForTag = await graphql(`
query {
allLinksYaml(
filter: {tags: {in: ["${tag.replace(/^\/|\/$/g, '')}"]}}
sort: {fields: title, order: ASC}
) {
edges {
node {
title
url
description
countries
}
}
}
}
`);
allLinks.forEach(link => {
allTags = [...allTags, ...link.categories];
});
allTags = uniq(allTags);
const links = linksForTag.data.allLinksYaml.edges.map(edge => edge.node);
await asyncForEach(allTags, async tag => {
const sanitizedTag = tag.replace(/^\/|\/$/g, '');
const linksForTag = allLinks.filter(link =>
includes(link.tags, sanitizedTag)
);
// The tag name with the dashes replaced with spaces and the first letter in each word capitalised.
const humanReadableTag = titleCase(tag);
......@@ -124,7 +125,7 @@ exports.createPages = async ({ graphql, actions }) => {
createPage({
path: `/tags/${tag}`,
component: path.resolve(`./src/templates/tag.jsx`),
context: { tag: humanReadableTag, links },
context: { tag: humanReadableTag, links: linksForTag },
});
});
};
......@@ -6,8 +6,6 @@ intro: Wherever you are in the world there's something you can do.
Wherever you are in the world there's something you can do. Research local land trusts or land management organizations to see if they need help. You can help maintain woodlands, eradicate invasive species, and monitor deforestation. Even just going for a hike on popular trails to collect rubbish can stop wildlife dying from eating plastic. Walking along any stretch of beach you'll find plenty of trash, and stop it going out to join the [Great Pacific Garbage Patch](https://www.nationalgeographic.org/encyclopedia/great-pacific-garbage-patch/) or [North Atlantic Garbage Patch](https://en.wikipedia.org/wiki/North_Atlantic_garbage_patch).
Research your local "Gleaners" network, to go to farms and pick the "second harvest" (i.e slightly bruised but edible food) to reduce food waste and help bolster food banks.
You don't need to fly to the Seychelles for a week of volunteering to pick up litter, those "Go Abroad" programs just encourage flying around and that ruins the impact you're having on the world.
You don't need to fly to the Seychelles for a week of volunteering to pick up litter, you can do that anywhere, on a hike, at the beach, or by a lake. Similarly you can research your local "Gleaners" network. Gleaners go to farms and pick the "second harvest" (i.e slightly bruised but edible food) to reduce food waste and help bolster food banks.
Here are a few more specific ideas.
This source diff could not be displayed because it is too large. You can view the blob instead.
import React, { useState } from 'react';
import { graphql, navigate } from 'gatsby';
import flag from 'country-code-emoji';
import { flattenDeep } from 'lodash';
import { union } from 'lodash';
import { Layout } from '../components';
import CountryContext from '../context/country-context';
......@@ -10,13 +10,10 @@ export default ({ data }) => {
const countries = require('i18n-iso-countries').getNames('en');
const [searchTerm, setSearchTerm] = useState('');
const countriesWithContent = flattenDeep([
...new Set(
data.allLinksYaml.edges
.map(({ node }) => node.countries)
.filter(countryList => !!countryList)
),
]).map(countryCode => countryCode.toUpperCase());
let countriesWithContent = [];
data.allDataYaml.nodes[0].links.forEach(link => {
countriesWithContent = union(countriesWithContent, link.countries);
});
return (
<Layout title={data.site.siteMetadata.title} seoTitle="Select Your Country">
......@@ -116,9 +113,9 @@ export const pageQuery = graphql`
title
}
}
allLinksYaml {
edges {
node {
allDataYaml {
nodes {
links {
countries
}
}
......