Showing
3 changed files
with
24 additions
and
3 deletions
init/config.js
0 → 100644
| 1 | +/** | ||
| 2 | + * config | ||
| 3 | + * Created by lintry on 2018/1/9. | ||
| 4 | + */ | ||
| 5 | + | ||
| 6 | +const customize = require('kml-customize'); | ||
| 7 | + | ||
| 8 | +const configure = customize({ | ||
| 9 | + "md": { | ||
| 10 | + "base_path": "md", | ||
| 11 | + "default_md": "readme.md", | ||
| 12 | + "theme": "metro-lake" | ||
| 13 | + } | ||
| 14 | +}); | ||
| 15 | + | ||
| 16 | +//绑定到全局变量 | ||
| 17 | +global.config = global.config = configure; | ||
| 18 | +module.exports = configure; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | "dependencies": { | 16 | "dependencies": { |
| 17 | "express": "^4.16.2", | 17 | "express": "^4.16.2", |
| 18 | "github-markdown-css": "^2.10.0", | 18 | "github-markdown-css": "^2.10.0", |
| 19 | + "kml-customize": "git+ssh://git@gitlab.kmlab.com/comm/customize.git#1.0.0", | ||
| 19 | "markdown-it": "^8.4.0" | 20 | "markdown-it": "^8.4.0" |
| 20 | } | 21 | } |
| 21 | } | 22 | } | ... | ... |
| 1 | const express = require('express'); | 1 | const express = require('express'); |
| 2 | const app = express(); | 2 | const app = express(); |
| 3 | 3 | ||
| 4 | +const config = require('./init/config').md; | ||
| 5 | + | ||
| 4 | const mdview = new (require('./lib/mdview')), | 6 | const mdview = new (require('./lib/mdview')), |
| 5 | path = require('path'); | 7 | path = require('path'); |
| 6 | 8 | ||
| 7 | -const MARKDOWN_FILE_BASE = path.resolve(process.cwd(), 'md'); | 9 | +const MARKDOWN_FILE_BASE = path.resolve(process.cwd(), config.base_path); |
| 8 | 10 | ||
| 9 | app.use(express.static(__dirname + '/themes')); | 11 | app.use(express.static(__dirname + '/themes')); |
| 10 | app.use(express.static(MARKDOWN_FILE_BASE)); | 12 | app.use(express.static(MARKDOWN_FILE_BASE)); |
| ... | @@ -12,7 +14,7 @@ app.use(express.static(MARKDOWN_FILE_BASE)); | ... | @@ -12,7 +14,7 @@ app.use(express.static(MARKDOWN_FILE_BASE)); |
| 12 | function sendTemplate (filename, theme) { | 14 | function sendTemplate (filename, theme) { |
| 13 | //默认md | 15 | //默认md |
| 14 | if (!filename || filename.match(/.+\/$/)) { | 16 | if (!filename || filename.match(/.+\/$/)) { |
| 15 | - filename = (filename || '') + 'readme.md' | 17 | + filename = (filename || '') + config.default_md |
| 16 | } | 18 | } |
| 17 | let file = path.resolve(MARKDOWN_FILE_BASE, filename); | 19 | let file = path.resolve(MARKDOWN_FILE_BASE, filename); |
| 18 | if (!path.parse(file).ext) { | 20 | if (!path.parse(file).ext) { |
| ... | @@ -20,7 +22,7 @@ function sendTemplate (filename, theme) { | ... | @@ -20,7 +22,7 @@ function sendTemplate (filename, theme) { |
| 20 | file += '.md' | 22 | file += '.md' |
| 21 | } | 23 | } |
| 22 | let result = mdview.renderFile(file); | 24 | let result = mdview.renderFile(file); |
| 23 | - theme = theme || 'metro-lake'; | 25 | + theme = theme || config.theme; |
| 24 | return ` | 26 | return ` |
| 25 | <!DOCTYPE html> | 27 | <!DOCTYPE html> |
| 26 | <html> | 28 | <html> | ... | ... |
-
Please register or login to post a comment