Skip to content

Commit da16147

Browse files
etewiahclaude
andcommitted
Prevent duplicate seed data and move widgets nav
- Move Embed Widgets from Insights to Website section in nav - Add semantic duplicate detection for links (same link_path + placement) - Improve logging in seed_pack for links and pages (shows skipped count) - Properties and pages already had proper duplicate protection This prevents issues like duplicate footer links when seeds are run multiple times or when YAML slugs change but content is the same. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a568771 commit da16147

File tree

3 files changed

+50
-16
lines changed

3 files changed

+50
-16
lines changed

app/views/layouts/site_admin/_navigation.html.erb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,6 @@
197197
</svg>
198198
<span>Analytics</span>
199199
<% end %>
200-
201-
<%= link_to site_admin_widgets_path, id: "tour-widgets", class: "flex items-center px-4 py-2 rounded-lg hover:bg-gray-700 #{request.path.start_with?('/site_admin/widgets') ? 'bg-gray-700' : ''}" do %>
202-
<svg class="w-5 h-5 mr-3" fill="currentColor" viewBox="0 0 20 20">
203-
<path fill-rule="evenodd" d="M12.316 3.051a1 1 0 01.633 1.265l-4 12a1 1 0 11-1.898-.632l4-12a1 1 0 011.265-.633zM5.707 6.293a1 1 0 010 1.414L3.414 10l2.293 2.293a1 1 0 11-1.414 1.414l-3-3a1 1 0 010-1.414l3-3a1 1 0 011.414 0zm8.586 0a1 1 0 011.414 0l3 3a1 1 0 010 1.414l-3 3a1 1 0 11-1.414-1.414L16.586 10l-2.293-2.293a1 1 0 010-1.414z" clip-rule="evenodd"></path>
204-
</svg>
205-
<span>Embed Widgets</span>
206-
<% end %>
207200
</div>
208201
</div>
209202

@@ -285,6 +278,13 @@
285278
<span>Domain</span>
286279
<% end %>
287280

281+
<%= link_to site_admin_widgets_path, id: "tour-widgets", class: "flex items-center px-4 py-2 rounded-lg hover:bg-gray-700 #{request.path.start_with?('/site_admin/widgets') ? 'bg-gray-700' : ''}" do %>
282+
<svg class="w-5 h-5 mr-3" fill="currentColor" viewBox="0 0 20 20">
283+
<path fill-rule="evenodd" d="M12.316 3.051a1 1 0 01.633 1.265l-4 12a1 1 0 11-1.898-.632l4-12a1 1 0 011.265-.633zM5.707 6.293a1 1 0 010 1.414L3.414 10l2.293 2.293a1 1 0 11-1.414 1.414l-3-3a1 1 0 010-1.414l3-3a1 1 0 011.414 0zm8.586 0a1 1 0 011.414 0l3 3a1 1 0 010 1.414l-3 3a1 1 0 11-1.414-1.414L16.586 10l-2.293-2.293a1 1 0 010-1.414z" clip-rule="evenodd"></path>
284+
</svg>
285+
<span>Embed Widgets</span>
286+
<% end %>
287+
288288
<%= link_to site_admin_onboarding_path, id: "tour-onboarding", class: "flex items-center px-4 py-2 rounded-lg hover:bg-gray-700 #{request.path.start_with?('/site_admin/onboarding') ? 'bg-gray-700' : ''}" do %>
289289
<svg class="w-5 h-5 mr-3" fill="currentColor" viewBox="0 0 20 20">
290290
<path fill-rule="evenodd" d="M6.267 3.455a3.066 3.066 0 001.745-.723 3.066 3.066 0 013.976 0 3.066 3.066 0 001.745.723 3.066 3.066 0 012.812 2.812c.051.643.304 1.254.723 1.745a3.066 3.066 0 010 3.976 3.066 3.066 0 00-.723 1.745 3.066 3.066 0 01-2.812 2.812 3.066 3.066 0 00-1.745.723 3.066 3.066 0 01-3.976 0 3.066 3.066 0 00-1.745-.723 3.066 3.066 0 01-2.812-2.812 3.066 3.066 0 00-.723-1.745 3.066 3.066 0 010-3.976 3.066 3.066 0 00.723-1.745 3.066 3.066 0 012.812-2.812zm7.44 5.252a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"></path>

lib/pwb/seed_pack.rb

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,16 +378,33 @@ def seed_links
378378

379379
links = YAML.safe_load(File.read(links_file), symbolize_names: true) || []
380380
count = 0
381+
skipped = 0
381382

382383
links.each do |link_data|
384+
# Check by slug first
383385
existing = @website.links.find_by(slug: link_data[:slug])
384-
unless existing
385-
@website.links.create!(link_data)
386-
count += 1
386+
if existing
387+
skipped += 1
388+
next
387389
end
390+
391+
# Also check for semantic duplicates (same link_path + placement)
392+
semantic_duplicate = @website.links.find_by(
393+
link_path: link_data[:link_path],
394+
link_path_params: link_data[:link_path_params],
395+
placement: link_data[:placement]
396+
)
397+
if semantic_duplicate
398+
log " Skipping '#{link_data[:slug]}' - semantic duplicate of '#{semantic_duplicate.slug}'", :detail
399+
skipped += 1
400+
next
401+
end
402+
403+
@website.links.create!(link_data)
404+
count += 1
388405
end
389406

390-
log " Created #{count} links", :detail
407+
log " Created #{count} links (#{skipped} skipped)", :detail
391408
end
392409

393410
def seed_pages
@@ -397,18 +414,23 @@ def seed_pages
397414
log "Seeding pages...", :info
398415

399416
count = 0
417+
skipped = 0
400418
Dir.glob(pages_dir.join('*.yml')).each do |page_file|
401419
page_data = YAML.safe_load(File.read(page_file), symbolize_names: true)
402420
next unless page_data
403421

422+
# Check by slug to prevent duplicates
404423
existing = @website.pages.find_by(slug: page_data[:slug])
405-
unless existing
406-
@website.pages.create!(page_data)
407-
count += 1
424+
if existing
425+
skipped += 1
426+
next
408427
end
428+
429+
@website.pages.create!(page_data)
430+
count += 1
409431
end
410432

411-
log " Created #{count} pages", :detail
433+
log " Created #{count} pages (#{skipped} skipped)", :detail
412434
end
413435

414436
def seed_page_parts

lib/pwb/seeder.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,22 @@ def set_field_key_translations(field_key, translations)
212212
def seed_links(yml_file)
213213
links_yml = load_seed_yml yml_file
214214
links_yml.each do |single_link_yml|
215-
# Check if this link already exists for this website
215+
# Check if this link already exists for this website by slug
216216
link_record = current_website.links.find_by(slug: single_link_yml["slug"])
217217

218+
# Also check for semantic duplicates (same link_path + placement)
219+
# This prevents creating duplicate links with different slugs
218220
unless link_record.present?
221+
semantic_duplicate = current_website.links.find_by(
222+
link_path: single_link_yml["link_path"],
223+
link_path_params: single_link_yml["link_path_params"],
224+
placement: single_link_yml["placement"]
225+
)
226+
if semantic_duplicate
227+
Rails.logger.info "Skipping link '#{single_link_yml['slug']}' - semantic duplicate of '#{semantic_duplicate.slug}'"
228+
next
229+
end
230+
219231
# Filter out unsupported locale attributes before creating
220232
filtered_attrs = filter_supported_locale_attrs(single_link_yml)
221233
# Create link with website association

0 commit comments

Comments
 (0)