From 9195070b576afee2c206124ad243e9678349a7c0 Mon Sep 17 00:00:00 2001 From: lumi-tip Date: Wed, 11 Dec 2024 12:04:24 -0400 Subject: [PATCH 1/3] refactor middleware for redirects --- src/middleware.js | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/middleware.js b/src/middleware.js index 0534239ae..9c7569bde 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -17,32 +17,41 @@ export const config = { }; async function middleware(req) { - const url = await req.nextUrl.clone(); + const url = req.nextUrl.clone(); const { href, origin } = url; - const fullPath = href.replace(origin, ''); + let fullPath = href.replace(origin, ''); + + const localeMatch = fullPath.match(/^\/(es|en|us)(\/|$)/); + const localePrefix = localeMatch ? localeMatch[1] : null; + + if (localePrefix) { + fullPath = fullPath.replace(`/${localePrefix}`, ''); + } const aliasAndLessonRedirects = [...aliasRedirects, ...redirectsFromApi]; + const currentProject = aliasAndLessonRedirects.find((item) => { - const destinationIsNotEqualToSource = item?.source !== item?.destination; + const normalizedSource = item.source.endsWith('/') ? item.source.slice(0, -1) : item.source; + const normalizedPath = fullPath.endsWith('/') ? fullPath.slice(0, -1) : fullPath; - if (item?.source === fullPath && destinationIsNotEqualToSource) return true; - return false; + return ( + normalizedSource === normalizedPath || normalizedSource === `/${localePrefix}${normalizedPath}` + ) && item.source !== item.destination; }); - const conditionalResult = () => { - if (currentProject?.type === 'PROJECT-REROUTE' && currentProject?.source) { - return true; + // Evitar redirecciones infinitas + if (currentProject) { + const destinationUrl = `${origin}${currentProject.destination}`; + if (destinationUrl === href) { + log('Middleware: already on destination URL, skipping redirect.'); + return NextResponse.next(); } - if (currentProject?.source) { - return true; - } - return false; - }; - if (conditionalResult()) { - log(`Middleware: redirecting from ${fullPath} → ${currentProject?.destination}`); - return NextResponse.redirect(`${origin}${currentProject?.destination || ''}`); + log(`Middleware: redirecting from ${href} → ${currentProject.destination}`); + return NextResponse.redirect(destinationUrl, 301); } + return NextResponse.next(); } + export default middleware; From 6b8c527e9cbe2545ef4fcce0dcc9802810b41b89 Mon Sep 17 00:00:00 2001 From: lumi-tip Date: Wed, 11 Dec 2024 17:21:55 -0400 Subject: [PATCH 2/3] using version 1 of quotes --- src/common/components/MarkDownParser/MDComponents/index.jsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/common/components/MarkDownParser/MDComponents/index.jsx b/src/common/components/MarkDownParser/MDComponents/index.jsx index 6e050e7ac..385606b1b 100644 --- a/src/common/components/MarkDownParser/MDComponents/index.jsx +++ b/src/common/components/MarkDownParser/MDComponents/index.jsx @@ -286,11 +286,7 @@ function QuoteVersion4({ ...props }) { ); } export function Quote({ children }) { - const [version, setVersion] = useState(2); - - useEffect(() => { - setVersion(Math.floor(Math.random() * 4) + 1); - }, []); + const version = 1; if (version === 1 && children.length > 0) { return ( From 15c76fd03e0968f1173e241cef154f33bddd75c4 Mon Sep 17 00:00:00 2001 From: lumi-tip Date: Wed, 11 Dec 2024 17:24:04 -0400 Subject: [PATCH 3/3] run back --- src/common/components/MarkDownParser/MDComponents/index.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/components/MarkDownParser/MDComponents/index.jsx b/src/common/components/MarkDownParser/MDComponents/index.jsx index 385606b1b..6e050e7ac 100644 --- a/src/common/components/MarkDownParser/MDComponents/index.jsx +++ b/src/common/components/MarkDownParser/MDComponents/index.jsx @@ -286,7 +286,11 @@ function QuoteVersion4({ ...props }) { ); } export function Quote({ children }) { - const version = 1; + const [version, setVersion] = useState(2); + + useEffect(() => { + setVersion(Math.floor(Math.random() * 4) + 1); + }, []); if (version === 1 && children.length > 0) { return (