Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views for pages with slugs will always redirect to the canonical slug #22

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

irskep
Copy link
Contributor

@irskep irskep commented Jul 21, 2024

This method requires maybe too much copypasta for hypothetical new endpoints. I also considered a couple other options which would make the call sites fail unless they do things correctly

(slugified_title, was_equal) = slugify_title(title)
if not was_equal:
    return redirect(...)
try:
    title = slugify_title(title)
except SlugMismatch as e:
    return redirect(...) # where SlugMismatch has the slug value
@with_slugified_url(key='title', make_url=lambda title: url_for('page.xxx', title=title'))
def view(title):
  # ...

...but these seemed like overkill.

@irskep irskep force-pushed the slugify-redirect branch 2 times, most recently from 701e8c2 to 4edc4fe Compare July 21, 2024 17:54
@irskep irskep force-pushed the slugify-redirect branch from 4edc4fe to a74ac67 Compare July 21, 2024 17:55
@cu
Copy link
Owner

cu commented Jul 26, 2024

Ideally this snippet would be applied to every route with <title> in the URL... but this was already a corner case of a purely cosmetic nature so this is certainly good enough for the time being.

@cu cu merged commit c6786b9 into cu:master Jul 26, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants