From cfabae56d7066105dae25e2b66307f9772b027ad Mon Sep 17 00:00:00 2001 From: Luis Contreras Date: Fri, 9 Oct 2020 01:21:44 +0200 Subject: [PATCH 1/2] fix: ignore duplicated tags --- gatsby-node.js | 3 ++- src/util/stats.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 8f64c729..f3084861 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -5,7 +5,8 @@ function sourceNodes({ actions, createNodeId, createContentDigest }) { // Add People to the GraphQL API, we randomize the data on each build so no one gets their feelings hurt people .sort(() => Math.random() - 0.5) - .forEach(person => { + .forEach(p => { + const person = { ...p, tags: [...new Set(p.tags)] }; const nodeMeta = { id: createNodeId(`person-${person.name}`), parent: null, diff --git a/src/util/stats.js b/src/util/stats.js index d41e05d8..862cf86b 100644 --- a/src/util/stats.js +++ b/src/util/stats.js @@ -3,7 +3,8 @@ import people from '../data.js'; function merge(prop) { return function(acc, obj) { - return [...obj[prop], ...acc]; + const propEntries = [...new Set(obj[prop])]; + return [...propEntries, ...acc]; }; } From a8afcfe6b6ce41129572fabd834a66ba1941e6d4 Mon Sep 17 00:00:00 2001 From: Luis Contreras Date: Fri, 9 Oct 2020 01:39:14 +0200 Subject: [PATCH 2/2] refactor: rename variable and adding some comments --- gatsby-node.js | 1 + src/util/stats.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index f3084861..a70e9aec 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -6,6 +6,7 @@ function sourceNodes({ actions, createNodeId, createContentDigest }) { people .sort(() => Math.random() - 0.5) .forEach(p => { + // Remove duplicated tags. const person = { ...p, tags: [...new Set(p.tags)] }; const nodeMeta = { id: createNodeId(`person-${person.name}`), diff --git a/src/util/stats.js b/src/util/stats.js index 862cf86b..f016702d 100644 --- a/src/util/stats.js +++ b/src/util/stats.js @@ -3,8 +3,9 @@ import people from '../data.js'; function merge(prop) { return function(acc, obj) { - const propEntries = [...new Set(obj[prop])]; - return [...propEntries, ...acc]; + // Remove duplicated values. + const values = [...new Set(obj[prop])]; + return [...values, ...acc]; }; }