From 753b84cdf198afc51a596ee59146a23118963ca8 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Wed, 8 Jun 2016 20:30:26 +0000 Subject: [PATCH] Also allow blog fid's to remove double dashes --- rophako/modules/blog/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/rophako/modules/blog/__init__.py b/rophako/modules/blog/__init__.py index e5f18db..f536b1d 100644 --- a/rophako/modules/blog/__init__.py +++ b/rophako/modules/blog/__init__.py @@ -103,10 +103,17 @@ def entry(fid): # or end, and remove them and see if we have a match. This allows for # fixing blog fid's that allowed leading/trailing dashes and having the # old URL just redirect to the new one. - post_id = Blog.resolve_id(fid.strip("-"), drafts=True) + fid = fid.strip("-") + post_id = Blog.resolve_id(fid, drafts=True) + + # If still nothing, try consolidating extra dashes into one. + if not post_id: + fid = re.sub(r'-+', '-', fid) + post_id = Blog.resolve_id(fid, drafts=True) + + # Did we find one now? if post_id: - # Got one! Redirect to it. - return redirect(url_for(".entry", fid=fid.strip("-"))) + return redirect(url_for(".entry", fid=fid)) flash("That blog post wasn't found.") return redirect(url_for(".index"))