Skip to content

Commit 261e5f8

Browse files
committed
feat: add and chang nav config
1 parent 0d6ce7e commit 261e5f8

File tree

12 files changed

+199
-161
lines changed

12 files changed

+199
-161
lines changed

docs/pages/reference/theme-config/nav.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ categories:
55
- themeConfig
66
end: true
77
---
8+
9+
默认情况下,nav 显示 `siteConfig.title` 作为站点的标题。如果想更改导航栏上显示的内容,可以在 themeConfig.navTitle 选项中定义自定义文本。

docs/valaxy.config.ts

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,79 +9,84 @@ export default defineConfig<ThemeConfig>({
99
devtools: true,
1010

1111
themeConfig: {
12-
header: {
13-
favicon: false,
1412

15-
title: pkg.name,
13+
logo: false,
14+
navTitle: pkg.name,
1615

17-
nav: [
18-
{
19-
text: '主页',
20-
link: '/',
21-
},
22-
{
23-
text: '指南',
24-
link: '/guide',
25-
sidebar: ['getting-started', 'writing'],
26-
subNav: [
27-
{
28-
text: '安装',
29-
link: '/guide/getting-started/installation',
30-
},
31-
{
32-
text: '更新',
33-
link: '/guide/getting-started/update',
34-
},
35-
{
36-
text: '资源处理',
37-
link: '/guide/writing/asset-handling',
38-
},
39-
{
40-
text: 'Frontmatter',
41-
link: '/guide/writing/frontmatter',
42-
},
43-
{
44-
text: '国际化',
45-
link: '/guide/writing/i18n',
46-
},
47-
{
48-
text: 'Markdown',
49-
link: '/guide/writing/markdown',
50-
},
51-
],
52-
},
53-
{
54-
text: '参考',
55-
link: '/reference',
56-
sidebar: ['reference', 'themeConfig'],
57-
subNav: [
58-
{
59-
text: '站点配置',
60-
link: '/reference/site-config',
61-
},
62-
{
63-
text: 'frontmatter 配置',
64-
link: '/reference/frontmatter-config',
65-
},
66-
{
67-
text: '主题配置',
68-
link: '/reference/theme-config',
69-
sidebar: ['themeConfig'],
70-
},
71-
],
72-
},
73-
{
74-
text: pkg.version,
75-
link: 'https://github.com/WRXinYue/valaxy-theme-oceanus/releases',
76-
},
77-
{
78-
text: '关于',
79-
link: '/about',
80-
},
81-
],
16+
nav: [
17+
{
18+
text: '主页',
19+
link: '/',
20+
},
21+
{
22+
text: '指南',
23+
link: '/guide',
24+
sidebar: ['getting-started', 'writing'],
25+
subNav: [
26+
{
27+
text: '安装',
28+
link: '/guide/getting-started/installation',
29+
},
30+
{
31+
text: '更新',
32+
link: '/guide/getting-started/update',
33+
},
34+
{
35+
text: '资源处理',
36+
link: '/guide/writing/asset-handling',
37+
},
38+
{
39+
text: 'Frontmatter',
40+
link: '/guide/writing/frontmatter',
41+
},
42+
{
43+
text: '国际化',
44+
link: '/guide/writing/i18n',
45+
},
46+
{
47+
text: 'Markdown',
48+
link: '/guide/writing/markdown',
49+
},
50+
],
51+
},
52+
{
53+
text: '参考',
54+
link: '/reference',
55+
sidebar: ['reference', 'themeConfig'],
56+
subNav: [
57+
{
58+
text: '站点配置',
59+
link: '/reference/site-config',
60+
},
61+
{
62+
text: 'frontmatter 配置',
63+
link: '/reference/frontmatter-config',
64+
},
65+
{
66+
text: '主题配置',
67+
link: '/reference/theme-config',
68+
sidebar: ['themeConfig'],
69+
},
70+
],
71+
},
72+
{
73+
text: pkg.version,
74+
link: 'https://github.com/WRXinYue/valaxy-theme-oceanus/releases',
75+
},
76+
{
77+
text: '关于',
78+
link: '/about',
79+
},
80+
],
8281

83-
github: pkg.repository.url,
84-
},
82+
navTools: [
83+
['togglTheme', 'toggleLocale'],
84+
[{
85+
icon: 'i-ri-github-fill',
86+
link: pkg.repository.url,
87+
}],
88+
['search'],
89+
],
8590

8691
hero: {
8792
title: 'VALAXY THEME OCEANUS',

theme/components/OceanusFooter.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const isThisYear = computed(() => {
1919
<footer class="oceanus-footer">
2020
<div class="oceanus-home-container footer-content">
2121
<div class="footer-columns">
22-
<template v-for="(nav, index) in themeConfig.header.nav">
22+
<template v-for="(nav, index) in themeConfig.nav">
2323
<div v-if="nav.subNav?.length" :key="index" class="footer-column">
2424
<h4 class="footer-nav-title">
2525
{{ nav.text }}

theme/components/OceanusHeader.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { useAppStore, useSiteConfig } from 'valaxy'
3-
import { computed, toValue } from 'vue'
3+
import { computed } from 'vue'
44
import { useRoute } from 'vue-router'
55
import { useMatchingNavItems, useThemeConfig } from '../composables'
66
@@ -13,16 +13,16 @@ const routePath = computed(() => route.path)
1313
1414
const matchingNavItems = useMatchingNavItems(routePath)
1515
16-
const { favicon, nav, title } = toValue(themeConfig).header
16+
const { logo, nav, navTitle } = themeConfig.value
1717
const currentNavItem = computed(() => matchingNavItems.value.firstNavItems)
1818
19-
const navFavicon = computed(() => {
20-
if (typeof favicon === 'boolean')
21-
return favicon === true ? siteConfig.value.favicon : ''
22-
else if (typeof favicon === 'string')
23-
return favicon
24-
else if (typeof favicon === 'object')
25-
return appStore.isDark ? favicon.dark : favicon.light
19+
const navLogo = computed(() => {
20+
if (typeof logo === 'boolean')
21+
return logo === true ? siteConfig.value.favicon : ''
22+
else if (typeof logo === 'string')
23+
return logo
24+
else if (typeof logo === 'object')
25+
return appStore.isDark ? logo.dark : logo.light
2626
2727
console.error('Invalid favicon type, check ThemeConfig.header.favicon config')
2828
return ''
@@ -32,7 +32,7 @@ const navFavicon = computed(() => {
3232
<template>
3333
<!-- <OceanusNavBanner /> -->
3434
<!-- <OceanusNavToolbar /> -->
35-
<OceanusNav :nav="nav" :favicon="navFavicon" :title :class="!currentNavItem?.subNav && 'fixed'" />
35+
<OceanusNav :nav="nav" :favicon="navLogo" :title="navTitle" :class="!currentNavItem?.subNav && 'fixed'" />
3636
<div :style="{ marginTop: currentNavItem?.subNav ? 0 : 'var(--oceanus-nav-height)' }" class="nav-placeholder" />
3737
<OceanusSubNav v-if="currentNavItem?.subNav" :title="currentNavItem?.text" :sub-nav="currentNavItem?.subNav" :class="currentNavItem?.subNav && 'sticky'" />
3838
</template>

theme/components/OceanusNav.vue

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts" setup>
22
import type { NavItem } from '../types'
3-
import { useAppStore } from 'valaxy'
4-
import { ref } from 'vue'
3+
import { useToggle } from '@vueuse/core'
54
import { useThemeConfig } from '../composables'
65
76
defineProps<{
@@ -11,35 +10,19 @@ defineProps<{
1110
}>()
1211
1312
const themeConfig = useThemeConfig()
14-
const appStore = useAppStore()
1513
16-
const isOpen = ref(false)
17-
// const isMobile = useMobile()
18-
19-
function open() {
20-
isOpen.value = true
21-
}
22-
23-
function close() {
24-
isOpen.value = false
25-
}
26-
27-
function toggle() {
28-
isOpen.value ? close() : open()
29-
}
14+
const [isOpen, toggle] = useToggle(false)
3015
</script>
3116

3217
<template>
3318
<nav class="oceanus-nav" w="full" role="navigation" :class="[isOpen && 'screen-open']">
3419
<div class="nav-content" flex="~ items-center">
3520
<div class="oceanus-safe-padding nav-content-header" flex="~ center md:justify-between">
36-
<OceanusNavMenu class="nav-menu left-2 z-50 absolute! md:hidden" h="full" :active="isOpen" @click="toggle" />
21+
<OceanusNavMenu class="nav-menu left-2 z-50 absolute! md:hidden" h="full" :active="isOpen" @click="toggle()" />
3722

38-
<AppLink to="/" :aria-label="title">
39-
<div class="h-30px flex text-center text-xl">
40-
<img v-if="favicon" class="mr-2 object-cover" alt="logo" :src="favicon">
41-
<span class="oceanus-text oceanus-nav-title md:inline">{{ title }}</span>
42-
</div>
23+
<AppLink to="/" :aria-label="title" class="flex text-center">
24+
<img v-if="favicon" class="oceanus-nav-icon mr-2 object-cover text-xl" alt="logo" :src="favicon">
25+
<span class="oceanus-text oceanus-nav-title text-xl md:inline">{{ title }}</span>
4326
</AppLink>
4427

4528
<div class="items-center leading-5 <md:hidden">
@@ -55,30 +38,11 @@ function toggle() {
5538
</template>
5639
</div>
5740

58-
<div flex="~ center" class="<md:hidden">
59-
<div flex="~ center">
60-
<OceanusToggleLocale />
61-
62-
<div class="oceanus-nav-toolbar-text text-icon" flex="~ center">
63-
<button type="button" aria-label="Toggle Dark Mode" @click="appStore.toggleDarkWithTransition">
64-
<div v-if="!appStore.isDark" i-tabler-sun />
65-
<div v-else i-tabler-moon />
66-
</button>
67-
</div>
68-
</div>
69-
70-
<div v-if="themeConfig.header?.github" class="text-b" flex="~ center">
71-
<AppLink class="oceanus-nav-toolbar-text text-icon" :to="themeConfig.header.github">
72-
<div i-ri-github-fill />
73-
</AppLink>
41+
<slot name="toolbar">
42+
<div flex="~ center" class="oceanus-nav-toolbar <md:hidden">
43+
<OceanusNavTools :nav-tools="themeConfig.navTools" />
7444
</div>
75-
76-
<div class="text-b cursor-not-allowed" flex="~ center">
77-
<div class="text-icon">
78-
<div i-tabler-search items-center />
79-
</div>
80-
</div>
81-
</div>
45+
</slot>
8246
</div>
8347

8448
<div class="search-placeholder-container absolute" w="full">
@@ -357,23 +321,4 @@ function toggle() {
357321
}
358322
}
359323
}
360-
361-
.text-icon {
362-
display: flex;
363-
justify-content: center;
364-
align-items: center;
365-
width: 36px;
366-
height: 36px;
367-
color: var(--vp-c-text-2);
368-
transition: color 0.5s;
369-
}
370-
371-
.text-b::before {
372-
margin-right: 8px;
373-
margin-left: 8px;
374-
width: 1px;
375-
height: 24px;
376-
background-color: var(--oceanus-c-divider);
377-
content: '';
378-
}
379324
</style>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script setup lang="ts">
2+
import type { NavTools } from '../types'
3+
4+
defineProps<{
5+
navTools: NavTools
6+
}>()
7+
</script>
8+
9+
<template>
10+
<div v-for="(tools, i) in navTools" :key="i" flex="~ center">
11+
<template v-for="(tool, j) in tools" :key="j">
12+
<OceanusToggleLocale v-if="tool === 'toggleLocale'" />
13+
<OceanusToggleTheme v-if="tool === 'togglTheme'" />
14+
<div v-if="tool === 'search'" class="text-icon cursor-not-allowed">
15+
<!-- TODO: -->
16+
<div i-tabler-search items-center />
17+
</div>
18+
19+
<template v-if="typeof tool === 'object'">
20+
<AppLink class="text-icon oceanus-nav-toolbar-text" :to="tool?.link">
21+
<div :class="tool.icon" />
22+
</AppLink>
23+
</template>
24+
</template>
25+
<div v-if="i !== navTools.length - 1" class="text-icon text-b" />
26+
</div>
27+
</template>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script lang="ts" setup>
2+
import { useAppStore } from 'valaxy'
3+
4+
const appStore = useAppStore()
5+
</script>
6+
7+
<template>
8+
<div class="oceanus-nav-toolbar-text text-icon" flex="~ center">
9+
<button type="button" aria-label="Toggle Dark Mode" @click="appStore.toggleDarkWithTransition">
10+
<div v-if="!appStore.isDark" i-tabler-sun />
11+
<div v-else i-tabler-moon />
12+
</button>
13+
</div>
14+
</template>

theme/composables/nav.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function useSplitPathSegments(path: MaybeRefOrGetter<string>) {
3636
*/
3737
export function useMatchingNavItems(path: MaybeRefOrGetter<string>) {
3838
const themeConfig = useThemeConfig()
39-
const navItems = themeConfig.value.header.nav!
39+
const navItems = themeConfig.value.nav!
4040

4141
return computed(() => {
4242
const matchingNavItems: {

0 commit comments

Comments
 (0)