forked from Csomnia/quick-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
60 lines (55 loc) · 1.76 KB
/
config.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
55
56
57
58
59
60
var Config = {
docRoot: 'pages/',
homepage: 'docs/index.md',
notFoundText: '',
defaultTitle: 'quick-markdown',
notFoundPage: '',
theme: 'default',
showFooterText: true,
footerText: '',
rootPath: '/quick-markdown/'
}
if (typeof module === 'object') {
module.exports = Config
} else if (window && document) {
const themeInfo =
window.location.search
.slice(1).split('&')
.slice(1).map(e => e.split('='))
.filter(e => e[0] === 'theme')[0]
const themeName = themeInfo && themeInfo[1]
const themeRootPath = Config.rootPath +
(
(themeName && 'themes/' + themeName)
|| (Config.theme && 'themes/' + Config.theme)
)
loadCSS(themeRootPath + '/index.css')
fetch(themeRootPath + '/header.html')
.then(res => res.text())
.then(data =>
document.getElementById('header').innerHTML = data
)
const $footerText = document.getElementById('footer-text')
const $customedFooterText = document.getElementById('customed-footer-text')
if ($footerText && $customedFooterText) {
if (Config.showFooterText) {
$customedFooterText.innerHTML = Config.footerText
} else {
$footerText.style.display = 'none'
}
}
function loadCSS (url) {
if (!url) {
document.getElementsByTagName('html')[0].style.display = 'block'
return
}
const head = document.getElementsByTagName('head')[0]
const link = document.createElement('link')
link.type = 'text/css'
link.rel = 'stylesheet'
link.href = url
head.appendChild(link)
document.getElementsByTagName('html')[0].style.display = 'block'
return link
}
}