@@ -66,14 +66,22 @@ CreateDatajs('./.deploy/js/dt.js',function(dt_path,arr){
6666
6767 CreateStyl ( '/template/styl/index.styl' , '/.deploy/css/index.css' )
6868 // 首页生成
69- ReadTmpToHTML ( '/template/index.ejs' , '/.deploy/index.html' ) ;
70- ReadTmpToHTML ( '/template/list.ejs' , '/.deploy/list.html' ) ;
69+ ReadTmpToHTML ( '/template/index.ejs' , '/.deploy/index.html' , null , {
70+ 'p' :'/index.html' ,
71+ 'n' :'首页' ,
72+ 'd' :'最专业的Linux命令大全,内容包含Linux命令手册、详解、学习,值得收藏的Linux命令速查手册。'
73+ } ) ;
74+ ReadTmpToHTML ( '/template/list.ejs' , '/.deploy/list.html' , null , {
75+ p :'/list.html' ,
76+ n :'搜索' ,
77+ d :'最专业的Linux命令大全,内容包含Linux命令手册、详解、学习,值得收藏的Linux命令速查手册。'
78+ } ) ;
7179 // 文章批量生成
7280 arr . forEach ( function ( itm , idx ) {
7381 var ejstpm = path . join ( '/template/' , itm . p ) ;
7482 var md_path = path . join ( '/command' , itm . p ) ;
75- var dep = path . join ( '/.deploy/command ' , itm . p ) ;
76- ReadTmpToHTML ( '/template/details.ejs' , dep + '.html' , md_path + '.md' )
83+ var dep = path . join ( '/.deploy/c ' , itm . p ) ;
84+ ReadTmpToHTML ( '/template/details.ejs' , dep + '.html' , md_path + '.md' , itm )
7785 } ) ;
7886
7987} )
@@ -118,23 +126,29 @@ watch.watchTree(path.join(path.dirname(__dirname),'/'), function (f, curr, prev)
118126 * [ReadTmpToHTML ejs 模板转换成HTML]
119127 * @param {[type] } from_path [模版来源地址]
120128 * @param {[type] } to_path [生成到指定的位置]
121- * @param {[type] } md_path [Markdown的位置]
129+ * @param {[type] } md_path [Markdown的路径] // 给md地址就生产详情页面
130+ * @param {[type] } des_json [页面信息 json 格式]
122131 */
123- function ReadTmpToHTML ( from_path , to_path , md_path ) {
132+ function ReadTmpToHTML ( from_path , to_path , md_path , des_json ) {
124133 var tmp_path = path . join ( path . dirname ( __dirname ) , from_path ) ;
125134 if ( ! exists ( tmp_path ) ) return console . log ( "\n → error: 模板文件 " + tmp_path + " 不存在" )
126135 var tmp_str = fs . readFileSync ( tmp_path ) ;
127136 tmp_str = tmp_str . toString ( ) ;
128137
129- var relative_path = '' ;
138+ var relative_path = '' , current_path = '' ;
130139 if ( md_path ) {
131- relative_path = path . relative ( md_path . toString ( ) , '/' ) ;
132- relative_path = relative_path . replace ( / \. \. $ / , '' ) ;
140+ //CSS/JS 引用相对地址
141+ relative_path = path . relative ( md_path . toString ( ) , '/' ) ;
142+ relative_path = relative_path . replace ( / \. \. $ / , '' ) ;
143+ current_path = md_path . replace ( / \. m d $ / , '.html' ) . replace ( / ^ \/ c o m m a n d \/ / , '/c/' ) ;
133144 }
134145 // 生成 HTML
135146 var html = ejs . render ( tmp_str , {
136147 filename : tmp_path ,
137- relative_path :relative_path
148+ relative_path :relative_path , // 当前文件相对于根目录的相对路径
149+ md_path :md_path ?md_path :'' , // markdown 路径
150+ current_path :current_path , // 当前 html 路径
151+ describe :des_json ?des_json :{ } , // 当前 md 的描述
138152 } ) ;
139153 // 生成到指定目录
140154 var new_to_path = path . join ( path . dirname ( __dirname ) , to_path ) ;
@@ -147,13 +161,10 @@ function ReadTmpToHTML(from_path,to_path,md_path){
147161 if ( err ) return console . log ( error ( ' → ' + md_path + " 转换成HTML失败!" ) ) ;
148162
149163 html = html . replace ( '{{content}}' , md_html ) ;
150- html = html . replace ( '<!--[编辑]-->' , '<a class="edit_btn" href="' + path . join ( 'https://github.com/jaywcjlove/linux-command/edit/master/' , md_path ) + '">编辑</a>' )
151164 fs . writeFileSync ( new_to_path , html ) ;
152165 console . log ( success ( " → " ) + to_path + '' ) ;
153-
154166 } )
155167 } else {
156-
157168 html = html . toString ( ) ;
158169 fs . writeFileSync ( new_to_path , html . replace ( / \n / g, '' ) ) ;
159170 console . log ( success ( " → " ) + to_path + '' ) ;
0 commit comments