-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'DIGG-512' into release-5.1.2
- Loading branch information
Showing
34 changed files
with
766 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { NextResponse } from "next/server"; | ||
import type { NextRequest } from "next/server"; | ||
|
||
import i18n from "./i18n"; | ||
|
||
function getLocale(request: NextRequest): string { | ||
const acceptLanguage = request.headers.get("accept-language"); | ||
if (acceptLanguage) { | ||
const [browserLocale] = acceptLanguage.split(","); | ||
if (i18n.locales.includes(browserLocale as string)) { | ||
return browserLocale; | ||
} | ||
} | ||
return i18n.defaultLocale; | ||
} | ||
|
||
export function middleware(request: NextRequest) { | ||
const pathname = request.nextUrl.pathname; | ||
|
||
// Check if the pathname already has a locale | ||
const pathnameHasLocale = i18n.locales.some( | ||
(locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`, | ||
); | ||
|
||
if (pathnameHasLocale) { | ||
// If it's the default locale, redirect to remove it from URL | ||
if (pathname.startsWith(`/${i18n.defaultLocale}/`)) { | ||
const newPathname = pathname.replace(`/${i18n.defaultLocale}`, "") || "/"; | ||
const newUrl = new URL(newPathname, request.url); | ||
newUrl.search = request.nextUrl.search; | ||
return NextResponse.redirect(newUrl); | ||
} | ||
return NextResponse.next(); | ||
} | ||
|
||
const locale = getLocale(request); | ||
|
||
// Only add locale to URL if it's not the default locale | ||
if (locale !== i18n.defaultLocale) { | ||
const newUrl = new URL(`/${locale}${pathname}`, request.url); | ||
newUrl.search = request.nextUrl.search; | ||
return NextResponse.redirect(newUrl); | ||
} | ||
|
||
// For default locale, just continue without modification | ||
return NextResponse.next(); | ||
} | ||
|
||
export const config = { | ||
matcher: [ | ||
"/((?!api|_next/static|_next/image|favicon.ico|__ENV.js|manifest.json|.*\\.(?:jpg|jpeg|gif|png|svg|woff|woff2)).*)", | ||
"/", | ||
], | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,53 @@ | ||
import { GetServerSidePropsContext } from "next/types"; | ||
import { useRouter } from "next/router"; | ||
import { useContext, useEffect, useState } from "react"; | ||
|
||
import { ConceptPage } from "@/features/entryscape/concept-page"; | ||
import { EntrystoreProvider } from "@/providers/entrystore-provider"; | ||
import { SettingsContext } from "@/providers/settings-provider"; | ||
import { handleEntryStoreRedirect } from "@/utilities/entrystore/entrystore-redirect"; | ||
|
||
export default function Concept() { | ||
return null; | ||
} | ||
const { env } = useContext(SettingsContext); | ||
const router = useRouter(); | ||
const { concept, param } = router.query || {}; | ||
const [resourceUri, setResourceUri] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchEntryStoreProps = async () => { | ||
if (!concept || !param) return; | ||
const isSandbox = window.location.host.includes("sandbox"); | ||
|
||
const data = await handleEntryStoreRedirect( | ||
{ | ||
pathPrefix: "/concepts", | ||
redirectPath: "/concepts", | ||
entrystorePathKey: "ENTRYSCAPE_TERMS_PATH", | ||
param: concept, | ||
secondParam: param as string, | ||
}, | ||
router, | ||
router.locale || "sv", | ||
isSandbox, | ||
); | ||
|
||
if (data?.resourceUri) { | ||
setResourceUri(data.resourceUri); | ||
} | ||
}; | ||
|
||
export const getServerSideProps = async ( | ||
context: GetServerSidePropsContext, | ||
) => { | ||
return handleEntryStoreRedirect(context, { | ||
pathPrefix: "/concepts", | ||
redirectPath: "/concepts", | ||
entrystorePathKey: "ENTRYSCAPE_TERMS_PATH", | ||
paramName: "concept", | ||
secondParamName: "param", | ||
}); | ||
}; | ||
fetchEntryStoreProps(); | ||
}, [concept, param]); | ||
|
||
if (!resourceUri) return null; | ||
|
||
return ( | ||
<EntrystoreProvider | ||
env={env} | ||
rUri={resourceUri} | ||
entrystoreUrl={env.ENTRYSCAPE_TERMS_PATH} | ||
pageType="concept" | ||
> | ||
<ConceptPage /> | ||
</EntrystoreProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.