Skip to main content

yggdrasil/components/
nav.rs

1//! 前台导航项配置
2//!
3//! 根据当前路由生成前台 Header 所需的导航项列表。
4
5use crate::components::header::NavItemConfig;
6use crate::router::Route;
7
8/// 生成前台导航项列表,当前访问的路由会被标记为激活。
9///
10/// 参数:
11/// - `route`:当前路由
12///
13/// 返回:包含首页、归档、标签、关于的导航配置数组。
14/// 搜索以图标形式置于 Header 右侧(主题切换左边),不在此文本导航中。
15pub fn use_nav_items(route: Route) -> Vec<NavItemConfig> {
16    vec![
17        NavItemConfig {
18            route: Route::Home {},
19            label: "首页",
20            is_active: matches!(route, Route::Home {}),
21        },
22        NavItemConfig {
23            route: Route::Archives {},
24            label: "归档",
25            is_active: matches!(route, Route::Archives {}),
26        },
27        NavItemConfig {
28            route: Route::Tags {},
29            label: "标签",
30            is_active: matches!(route, Route::Tags {}) || matches!(route, Route::TagDetail { .. }),
31        },
32        NavItemConfig {
33            route: Route::Friends {},
34            label: "友链",
35            is_active: matches!(route, Route::Friends {}),
36        },
37        NavItemConfig {
38            route: Route::About {},
39            label: "关于",
40            is_active: matches!(route, Route::About {}),
41        },
42    ]
43}