diff --git a/package-lock.json b/package-lock.json index ff6639d6..8a3f260c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "19.6.16", + "version": "19.6.17", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "19.6.16", + "version": "19.6.17", "license": "MIT", "dependencies": { "@cdransf/api-text": "^1.4.0", diff --git a/package.json b/package.json index 13fa153b..8559bd35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "19.6.16", + "version": "19.6.17", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": { diff --git a/src/_data/posts.js b/src/_data/posts.js index 88bc9652..eef98114 100644 --- a/src/_data/posts.js +++ b/src/_data/posts.js @@ -21,6 +21,20 @@ const fetchBlockData = async (collection, itemId) => { return data } +const fetchTagsForPost = async (postId) => { + const { data, error } = await supabase + .from('posts_tags') + .select('tags(id, name)') + .eq('posts_id', postId) + + if (error) { + console.error(`Error fetching tags for post ${postId}:`, error) + return [] + } + + return data.map(pt => pt.tags.name) +} + const fetchBlocksForPost = async (postId) => { const { data, error } = await supabase .from('posts_blocks') @@ -43,24 +57,11 @@ const fetchBlocksForPost = async (postId) => { return blocks } -const fetchTagsForPost = async (postId) => { - const { data, error } = await supabase - .from('posts_tags') - .select('tags(id, name)') - .eq('posts_id', postId) - - if (error) { - console.error(`Error fetching tags for post ${postId}:`, error) - return [] - } - - return data.map(pt => pt.tags.name) -} - const fetchAllPosts = async () => { let posts = [] let page = 0 let fetchMore = true + const uniqueSlugs = new Set() while (fetchMore) { const { data, error } = await supabase @@ -77,11 +78,14 @@ const fetchAllPosts = async () => { if (data.length < PAGE_SIZE) fetchMore = false for (const post of data) { + if (uniqueSlugs.has(post.slug)) continue + + uniqueSlugs.add(post.slug) post.tags = await fetchTagsForPost(post.id) post.blocks = await fetchBlocksForPost(post.id) + posts.push(post) } - posts = posts.concat(data) page++ }