fix: deduplicate tags

This commit is contained in:
Cory Dransfeldt 2023-09-08 12:55:35 -07:00
parent 8f6e26088c
commit 1dfa62dce6
No known key found for this signature in database

View file

@ -86,8 +86,9 @@ module.exports = function (eleventyConfig) {
if (item.data.collections.posts) { if (item.data.collections.posts) {
item.data.collections.posts.forEach((post) => { item.data.collections.posts.forEach((post) => {
const url = post.url.includes('http') ? post.url : `https://coryd.dev${post.url}` const url = post.url.includes('http') ? post.url : `https://coryd.dev${post.url}`
const tagString = post.data.tags const tagString = [
.map((tag) => { ...new Set(
post.data.tags.map((tag) => {
if ( if (
typeof tagAliases.tags.find((t) => t.aliases.includes(tag.toLowerCase()))?.[ typeof tagAliases.tags.find((t) => t.aliases.includes(tag.toLowerCase()))?.[
'tag' 'tag'
@ -97,6 +98,8 @@ module.exports = function (eleventyConfig) {
tagAliases.tags.find((t) => t.aliases.includes(tag.toLowerCase()))?.['tag'] tagAliases.tags.find((t) => t.aliases.includes(tag.toLowerCase()))?.['tag']
}` }`
}) })
),
]
.join(' ') .join(' ')
.trim() .trim()
if (tagString) tags[url] = tagString if (tagString) tags[url] = tagString
@ -104,8 +107,9 @@ module.exports = function (eleventyConfig) {
} }
if (item.data.links) { if (item.data.links) {
item.data.links.forEach((link) => { item.data.links.forEach((link) => {
const tagString = link.tags const tagString = [
.map((tag) => { ...new Set(
link.tags.map((tag) => {
if ( if (
typeof tagAliases.tags.find((t) => t.aliases.includes(tag.toLowerCase()))?.[ typeof tagAliases.tags.find((t) => t.aliases.includes(tag.toLowerCase()))?.[
'tag' 'tag'
@ -115,6 +119,8 @@ module.exports = function (eleventyConfig) {
tagAliases.tags.find((t) => t.aliases.includes(tag.toLowerCase()))?.['tag'] tagAliases.tags.find((t) => t.aliases.includes(tag.toLowerCase()))?.['tag']
}` }`
}) })
),
]
.join(' ') .join(' ')
.trim() .trim()
if (tagString) tags[link.url] = tagString if (tagString) tags[link.url] = tagString