Skip to content

Commit f8b378c

Browse files
committed
refactor: Extract i18n out of nav definitions
1 parent aa8f339 commit f8b378c

File tree

4 files changed

+469
-595
lines changed

4 files changed

+469
-595
lines changed

src/components/blog-overview/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import config from '../../config.json';
2-
import { useLanguage, useTranslation, getRouteName } from '../../lib/i18n';
2+
import { useLanguage, useTranslation } from '../../lib/i18n';
33
import { Time } from '../time';
44
import { prefetchContent } from '../../lib/use-content';
55
import { BlogPage } from '../routes.jsx';
@@ -13,7 +13,8 @@ export default function BlogOverview() {
1313
<div>
1414
<div class={s.postList}>
1515
{config.blog.map(post => {
16-
const name = getRouteName(post, lang);
16+
//const name = getRouteName(post, lang);
17+
const name = 'FIXME';
1718
const excerpt = post.excerpt[lang] || post.excerpt.en;
1819

1920
const prefetchAndPreload = () => {

src/components/sidebar/index.jsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,44 @@ import DocVersion from '../doc-version';
33
import SidebarNav from './sidebar-nav';
44
import config from '../../config.json';
55
import { useOverlayToggle } from '../../lib/toggle-overlay';
6-
import { useLanguage, getRouteName } from '../../lib/i18n';
6+
import {
7+
useLanguage,
8+
getSidebarRouteName,
9+
getHeaderRouteName
10+
} from '../../lib/i18n';
711
import style from './style.module.css';
812

913
export default function Sidebar() {
10-
const { version } = useRoute().params;
14+
const {
15+
version
16+
} = /** @type {{ version: 'v8' | 'v10' | 'v11' }} */ (useRoute().params);
1117
const [lang] = useLanguage();
1218
const [open, setOpen] = useOverlayToggle();
1319

1420
const navItems = [];
15-
const routes = config.docs[version];
16-
for (let i = 0; i < routes.length; i++) {
17-
const item = routes[i];
21+
for (const item of config.docs[version]) {
1822
if (item.routes) {
1923
navItems.push({
20-
text: getRouteName(item, lang),
24+
text: getSidebarRouteName(item.name, lang),
2125
level: 2,
2226
href: null,
2327
routes: item.routes.map(nested => ({
24-
text: getRouteName(nested, lang),
28+
text: getSidebarRouteName(nested.name, lang),
2529
level: 3,
2630
href: `/guide/${version}${nested.path}`
2731
}))
2832
});
2933
} else {
3034
navItems.push({
31-
text: getRouteName(item, lang),
35+
text: getSidebarRouteName(item.name, lang),
3236
level: 2,
3337
href: `/guide/${version}${item.path}`
3438
});
3539
}
3640
}
3741

38-
// TODO: Need to entirely disassociate nav labels from URLs
39-
const guide = config.nav.find(
40-
item => item.path === '/guide/v10/getting-started'
41-
);
42-
const sectionName = getRouteName(guide, lang);
42+
// TODO: Is "Guide" really the best label for the button?
43+
const mobileButtonLabel = getHeaderRouteName('guide', lang);
4344

4445
return (
4546
<div class={style.wrapper} data-open={open}>
@@ -48,7 +49,7 @@ export default function Sidebar() {
4849
onClick={() => setOpen(v => !v)}
4950
value="sidebar"
5051
>
51-
{sectionName}
52+
{mobileButtonLabel}
5253
</button>
5354
<aside class={style.sidebar}>
5455
<div class={style.sidebarInner}>

0 commit comments

Comments
 (0)