Skip to content

Commit

Permalink
feat(src): dynamic title and fix sidebar style
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Feb 11, 2017
1 parent 0ff36c2 commit 6b30eb6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export function scrollActiveSidebar () {

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

if (href !== '/') {
const match = href.match('#([^#]+)$')
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/ga.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function collect () {
}

const install = function () {
if (install.installed) return
install.installed = true

if (!window.Docsify || !window.Docsify.installed) {
console.error('[Docsify] Please load docsify.js first.')
return
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ const searchPlugin = function () {
}

const install = function () {
if (install.installed) return
install.installed = true

if (!window.Docsify || !window.Docsify.installed) {
console.error('[Docsify] Please load docsify.js first.')
return
Expand Down
9 changes: 8 additions & 1 deletion src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { genTree, getRoute, isMobile, slugify, merge, emojify } from './util'
let markdown = marked
let toc = []
const CACHE = {}
const originTitle = document.title

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

renderTo('.sidebar-nav', html)

if (toc[0] && toc[0].level === 1) {
document.title = `${toc[0].title}${originTitle ? ' - ' + originTitle : ''}`
}

const target = event.activeLink('.sidebar-nav', true)
if (target) renderSubSidebar(target)
toc = []

toc = []
event.scrollActiveSidebar()
}

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

Expand Down
5 changes: 5 additions & 0 deletions src/themes/basic/_layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ main {
padding: 0;
}

li>p {
font-weight: 700;
margin: 0;
}

ul, ul li {
list-style: none;
}
Expand Down
4 changes: 3 additions & 1 deletion src/themes/vue.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ body {
background-color: $color-bg;

li {
margin: 6px 15px;
margin: 6px 0 6px 15px;
}

ul li a {
Expand All @@ -28,6 +28,7 @@ body {
white-space: nowrap;
text-decoration: none;
font-size: 14px;
font-weight: normal;

&:hover {
text-decoration: underline;
Expand All @@ -41,6 +42,7 @@ body {
ul li.active>a {
color: var(--theme-color, $color-primary);
font-weight: 600;
border-right: 2px solid;
}
}

Expand Down

0 comments on commit 6b30eb6

Please sign in to comment.