forked from docsifyjs/docsify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (45 loc) · 1.47 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { load, camel2kebab, isNil } from './util'
import * as render from './render'
const OPTIONS = {
el: '#app',
repo: '',
maxLevel: 6,
sidebar: '',
sidebarToggle: false,
loadSidebar: null,
loadNavbar: null
}
const script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop()
// load configuration for script attribute
if (script) {
for (const prop in OPTIONS) {
const val = script.getAttribute('data-' + camel2kebab(prop))
OPTIONS[prop] = isNil(val) ? OPTIONS[prop] : (val || true)
}
if (OPTIONS.loadSidebar === true) OPTIONS.loadSidebar = '_sidebar.md'
if (OPTIONS.loadNavbar === true) OPTIONS.loadNavbar = '_navbar.md'
if (OPTIONS.sidebar) OPTIONS.sidebar = window[OPTIONS.sidebar]
}
const Docsify = function () {
const dom = document.querySelector(OPTIONS.el) || document.body
const replace = dom !== document.body
let loc = document.location.pathname
if (/\/$/.test(loc)) loc += 'README'
// Render app
render.renderApp(dom, replace, OPTIONS)
// Render markdown file
load(`${loc}.md`)
.then(content => render.renderArticle(content, OPTIONS),
_ => render.renderArticle(null, OPTIONS))
// Render sidebar
if (OPTIONS.loadSidebar) {
load(OPTIONS.loadSidebar)
.then(content => render.renderSidebar(content, OPTIONS))
}
// Render navbar
if (OPTIONS.loadNavbar) {
load(OPTIONS.loadNavbar)
.then(content => render.renderNavbar(content, OPTIONS))
}
}
export default Docsify()