Skip to content
Snippets Groups Projects
Commit 6e37d2e3 authored by Chris Fraser's avatar Chris Fraser
Browse files

Merge branch 'locale-redirect-for-blog-posts' into 'master'

updated regex to account for locales

See merge request gitlab-com/www-gitlab-com!139078
parents c091c2b3 d0f40426
No related branches found
No related tags found
No related merge requests found
......@@ -45,21 +45,21 @@ function needsEarlyRedirect(clientRequestURL: URL, clientRequest: Request): bool
function needsBlogRedirect(clientRequestURL: URL): boolean {
const { pathname } = clientRequestURL;
// Blog migration redirects
// const regex = /^\/(?:blog\/)?\d{4}\/\d{2}\/\d{2}\/([^\/]+)/;
const regex =
// eslint-disable-next-line no-useless-escape
const regex = /^\/(?:blog\/)?(?:2012|2013|2014|2015|2016|2017|2018|2019)\/\d{2}\/\d{2}\/([^\/]+)/;
/^\/(?:(?<locale>[a-z]{2}-[a-z]{2})\/)?(?:blog\/)?(?:2012|2013|2014|2015|2016|2017|2018|2019)\/\d{2}\/\d{2}\/(?<slug>[^\/]+)/;
const match = pathname.match(regex);
if (match) {
clientRequestURL.pathname = `/blog/${match[1]}/`;
if (match && match.groups) {
const { locale, slug } = match.groups;
const localePrefix = locale ? `/${locale}` : '';
clientRequestURL.pathname = `${localePrefix}/blog/${slug}/`;
return true;
}
// Blog tag lowercase redirects
// eslint-disable-next-line no-useless-escape
const tagRegex = /^\/blog\/tags\/([^\/]+)\/?$/;
const tagMatch = pathname.match(tagRegex);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment