Skip to content

Commit

Permalink
Fix error script path loaded by MixJS
Browse files Browse the repository at this point in the history
  • Loading branch information
HakurouKen committed Sep 17, 2016
1 parent ef494a8 commit 648f766
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion bin/nodeppt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ program
.usage('[file_path] [save_path]')
.description('export html file')
.option('-a, --all [false]', 'output all style(include js,css) file', false)
.option('-p, --asset-path','set the relative path of html to assets(in website), ignored when -a is specified')
.option('-p, --asset-path [path]','set the relative path of html to assets(in website), ignored when -a is specified','.')
.action(function (cmd, output, options) {
var filename = '';
var shouldAll = false;
Expand All @@ -53,6 +53,7 @@ program
options = output;
output = undefined;
}

if (typeof cmd === 'string') {
filename = cmd;
shouldAll = options.all;
Expand Down
16 changes: 10 additions & 6 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ module.exports = function (filepath, outputDir, isAll, rDir) {
console.log('生成结束!'.bold.green + require('path').relative('b:/', outputDir).yellow);
};

function parser(content, template) {
function parser(content,config) {
try {
var html = md_parser(content, null, null, null, {
generate: true
});
var html = md_parser(content, null, null, null, $.mix({
generate: true,
},config));
return html;
} catch (e) {
console.log('ERROR: '.bold.red + e.toString());
Expand All @@ -60,7 +60,9 @@ function generate(filepath, outputDir, rDir) {
$.copy(filepath, outputDir, function (filename, dir, subdir) {
if (!subdir && /\.(?:md|markdown)$/i.test(filename)) {
var content = $.readFile(path.join(filepath, filename));
var html = parser(content);
var html = parser(content,{
assetPath: rDir
});
if (html) {
var title = html.match(/<title>(.*?)<\/title>/);
if (title && title[1]) {
Expand Down Expand Up @@ -102,7 +104,9 @@ function generate(filepath, outputDir, rDir) {
}
filename = path.basename(filepath);
copyLinkToOutput(content, filepath, outputDir, rDir);
var html = parser(content);
var html = parser(content,{
assetPath: rDir
});
if (html) {
html = handlerHTML(html, rDir);
$.writeFile(path.join(outputDir, filename.replace(/\.(?:md|markdown)$/i, '.htm')), html);
Expand Down
6 changes: 6 additions & 0 deletions template/markdown.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<button class="fa fa-bars" id="_btn-bar" data-toggle="fa fa-close"></button>
</div>
<script src="/js/mixjs/lib/mix.0.3.0.min.js"></script>
<script>
var ASSET_RELATIVE_DIR = "<%= hasOwnProperty('assetPath') && assetPath || '' %>";
</script>
<script>
var base = location.protocol + '//' + location.host;
<%if (hasOwnProperty('generate') && generate) { %>
Expand All @@ -59,6 +62,9 @@ var path = (location.pathname + '#').split('/').filter(function(v){
});
path.pop();
path = path.join('/');
if (typeof ASSET_RELATIVE_DIR === 'string') {
path = path + '/' + ASSET_RELATIVE_DIR;
}
MixJS.config({
baseURL: [ base, path, 'js'].join('/')+'/'
});
Expand Down

0 comments on commit 648f766

Please sign in to comment.