Skip to content

Commit 160b19f

Browse files
committed
feat(.vitepress): add i18n and sidebar integration
Integrate vitepress-i18n and vitepress-sidebar, refactor VitePress config to support multi-locale sidebar generation, update Chinese path to /zhHans/, add rewrites and i18n/sidebar options, and update lockfile with required packages.
1 parent 633c232 commit 160b19f

File tree

20 files changed

+477
-95
lines changed

20 files changed

+477
-95
lines changed

docs/.vitepress/config.ts

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { defineConfig } from "vitepress";
1+
import { defineConfig, UserConfig } from "vitepress";
2+
import { withSidebar } from "vitepress-sidebar";
3+
import { withI18n } from "vitepress-i18n";
4+
import { VitePressI18nOptions } from "vitepress-i18n/types";
25

3-
// https://vitepress.dev/reference/site-config
4-
export default defineConfig({
6+
const vitePressConfig: UserConfig = {
57
base: "/",
68
title: "Tessera",
79
description: "A declarative, immediate-mode UI framework for Rust",
@@ -22,44 +24,22 @@ export default defineConfig({
2224
if (pathname === base || pathname === (base + 'index.html')) {
2325
const userLang = navigator.language;
2426
if (userLang.toLowerCase().startsWith('zh')) {
25-
window.location.replace(base + 'zh/' + search + hash);
27+
window.location.replace(base + 'zhHans/' + search + hash);
2628
}
2729
}
2830
})();
2931
`,
3032
],
3133
],
3234

33-
locales: {
34-
root: {
35-
label: "English",
36-
},
37-
zh: {
38-
label: "简体中文",
39-
lang: "zh-CN",
40-
link: "/zh/",
41-
},
35+
rewrites: {
36+
"en/:rest*": ":rest*",
4237
},
4338

4439
themeConfig: {
4540
// https://vitepress.dev/reference/default-theme-config
4641
logo: "/icon-text-only.svg",
4742
siteTitle: false,
48-
nav: [
49-
{ text: "Home", link: "/" },
50-
{ text: "Guide", link: "/guide/getting-started" },
51-
{ text: "About", link: "/about/about" },
52-
],
53-
54-
sidebar: [
55-
{
56-
text: "Docs",
57-
items: [
58-
{ text: "What is Tessera?", link: "/guide/what-is-tessera" },
59-
{ text: "Getting Started", link: "/guide/getting-started" },
60-
],
61-
},
62-
],
6343

6444
socialLinks: [
6545
{ icon: "github", link: "https://github.com/tessera-ui/tessera" },
@@ -71,9 +51,55 @@ export default defineConfig({
7151

7252
footer: {
7353
message: "Licensed under the MIT or Apache-2.0 at your option.",
74-
copyright: "Copyright © Tessera UI Framework Developers"
54+
copyright: "Copyright © Tessera UI Framework Developers",
7555
},
7656

7757
i18nRouting: true,
7858
},
79-
});
59+
};
60+
61+
const supportedLocales = ["en", "zhHans"];
62+
const rootLocale = "en";
63+
64+
const commonVitePressSidebarConfig = {
65+
useTitleFromFrontmatter: true,
66+
useFolderTitleFromIndexFile: true,
67+
sortMenusByFrontmatterOrder: true,
68+
};
69+
70+
const vitePressSidebarConfigs = supportedLocales.map((lang) => ({
71+
...commonVitePressSidebarConfig,
72+
...(lang === rootLocale ? {} : { basePath: `/${lang}/` }),
73+
documentRootPath: `docs/${lang}`,
74+
resolvePath: lang === rootLocale ? "/" : `/${lang}/`,
75+
}));
76+
77+
const vitePressI18nConfig: VitePressI18nOptions = {
78+
// VitePress I18n config
79+
locales: ["en", "zhHans"],
80+
searchProvider: "local",
81+
themeConfig: {
82+
zhHans: {
83+
nav: [
84+
{ text: "主页", link: "/zhHans" },
85+
{ text: "手册", link: "/zhHans/guide/getting-started" },
86+
{ text: "关于", link: "/zhHans/about" },
87+
],
88+
},
89+
en: {
90+
nav: [
91+
{ text: "Home", link: "/" },
92+
{ text: "Guide", link: "/guide/getting-started" },
93+
{ text: "About", link: "/about" },
94+
],
95+
},
96+
},
97+
};
98+
99+
// https://vitepress.dev/reference/site-config
100+
export default defineConfig(
101+
withSidebar(
102+
withI18n(vitePressConfig, vitePressI18nConfig),
103+
vitePressSidebarConfigs
104+
)
105+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
layout: home
3+
title: About Tessera
34

45
hero:
56
name: "About Tessera"

docs/en/about/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: About
3+
---
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Getting Started
3+
order: 0
4+
---
5+
6+
# Getting Started

docs/en/components/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: Components
3+
---
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
title: Getting Started
3+
order: 1
4+
---
5+
16
# Getting Started
27

38
This section guides you through creating a basic `tessera` application.

docs/en/guide/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: Guide
3+
---
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
title: What is Tessera?
3+
order: 0
4+
---
5+
16
# Tessera UI Framework
27

38
Tessera is a declarative, immediate-mode UI framework for Rust that emphasizes performance, flexibility, and extensibility through a functional approach and a pluggable shader system.
File renamed without changes.

docs/zh/config.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)