Skip to content

Commit

Permalink
fix(theme-default): revert to page data header because of vuepress/co…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Jan 18, 2025
1 parent 7c5daab commit 9975ad4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion themes/theme-default/src/client/composables/useHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ export const setupHeaders = (): void => {
provideLocal(headersSymbol, headersRef)

onMounted(() => {
watchImmediate(() => [levels, routePath], updateHeaders)
watchImmediate([levels, routePath], updateHeaders)
})
}
31 changes: 14 additions & 17 deletions themes/theme-default/src/client/composables/useSidebarItems.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { resolveAutoLink } from '@theme/resolveAutoLink'
import { resolvePrefix } from '@theme/resolvePrefix'
import { useHeaders } from '@theme/useHeaders'
import { useThemeLocaleData } from '@theme/useThemeData'
import type { HeaderItem } from '@vuepress/helper/client'
import { isLinkRelative, keys, startsWith } from '@vuepress/helper/client'
import type { ComputedRef, InjectionKey } from 'vue'
import { computed, inject, provide } from 'vue'
import type { PageData } from 'vuepress/client'
import type { PageData, PageHeader } from 'vuepress/client'
import {
usePageData,
usePageFrontmatter,
Expand All @@ -27,30 +25,30 @@ import type { SidebarHeaderItem, SidebarItem } from '../typings.js'
/**
* Util to transform page header to sidebar item
*/
export const resolveSidebarHeaderItem = (
header: HeaderItem,
export const resolveSidebarPageHeader = (
header: PageHeader,
): SidebarHeaderItem => ({
text: header.title,
link: header.link,
// eslint-disable-next-line @typescript-eslint/no-use-before-define
children: resolveSidebarHeaderItems(header.children),
children: resolveSidebarPageHeaders(header.children),
})

export const resolveSidebarHeaderItems = (
headers?: HeaderItem[],
export const resolveSidebarPageHeaders = (
headers?: PageHeader[],
): SidebarHeaderItem[] =>
headers ? headers.map((header) => resolveSidebarHeaderItem(header)) : []
headers ? headers.map((header) => resolveSidebarPageHeader(header)) : []

/**
* Resolve current page and its header to sidebar items if the config is `heading`
*/
export const resolveSidebarHeadingItem = (
page: PageData,
headers: HeaderItem[],
headers: PageHeader[],
): SidebarItem[] => [
{
text: page.title,
children: resolveSidebarHeaderItems(headers),
children: resolveSidebarPageHeaders(headers),
},
]

Expand All @@ -59,7 +57,7 @@ export const resolveSidebarHeadingItem = (
*/
export const resolveArraySidebarItems = (
sidebarConfig: SidebarArrayOptions,
headers: HeaderItem[],
headers: PageHeader[],
path: string,
prefix = '',
): SidebarItem[] => {
Expand Down Expand Up @@ -96,7 +94,7 @@ export const resolveArraySidebarItems = (

return {
...childItem,
children: resolveSidebarHeaderItems(currentHeaders),
children: resolveSidebarPageHeaders(currentHeaders),
}
}

Expand All @@ -112,7 +110,7 @@ export const resolveArraySidebarItems = (
export const resolveMultiSidebarItems = (
sidebarConfig: SidebarObjectOptions,
page: PageData,
headers: HeaderItem[],
headers: PageHeader[],
path: string,
): SidebarItem[] => {
const sidebarRoutes = keys(sidebarConfig).sort((x, y) => y.length - x.length)
Expand Down Expand Up @@ -161,7 +159,7 @@ export const resolveSidebarItems = (
page: PageData,
path: string,
routeLocale: string,
headers: HeaderItem[],
headers: PageHeader[],
): SidebarItem[] => {
// resolve sidebar items according to the config
if (sidebarConfig === false) {
Expand Down Expand Up @@ -194,7 +192,6 @@ export const setupSidebarItems = (): void => {
const page = usePageData()
const route = useRoute()
const routeLocale = useRouteLocale()
const headers = useHeaders()

const sidebarConfig = computed<SidebarOptions | false>(() =>
frontmatter.value.home
Expand All @@ -210,7 +207,7 @@ export const setupSidebarItems = (): void => {
page.value,
route.path,
routeLocale.value,
headers.value,
page.value.headers,
),
)
provide(sidebarItemsSymbol, sidebarItems)
Expand Down
2 changes: 0 additions & 2 deletions themes/theme-default/src/client/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { setupDarkMode } from '@theme/useDarkMode'
import { setupHeaders } from '@theme/useHeaders'
import { useScrollPromise } from '@theme/useScrollPromise'
import { setupSidebarItems } from '@theme/useSidebarItems'
import { hasGlobalComponent } from '@vuepress/helper/client'
Expand All @@ -26,7 +25,6 @@ export default defineClientConfig({

setup() {
setupDarkMode()
setupHeaders()
setupSidebarItems()
},

Expand Down

0 comments on commit 9975ad4

Please sign in to comment.