Skip to content

Commit 648f766

Browse files
committed
Fix error script path loaded by MixJS
1 parent ef494a8 commit 648f766

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

bin/nodeppt

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ program
4444
.usage('[file_path] [save_path]')
4545
.description('export html file')
4646
.option('-a, --all [false]', 'output all style(include js,css) file', false)
47-
.option('-p, --asset-path','set the relative path of html to assets(in website), ignored when -a is specified')
47+
.option('-p, --asset-path [path]','set the relative path of html to assets(in website), ignored when -a is specified','.')
4848
.action(function (cmd, output, options) {
4949
var filename = '';
5050
var shouldAll = false;
@@ -53,6 +53,7 @@ program
5353
options = output;
5454
output = undefined;
5555
}
56+
5657
if (typeof cmd === 'string') {
5758
filename = cmd;
5859
shouldAll = options.all;

lib/generate.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ module.exports = function (filepath, outputDir, isAll, rDir) {
3030
console.log('生成结束!'.bold.green + require('path').relative('b:/', outputDir).yellow);
3131
};
3232

33-
function parser(content, template) {
33+
function parser(content,config) {
3434
try {
35-
var html = md_parser(content, null, null, null, {
36-
generate: true
37-
});
35+
var html = md_parser(content, null, null, null, $.mix({
36+
generate: true,
37+
},config));
3838
return html;
3939
} catch (e) {
4040
console.log('ERROR: '.bold.red + e.toString());
@@ -60,7 +60,9 @@ function generate(filepath, outputDir, rDir) {
6060
$.copy(filepath, outputDir, function (filename, dir, subdir) {
6161
if (!subdir && /\.(?:md|markdown)$/i.test(filename)) {
6262
var content = $.readFile(path.join(filepath, filename));
63-
var html = parser(content);
63+
var html = parser(content,{
64+
assetPath: rDir
65+
});
6466
if (html) {
6567
var title = html.match(/<title>(.*?)<\/title>/);
6668
if (title && title[1]) {
@@ -102,7 +104,9 @@ function generate(filepath, outputDir, rDir) {
102104
}
103105
filename = path.basename(filepath);
104106
copyLinkToOutput(content, filepath, outputDir, rDir);
105-
var html = parser(content);
107+
var html = parser(content,{
108+
assetPath: rDir
109+
});
106110
if (html) {
107111
html = handlerHTML(html, rDir);
108112
$.writeFile(path.join(outputDir, filename.replace(/\.(?:md|markdown)$/i, '.htm')), html);

template/markdown.ejs

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
<button class="fa fa-bars" id="_btn-bar" data-toggle="fa fa-close"></button>
5252
</div>
5353
<script src="/js/mixjs/lib/mix.0.3.0.min.js"></script>
54+
<script>
55+
var ASSET_RELATIVE_DIR = "<%= hasOwnProperty('assetPath') && assetPath || '' %>";
56+
</script>
5457
<script>
5558
var base = location.protocol + '//' + location.host;
5659
<%if (hasOwnProperty('generate') && generate) { %>
@@ -59,6 +62,9 @@ var path = (location.pathname + '#').split('/').filter(function(v){
5962
});
6063
path.pop();
6164
path = path.join('/');
65+
if (typeof ASSET_RELATIVE_DIR === 'string') {
66+
path = path + '/' + ASSET_RELATIVE_DIR;
67+
}
6268
MixJS.config({
6369
baseURL: [ base, path, 'js'].join('/')+'/'
6470
});

0 commit comments

Comments
 (0)