Skip to content

Add permalink history for taxon on friendly-id#7

Merged
JustShah merged 1 commit intomainfrom
add-permalink-history-to-taxon
Feb 17, 2025
Merged

Add permalink history for taxon on friendly-id#7
JustShah merged 1 commit intomainfrom
add-permalink-history-to-taxon

Conversation

@JustShah
Copy link
Collaborator

@JustShah JustShah commented Feb 5, 2025

[WIP] Open Questions

This PR aligns URL handling of taxons with products.

Open questions:

  • The slugs of taxons are currently called permalinks (which they aren't), should they be renamed to slug (in backend and DB) creating also a migration

Related Issues, PRs and Discussions

Description

This PR introduces FriendlyId to the Taxon model to store the history of permalinks (slugs) and provides a more flexible approach to handling slugs for taxons.

Changes:

  • Taxon Model:

    • Added FriendlyId to the Taxon model, enabling it to generate and store slug history.
    • The before_save callback is used to set the permalink instead of before_create and before_update, allowing for better slug management.
    • Introduced a custom method for should_generate_new_friendly_id? to control when a new friendly ID should be generated, specifically when the permalink changes.
    • Added a custom normalize_friendly_id method to adjust how slugs are generated, especially for nested taxons, ensuring proper formatting of the slug.
  • Test:

    • Added a test to ensure that the history of permalinks is correctly stored when a taxon's permalink is updated. The test verifies that both the initial and updated slugs are retained in the history.

Motivation

This update enhances the management of taxon slugs by allowing historical tracking of slugs. This is particularly useful for SEO purposes and for maintaining accessibility of the resource if URLs change over time.

Note

The starter frontend PR is dependent for this change starter frontend PR

- Introduced FriendlyId to the Taxon model to enable slug history tracking.
- Replaced before_create and before_update callbacks with a before_save callback for better slug management.
- Implemented a custom should_generate_new_friendly_id? method to control when a new slug is generated, specifically when the permalink changes.
- Added a custom normalize_friendly_id method to ensure proper slug formatting for nested taxons.
- Included a test to verify that the history of permalinks is correctly stored when a taxon's permalink is updated, ensuring both initial and updated slugs are retained.

This change enhances the flexibility and reliability of handling slugs for taxons.
@JustShah JustShah force-pushed the add-permalink-history-to-taxon branch from 8722086 to 5618cc6 Compare February 10, 2025 10:36
@JustShah JustShah merged commit efe8b97 into main Feb 17, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant