Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Shenlin
/
markdown-view
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
lintry
2018-01-09 11:32:00 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c7f78971fd8395f9d8d5a2096c4df4fa087daf1a
c7f78971
1 parent
3cd7c44f
添加配置
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
3 deletions
init/config.js
package.json
server.js
init/config.js
0 → 100644
View file @
c7f7897
/**
* config
* Created by lintry on 2018/1/9.
*/
const
customize
=
require
(
'kml-customize'
);
const
configure
=
customize
({
"md"
:
{
"base_path"
:
"md"
,
"default_md"
:
"readme.md"
,
"theme"
:
"metro-lake"
}
});
//绑定到全局变量
global
.
config
=
global
.
config
=
configure
;
module
.
exports
=
configure
;
\ No newline at end of file
package.json
View file @
c7f7897
...
...
@@ -16,6 +16,7 @@
"dependencies"
:
{
"express"
:
"^4.16.2"
,
"github-markdown-css"
:
"^2.10.0"
,
"kml-customize"
:
"git+ssh://git@gitlab.kmlab.com/comm/customize.git#1.0.0"
,
"markdown-it"
:
"^8.4.0"
}
}
...
...
server.js
View file @
c7f7897
const
express
=
require
(
'express'
);
const
app
=
express
();
const
config
=
require
(
'./init/config'
).
md
;
const
mdview
=
new
(
require
(
'./lib/mdview'
)),
path
=
require
(
'path'
);
const
MARKDOWN_FILE_BASE
=
path
.
resolve
(
process
.
cwd
(),
'md'
);
const
MARKDOWN_FILE_BASE
=
path
.
resolve
(
process
.
cwd
(),
config
.
base_path
);
app
.
use
(
express
.
static
(
__dirname
+
'/themes'
));
app
.
use
(
express
.
static
(
MARKDOWN_FILE_BASE
));
...
...
@@ -12,7 +14,7 @@ app.use(express.static(MARKDOWN_FILE_BASE));
function
sendTemplate
(
filename
,
theme
)
{
//默认md
if
(
!
filename
||
filename
.
match
(
/.+
\/
$/
))
{
filename
=
(
filename
||
''
)
+
'readme.md'
filename
=
(
filename
||
''
)
+
config
.
default_md
}
let
file
=
path
.
resolve
(
MARKDOWN_FILE_BASE
,
filename
);
if
(
!
path
.
parse
(
file
).
ext
)
{
...
...
@@ -20,7 +22,7 @@ function sendTemplate (filename, theme) {
file
+=
'.md'
}
let
result
=
mdview
.
renderFile
(
file
);
theme
=
theme
||
'metro-lake'
;
theme
=
theme
||
config
.
theme
;
return
`
<!DOCTYPE html>
<html>
...
...
Please
register
or
login
to post a comment