Showing
5 changed files
with
14 additions
and
6 deletions
| ... | @@ -54,7 +54,8 @@ function MdAction (alias_name, md_path) { | ... | @@ -54,7 +54,8 @@ function MdAction (alias_name, md_path) { |
| 54 | return next(); | 54 | return next(); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | - let html = viewer.render(urls[1], query.t); | 57 | + let resource_base = req.original_uri.base || ''; |
| 58 | + let html = viewer.render(urls[1], query.t, resource_base); | ||
| 58 | res.send(html) | 59 | res.send(html) |
| 59 | 60 | ||
| 60 | }); | 61 | }); | ... | ... |
| ... | @@ -29,9 +29,11 @@ class ViewMarkdown { | ... | @@ -29,9 +29,11 @@ class ViewMarkdown { |
| 29 | * 渲染文件 | 29 | * 渲染文件 |
| 30 | * @param filename 文件名,绝对路径 | 30 | * @param filename 文件名,绝对路径 |
| 31 | * @param theme 主题 | 31 | * @param theme 主题 |
| 32 | + * @param resource_base 资源根路径 | ||
| 32 | * @return {string} | 33 | * @return {string} |
| 33 | */ | 34 | */ |
| 34 | - render (filename, theme) { | 35 | + render (filename, theme, resource_base) { |
| 36 | + resource_base = resource_base || ''; | ||
| 35 | const options = this.options; | 37 | const options = this.options; |
| 36 | //默认md | 38 | //默认md |
| 37 | if (!filename || filename.match(/.+\/$/)) { | 39 | if (!filename || filename.match(/.+\/$/)) { |
| ... | @@ -56,7 +58,8 @@ class ViewMarkdown { | ... | @@ -56,7 +58,8 @@ class ViewMarkdown { |
| 56 | let html = ejs.render(template, { | 58 | let html = ejs.render(template, { |
| 57 | tittle, | 59 | tittle, |
| 58 | theme, | 60 | theme, |
| 59 | - content | 61 | + content, |
| 62 | + resource_base | ||
| 60 | }, { | 63 | }, { |
| 61 | root: process.cwd() | 64 | root: process.cwd() |
| 62 | }); | 65 | }); | ... | ... |
| ... | @@ -25,6 +25,7 @@ | ... | @@ -25,6 +25,7 @@ |
| 25 | "github-markdown-css": "^2.10.0", | 25 | "github-markdown-css": "^2.10.0", |
| 26 | "juice": "^4.2.2", | 26 | "juice": "^4.2.2", |
| 27 | "kml-customize": "git+ssh://git@gitlab.kmlab.com/comm/customize.git#1.0.0", | 27 | "kml-customize": "git+ssh://git@gitlab.kmlab.com/comm/customize.git#1.0.0", |
| 28 | + "kml-original-url-mw": "git+ssh://git@gitlab.kmlab.com/comm/original-url-mw.git#1.0.0", | ||
| 28 | "markdown-it": "^8.4.0", | 29 | "markdown-it": "^8.4.0", |
| 29 | "markdown-it-github-toc": "^3.2.4" | 30 | "markdown-it-github-toc": "^3.2.4" |
| 30 | }, | 31 | }, | ... | ... |
| 1 | const express = require('express'); | 1 | const express = require('express'); |
| 2 | const app = express(); | 2 | const app = express(); |
| 3 | - | 3 | +const original_url_mw = require('kml-original-url-mw'); |
| 4 | const config = require('./init/config'); | 4 | const config = require('./init/config'); |
| 5 | 5 | ||
| 6 | +// 解析原始请求url | ||
| 7 | +app.use(original_url_mw()); | ||
| 8 | + | ||
| 6 | //markdown主题 | 9 | //markdown主题 |
| 7 | app.use(express.static(__dirname + '/themes')); | 10 | app.use(express.static(__dirname + '/themes')); |
| 8 | 11 | ... | ... |
| ... | @@ -6,8 +6,8 @@ | ... | @@ -6,8 +6,8 @@ |
| 6 | <%= tittle %> | 6 | <%= tittle %> |
| 7 | </title> | 7 | </title> |
| 8 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | 8 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 9 | - <link rel="stylesheet" href="/markdown.css"> | 9 | + <link rel="stylesheet" href="<%= resource_base + '/markdown.css'%>"> |
| 10 | - <link rel="stylesheet" href="<%= '/' + theme + '/' + theme + '.css' %>"> | 10 | + <link rel="stylesheet" href="<%= resource_base + '/' + theme + '/' + theme + '.css' %>"> |
| 11 | </head> | 11 | </head> |
| 12 | <body> | 12 | <body> |
| 13 | <div class='markdown <%= theme %>'> | 13 | <div class='markdown <%= theme %>'> | ... | ... |
-
Please register or login to post a comment