-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add array sidebar support (#35)
- Loading branch information
Showing
5 changed files
with
132 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,61 @@ | ||
<template> | ||
<div class="sidebar"> | ||
<ul> | ||
<SideBarItem v-for="item of items" :item="item"></SideBarItem> | ||
</ul> | ||
</div> | ||
<ul class="sidebar"> | ||
<SideBarItem v-for="item of items" :item="item" /> | ||
</ul> | ||
</template> | ||
|
||
<script src="./SideBar"></script> | ||
|
||
<style> | ||
.sidebar ul { | ||
.sidebar, | ||
.sidebar-items { | ||
list-style-type: none; | ||
line-height: 2; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
.sidebar a { | ||
display: inline-block; | ||
color: var(--text-color); | ||
padding-left: 1.5rem; | ||
.sidebar-items .sidebar-items { | ||
padding-left: 1rem; | ||
} | ||
.sidebar a:hover { | ||
color: var(--accent-color); | ||
.sidebar-items .sidebar-items .sidebar-link { | ||
border-left: 0; | ||
} | ||
.sidebar a.active { | ||
color: var(--accent-color); | ||
.sidebar-items .sidebar-items .sidebar-link.active { | ||
font-weight: 500; | ||
} | ||
.sidebar > ul > li > a.active { | ||
padding-left: 1.25rem; | ||
border-left: .25rem solid var(--accent-color); | ||
.sidebar-items .sidebar-link { | ||
padding: .35rem 1rem .35rem 2rem; | ||
line-height: 1.4; | ||
font-size: 0.9em; | ||
font-weight: 400; | ||
} | ||
.sidebar ul ul { | ||
font-size: 0.9em; | ||
padding-left: 1rem; | ||
.sidebar-link { | ||
display: block; | ||
margin: 0; | ||
border-left: .25rem solid transparent; | ||
padding: .35rem 1.5rem .35rem 1.25rem; | ||
line-height: 1.7; | ||
font-size: 1em; | ||
font-weight: 600; | ||
color: var(--text-color); | ||
} | ||
a.sidebar-link { | ||
transition: color .15s ease; | ||
} | ||
a.sidebar-link:hover { | ||
color: var(--accent-color); | ||
} | ||
a.sidebar-link.active { | ||
border-left-color: var(--accent-color); | ||
font-weight: 600; | ||
color: var(--accent-color); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
import { useSiteData } from 'vitepress' | ||
import { useSiteData, Route } from 'vitepress' | ||
|
||
export const hashRE = /#.*$/ | ||
export const extRE = /\.(md|html)$/ | ||
|
||
export function withBase(path: string) { | ||
return (useSiteData().value.base + path).replace(/\/+/g, '/') | ||
} | ||
|
||
export function isActive(route: Route, path?: string): boolean { | ||
if (path === undefined) { | ||
return false | ||
} | ||
|
||
const routePath = normalize(route.path) | ||
const pagePath = normalize(path) | ||
|
||
return routePath === pagePath | ||
} | ||
|
||
export function normalize(path: string): string { | ||
return decodeURI(path).replace(hashRE, '').replace(extRE, '') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters