Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(theme): support hiding aside component from frontmatter #980

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/config/frontmatter-configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,18 @@ interface Feature {
details: string
}
```

## rightsidebar

- Type: `boolean`

This option only take effect when `layout` is set to `page`.
brc-dd marked this conversation as resolved.
Show resolved Hide resolved

By default, the right aside will be shown, if you want to remove it, configure the option to `false`:

```yaml
---
rightsidebar: false
---
```

9 changes: 6 additions & 3 deletions src/client/theme-default/components/VPDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import VPDocAside from './VPDocAside.vue'
import VPDocFooter from './VPDocFooter.vue'

const route = useRoute()
const { hasSidebar } = useSidebar()
const { hasSidebar, hasRightSidebar } = useSidebar()

const pageName = computed(() =>
route.path.replace(/[./]+/g, '_').replace(/_html$/, '')
Expand All @@ -16,7 +16,7 @@ const pageName = computed(() =>
<template>
<div class="VPDoc" :class="{ 'has-sidebar': hasSidebar }">
<div class="container">
<div class="aside">
<div v-if="hasRightSidebar" class="aside">
<div class="aside-curtain" />
<div class="aside-container">
<div class="aside-content">
Expand All @@ -33,7 +33,7 @@ const pageName = computed(() =>
</div>

<div class="content">
<div class="content-container">
<div class="content-container" :class="{ 'has-right-sidebar': hasRightSidebar }">
<slot name="doc-before" />

<main class="main">
Expand Down Expand Up @@ -170,6 +170,9 @@ const pageName = computed(() =>

.content-container {
margin: 0 auto;
}

.content-container.has-right-sidebar {
max-width: 688px;
}
</style>
8 changes: 8 additions & 0 deletions src/client/theme-default/composables/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export function useSidebar() {
)
})

const hasRightSidebar = computed(() => {
if (frontmatter.value.layout !== 'home' && frontmatter.value.rightsidebar === false)
return false

return hasSidebar.value
})

function open() {
isOpen.value = true
}
Expand All @@ -38,6 +45,7 @@ export function useSidebar() {
isOpen,
sidebar,
hasSidebar,
hasRightSidebar,
open,
close,
toggle
Expand Down