Skip to content

Commit b3899c3

Browse files
committed
feat: upd alpahs
1 parent aaa5f18 commit b3899c3

File tree

5 files changed

+89
-44
lines changed

5 files changed

+89
-44
lines changed

package-lock.json

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"sideEffects": false,
77
"dependencies": {
88
"@diplodoc/transform": "^4.18.0",
9-
"@gravity-ui/blog-constructor": "^8.5.0",
9+
"@gravity-ui/blog-constructor": "^9.0.0-alpha.1",
1010
"@gravity-ui/chartkit": "^6.1.1",
1111
"@gravity-ui/charts": "^0.8.0",
1212
"@gravity-ui/components": "^4.16.0",
@@ -16,7 +16,7 @@
1616
"@gravity-ui/icons": "^2.16.0",
1717
"@gravity-ui/markdown-editor": "^15.1.0",
1818
"@gravity-ui/navigation": "^3.8.0",
19-
"@gravity-ui/page-constructor": "^7.20.0-alpha.1",
19+
"@gravity-ui/page-constructor": "^8.0.0-alpha.1",
2020
"@gravity-ui/uikit": "^7.26.1",
2121
"@gravity-ui/uikit-themer": "^1.4.1",
2222
"@mdx-js/mdx": "^2.3.0",

src/components/Menu/LocalePicker/LocalePicker.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export const LocalePicker: React.FC = () => {
2626

2727
const appLocale = useLocale();
2828

29+
// Check if we're on a blog page - blog is only available for en and ru
30+
const isBlogPage = router.asPath.includes('/blog');
31+
2932
const renderOption = React.useCallback((option: SelectOption<string>) => {
3033
const locale = option.value;
3134
const localeUpperCase = option.value.toUpperCase();
@@ -43,13 +46,23 @@ export const LocalePicker: React.FC = () => {
4346
return null;
4447
}
4548

49+
// Filter locales for blog pages - only en and ru are available
50+
const availableLocales = React.useMemo(() => {
51+
if (isBlogPage) {
52+
return i18nextConfig.i18n.locales.filter(
53+
(locale) => locale === 'en' || locale === 'ru',
54+
);
55+
}
56+
return i18nextConfig.i18n.locales;
57+
}, [isBlogPage]);
58+
4659
return (
4760
<div className={b()}>
4861
<Select
4962
size="xl"
5063
width="max"
5164
value={[appLocale]}
52-
options={i18nextConfig.i18n.locales.map((locale) => ({
65+
options={availableLocales.map((locale) => ({
5366
value: locale,
5467
}))}
5568
renderOption={renderOption}
@@ -59,6 +72,11 @@ export const LocalePicker: React.FC = () => {
5972
return;
6073
}
6174

75+
// For blog pages, only allow en and ru
76+
if (isBlogPage && locale !== 'en' && locale !== 'ru') {
77+
return;
78+
}
79+
6280
setCookie({name: NEXT_LOCALE_COOKIE, value: locale});
6381

6482
router.push(router.pathname, router.asPath, {locale});

src/components/Menu/Menu.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export const Menu: React.FC = () => {
3434

3535
const {hideLocalePicker} = React.useContext(EnvironmentContext);
3636

37+
// Filter menu items based on locale - blog is only available for en and ru
38+
const filteredMenu = React.useMemo(() => {
39+
if (locale === 'en' || locale === 'ru') {
40+
return menu;
41+
}
42+
return menu.filter((item) => item.url !== '/blog');
43+
}, [locale]);
44+
3745
const renderItem = (item: MenuItem) => {
3846
if (item.isComingSoon) {
3947
return (
@@ -69,7 +77,7 @@ export const Menu: React.FC = () => {
6977

7078
<div className={b('desktop-menu')}>
7179
<div className={b('desktop-menu-items')}>
72-
{menu.map((item) => (
80+
{filteredMenu.map((item) => (
7381
<div
7482
key={item.titleKey}
7583
className={b('desktop-menu-item', {
@@ -121,7 +129,7 @@ export const Menu: React.FC = () => {
121129
<Row>
122130
<Col sizes={{sm: 12}}>
123131
<div className={b('mobile-menu-items')}>
124-
{menu.map((item) => (
132+
{filteredMenu.map((item) => (
125133
<div className={b('mobile-menu-item')} key={item.titleKey}>
126134
{renderItem(item)}
127135
</div>

src/middleware.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ const getLocaleFromCookie = (request: NextRequest): string | undefined => {
4444
export const middleware = async (request: NextRequest) => {
4545
const {pathname} = request.nextUrl;
4646

47+
// Blog is only available for en and ru locales
48+
// Check if path is related to blog
49+
const isBlogPath = pathname.includes('/blog');
50+
51+
if (isBlogPath) {
52+
const blogLocale = request.nextUrl.locale || defaultLocale;
53+
54+
// Redirect to en if locale is not en or ru
55+
if (blogLocale !== 'en' && blogLocale !== 'ru') {
56+
const url = request.nextUrl.clone();
57+
url.locale = 'en';
58+
return NextResponse.redirect(url);
59+
}
60+
61+
// For blog pages, ignore cookie-based locale detection to prevent redirect loops
62+
// Only use the current locale from URL, don't try to detect from cookie/headers
63+
return NextResponse.next();
64+
}
65+
4766
if (
4867
nextI18nextConfig.routesWithoutRedirect.some(
4968
(route) => pathname === route || pathname.startsWith(route),

0 commit comments

Comments
 (0)