I have a code that loops through all existing posts, I need to do some comprobations after pushing an array of tags, such as if the post has a locale set, if it has tags and even if it has content, etc.
posts.map(({ node }) => {
if (node.frontmatter.content && node.frontmatter.content.tags) node.frontmatter.content.tags.map(tag => tags.push(tag));
if (node.frontmatter.locale) tags.push(node.frontmatter.locale);
return Array.from(new Set(tags));
});
It seems quite logical that it is possible to refactor those 2 conditions in something more semantic or clean, but I didn't find any solution yet.
If you also have any other advice or tip, please don't hesitate.
Thanks.
Aucun commentaire:
Enregistrer un commentaire