undocs 0.2.14 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,23 +7,15 @@ const appConfig = useAppConfig()
7
7
 
8
8
  const { metaSymbol } = useShortcuts()
9
9
 
10
- const route = useRoute()
11
-
12
- const navLinks = computed(() => {
13
- // console.log(mapContentNavigation(navigation.value))
14
- // console.log(JSON.parse(JSON.stringify(navigation.value, null, 2)))
15
- return navigation.value
16
- .map((nav) => {
17
- if (!nav.children?.find((c) => c._path === nav._path)) {
18
- return
19
- }
20
- return {
21
- label: toLabel(nav._path.substring(1)),
22
- to: nav._path,
23
- active: route.path.startsWith(nav._path),
24
- }
25
- })
26
- .filter(Boolean)
10
+ const docsNav = useDocsNav()
11
+
12
+ const headerLinks = computed(() => {
13
+ return docsNav.links.map((link) => {
14
+ return {
15
+ ...link,
16
+ children: link.children?.filter((child) => !child.children || child.children.some((c) => c.to === child.to)),
17
+ }
18
+ })
27
19
  })
28
20
  </script>
29
21
 
@@ -36,26 +28,30 @@ const navLinks = computed(() => {
36
28
  {{ appConfig.site.name }}
37
29
  </span>
38
30
  </NuxtLink>
39
- </template>
40
31
 
41
- <template #center>
42
- <UContentSearchButton label="Search..." class="hidden lg:flex" />
32
+ <div class="ml-8 lg:flex hidden">
33
+ <UContentSearchButton label="Search..." />
34
+ </div>
43
35
  </template>
44
36
 
37
+ <!-- <template #center>
38
+ <UContentSearchButton label="Search..." class="lg:flex hidden" />
39
+ </template> -->
40
+
45
41
  <template #right>
46
- <UHeaderLinks :links="navLinks" class="hidden sm:flex mr-4" v-if="navLinks.length > 1" />
42
+ <UHeaderLinks :links="headerLinks" class="hidden md:flex mr-4" v-if="docsNav.links.length > 1" />
47
43
 
48
44
  <UTooltip class="lg:hidden" text="Search" :shortcuts="[metaSymbol, 'K']">
49
45
  <UContentSearchButton :label="null" />
50
46
  </UTooltip>
51
47
 
52
- <!-- <ColorPicker /> -->
48
+ <ColorPicker />
53
49
 
54
- <SocialButtons :socials="['github']" />
50
+ <SocialButtons />
55
51
  </template>
56
52
 
57
53
  <template #panel>
58
- <NavigationTree />
54
+ <UNavigationTree :links="docsNav.links" default-open :multiple="false" />
59
55
  </template>
60
56
  </UHeader>
61
57
  </template>
@@ -16,7 +16,7 @@ import { splitByCase, upperFirst } from 'scule'
16
16
  const props = defineProps({
17
17
  to: {
18
18
  type: String,
19
- required: true,
19
+ required: false,
20
20
  },
21
21
  title: {
22
22
  type: String,
@@ -1,11 +1,14 @@
1
- <script setup lang="ts"></script>
1
+ <script setup lang="ts">
2
+ const docsNav = useDocsNav()
3
+ </script>
2
4
 
3
5
  <template>
4
6
  <UContainer>
5
7
  <UPage>
6
8
  <template #left>
7
- <UAside>
8
- <NavigationTree />
9
+ <UAside :links="docsNav.links">
10
+ <UDivider type="dashed" class="mb-6" v-if="docsNav.activeLinks?.length" />
11
+ <UNavigationTree :links="docsNav.activeLinks" />
9
12
  </UAside>
10
13
  </template>
11
14
  <slot />
@@ -68,9 +68,11 @@ onMounted(() => {
68
68
  <UPageHeader :title="page.title" :description="page.description" :links="page.links" :headline="headline">
69
69
  </UPageHeader>
70
70
 
71
- <div class="float-right mt-4 top-[calc(var(--header-height)_+_0.5rem)] z-10 flex justify-end sticky">
71
+ <div
72
+ v-if="tocLinks.length > 1"
73
+ class="float-right mt-4 top-[calc(var(--header-height)_+_0.5rem)] z-10 flex justify-end sticky"
74
+ >
72
75
  <UDropdown
73
- v-if="tocLinks.length > 2"
74
76
  :items="[[{ label: 'Return to top', click: scrollToTop }], tocLinks]"
75
77
  :popper="{ placement: 'bottom-end' }"
76
78
  :mode="isMobile ? 'click' : 'hover'"
@@ -86,6 +88,8 @@ onMounted(() => {
86
88
  </div>
87
89
 
88
90
  <UPageBody prose>
91
+ <br v-if="tocLinks.length > 1" />
92
+
89
93
  <ContentRenderer v-if="page.body" :value="page" />
90
94
 
91
95
  <div class="space-y-6">
@@ -38,7 +38,7 @@ function nornalizeHeroLinks(links: LandingConfig['heroLinks']) {
38
38
  link = { to: link }
39
39
  }
40
40
  return {
41
- label: toLabel(key),
41
+ label: titleCase(key),
42
42
  order,
43
43
  target: link.to?.startsWith('https') ? '_blank' : undefined,
44
44
  ...link,
@@ -0,0 +1,36 @@
1
+ import type { NavItem } from '@nuxt/content/dist/runtime/types'
2
+
3
+ export function useDocsNav() {
4
+ const navigation = inject<Ref<NavItem[]>>('navigation')
5
+
6
+ const route = useRoute()
7
+
8
+ const isActive = (path: string) => route.path.startsWith(path)
9
+
10
+ const links = computed(() => {
11
+ return mapContentNavigation(navigation.value).map((item) => {
12
+ if (item.children?.length === 1) {
13
+ return {
14
+ ...item,
15
+ ...item.children[0],
16
+ children: undefined,
17
+ active: isActive(item.to as string),
18
+ }
19
+ }
20
+ return {
21
+ ...item,
22
+ label: titleCase(item.to),
23
+ active: isActive(item.to as string),
24
+ }
25
+ })
26
+ })
27
+
28
+ const activeLinks = computed(() => {
29
+ return links.value.find((l) => route.path.startsWith(l.to as string))?.children || []
30
+ })
31
+
32
+ return reactive({
33
+ links,
34
+ activeLinks,
35
+ })
36
+ }
@@ -0,0 +1,9 @@
1
+ import { titleCase as _titleCase } from 'scule'
2
+
3
+ export function titleCase(key: string) {
4
+ let label = _titleCase(key)
5
+ if (label === 'Api') {
6
+ label = 'API'
7
+ }
8
+ return label
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undocs",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "repository": "unjs/undocs",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,22 +0,0 @@
1
- <script setup lang="ts">
2
- import type { NavItem } from '@nuxt/content/dist/runtime/types'
3
-
4
- const navigation = inject<Ref<NavItem[]>>('navigation')
5
-
6
- const navigationLinks = computed(() => {
7
- return mapContentNavigation(navigation.value).map((item) => {
8
- if (item.children?.length === 1) {
9
- return {
10
- ...item,
11
- ...item.children[0],
12
- children: undefined,
13
- }
14
- }
15
- return item
16
- })
17
- })
18
- </script>
19
-
20
- <template>
21
- <UNavigationTree :links="navigationLinks" default-open :multiple="false" />
22
- </template>
@@ -1,9 +0,0 @@
1
- import { trainCase } from 'scule'
2
-
3
- export function toLabel(key: string) {
4
- let label = trainCase(key).replaceAll('-', ' ')
5
- if (label === 'Api') {
6
- label = 'API'
7
- }
8
- return label
9
- }