Skip to content

Commit 6b30eb6

Browse files
committed
feat(src): dynamic title and fix sidebar style
1 parent 0ff36c2 commit 6b30eb6

File tree

6 files changed

+25
-3
lines changed

6 files changed

+25
-3
lines changed

src/event.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export function scrollActiveSidebar () {
1919

2020
for (let i = 0, len = lis.length; i < len; i += 1) {
2121
const li = lis[i]
22-
let href = li.querySelector('a').getAttribute('href')
22+
const a = li.querySelector('a')
23+
if (!a) continue
24+
let href = a.getAttribute('href')
2325

2426
if (href !== '/') {
2527
const match = href.match('#([^#]+)$')

src/plugins/ga.js

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function collect () {
2525
}
2626

2727
const install = function () {
28+
if (install.installed) return
29+
install.installed = true
30+
2831
if (!window.Docsify || !window.Docsify.installed) {
2932
console.error('[Docsify] Please load docsify.js first.')
3033
return

src/plugins/search.js

+3
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ const searchPlugin = function () {
321321
}
322322

323323
const install = function () {
324+
if (install.installed) return
325+
install.installed = true
326+
324327
if (!window.Docsify || !window.Docsify.installed) {
325328
console.error('[Docsify] Please load docsify.js first.')
326329
return

src/render.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { genTree, getRoute, isMobile, slugify, merge, emojify } from './util'
88
let markdown = marked
99
let toc = []
1010
const CACHE = {}
11+
const originTitle = document.title
1112

1213
const renderTo = function (dom, content) {
1314
dom = typeof dom === 'object' ? dom : document.querySelector(dom)
@@ -163,15 +164,21 @@ export function renderSidebar (content) {
163164
}
164165

165166
renderTo('.sidebar-nav', html)
167+
168+
if (toc[0] && toc[0].level === 1) {
169+
document.title = `${toc[0].title}${originTitle ? ' - ' + originTitle : ''}`
170+
}
171+
166172
const target = event.activeLink('.sidebar-nav', true)
167173
if (target) renderSubSidebar(target)
168-
toc = []
169174

175+
toc = []
170176
event.scrollActiveSidebar()
171177
}
172178

173179
export function renderSubSidebar (target) {
174180
if (!$docsify.subMaxLevel) return
181+
toc[0] && toc[0].level === 1 && toc.shift()
175182
target.parentNode.innerHTML += tpl.tree(genTree(toc, $docsify.subMaxLevel), '<ul>')
176183
}
177184

src/themes/basic/_layout.css

+5
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ main {
223223
padding: 0;
224224
}
225225

226+
li>p {
227+
font-weight: 700;
228+
margin: 0;
229+
}
230+
226231
ul, ul li {
227232
list-style: none;
228233
}

src/themes/vue.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ body {
1818
background-color: $color-bg;
1919

2020
li {
21-
margin: 6px 15px;
21+
margin: 6px 0 6px 15px;
2222
}
2323

2424
ul li a {
@@ -28,6 +28,7 @@ body {
2828
white-space: nowrap;
2929
text-decoration: none;
3030
font-size: 14px;
31+
font-weight: normal;
3132

3233
&:hover {
3334
text-decoration: underline;
@@ -41,6 +42,7 @@ body {
4142
ul li.active>a {
4243
color: var(--theme-color, $color-primary);
4344
font-weight: 600;
45+
border-right: 2px solid;
4446
}
4547
}
4648

0 commit comments

Comments
 (0)