Skip to content

Commit 35d3bd1

Browse files
authored
customize sidebar and navbar via markdown file, #6 (#8)
* Refactor: use iife * Feat: customize sidebar and navbar via markdown file, #6 * Add changelog
1 parent e09b6f2 commit 35d3bd1

16 files changed

+608
-316
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
## 0.5.0
2+
### Features
3+
- Custom sidebars and navbars by markdown file
4+
15
## 0.4.2
2-
## Bug fixes
6+
### Bug fixes
37
- Correct catch ajax error
48

59
## 0.4.1
6-
## Bug fixes
10+
### Bug fixes
711
- catch ajax error
812

913
## 0.4.0

build/build.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ var build = function (opts) {
1515

1616
console.log(dest)
1717
bundle.write({
18-
format: 'umd',
18+
format: 'iife',
1919
moduleName: opts.moduleName || 'Docsify',
2020
dest: dest
2121
})
2222
})
23+
.catch(function (err) {
24+
console.error(err)
25+
})
2326
}
2427

2528
build({

docs/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,60 @@ Custom sidebar. if it'set, the TOC will be disabeld. Bind global variables on th
144144
<script src="/lib/docsify.js" data-sidebar="sidebar"></script>
145145
```
146146

147+
148+
#### load-sidebar
149+
150+
Load sidebar markdown file. If it is configured, load the current directory `_sidebar.md` by default. If the file isn't exist, sidebar will appear TOC.
151+
152+
```html
153+
<script src="/lib/docsify.js" data-load-sidebar></script>
154+
```
155+
156+
You can specify a file:
157+
158+
```html
159+
<script src="/lib/docsify.js" data-load-sidebar="_sidebar.md"></script>
160+
```
161+
162+
The contents of the file can be:
163+
164+
```markdown
165+
- [Home](/)
166+
- [Installation](/installation)
167+
- Essentials
168+
- [Getting Started](/getting-started)
169+
- [Dynamic Route Matching](/dynamic-matching)
170+
- [Nested Routes](/nested-routes)
171+
- [Programmatic Navigation](/navigation)
172+
- [Named Routes](/named-routes)
173+
- [Named Views](/named-views)
174+
- [Redirect and Alias](/redirect-and-alias)
175+
- [HTML5 History Mode](/history-mode)
176+
```
177+
178+
#### load-navbar
179+
180+
Load navbar markdown file. If it is configured, load the current directory `_navbar.md` by default.
181+
182+
```html
183+
<script src="/lib/docsify.js" data-load-navbar></script>
184+
```
185+
186+
You can specify a file:
187+
188+
```html
189+
<script src="/lib/docsify.js" data-load-navbar="_navbar.md"></script>
190+
```
191+
192+
The contents of the file can be:
193+
194+
```markdown
195+
- [en](/)
196+
- [chinese](/zh-cn)
197+
```
198+
199+
## FAQ
200+
201+
### Why use `404.html` instead of `index.html`
202+
203+
[issues/7](https://github.com/QingWei-Li/docsify/issues/7)

docs/zh-cn.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,63 @@ docsify serve docs
142142
<script src="/lib/docsify.js" data-sidebar="sidebar"></script>
143143
```
144144

145+
#### load-sidebar
146+
147+
读取侧边栏配置文件,如果配置,默认加载当前目录下的 `_sidebar.md`。如果文件不存在,会显示 TOC 作为侧边栏内容。如果你有二级目录,也应该放置一份配置文件。
148+
149+
```html
150+
<script src="/lib/docsify.js" data-load-sidebar></script>
151+
```
152+
153+
你可以指定侧边栏文件名
154+
155+
```html
156+
<script src="/lib/docsify.js" data-load-sidebar="_sidebar.md"></script>
157+
```
158+
159+
`_sidebar.md` 的内容可以是这样的
160+
161+
```markdown
162+
- [Home](/)
163+
- [Installation](/installation)
164+
- Essentials
165+
- [Getting Started](/getting-started)
166+
- [Dynamic Route Matching](/dynamic-matching)
167+
- [Nested Routes](/nested-routes)
168+
- [Programmatic Navigation](/navigation)
169+
- [Named Routes](/named-routes)
170+
- [Named Views](/named-views)
171+
- [Redirect and Alias](/redirect-and-alias)
172+
- [HTML5 History Mode](/history-mode)
173+
```
174+
175+
#### load-navbar
176+
177+
读取导航配置文件,如果配置,默认加载当前目录下的 `_navbar.md`。如果文件不存在,会显示 html 里定义的导航栏。
178+
179+
```html
180+
<script src="/lib/docsify.js" data-load-navbar></script>
181+
```
182+
183+
你可以指定导航栏文件名
184+
185+
```html
186+
<script src="/lib/docsify.js" data-load-navbar="_navbar.md"></script>
187+
```
188+
189+
`_navbar.md` 的内容可以是这样
190+
191+
```markdown
192+
- [en](/)
193+
- [中文](/zh-cn)
194+
```
195+
196+
## FAQ
197+
198+
### 为什么是 `404.html` 而不用 `index.html`
199+
200+
docsify 想要实现的是用最简单的方式 **动态渲染内容**
201+
202+
例如我有两个文档分别为 `README.md``guide.md`,如果我用 `index.html` 作为文件名,`README.md` 可以被正确的渲染因为我们已经规定它为首页文件,但是如果我们访问 `my-domain.com/guide` 想要得到的结果是 `guide.md` 的内容,它将无法工作,因为目录下并不存在一个 `guide.html` 的文件。
203+
204+
但是 GitHub Pages 服务器找不到资源, 就会回退并渲染 `404.html` 文件。😄

0 commit comments

Comments
 (0)