@@ -8,12 +8,14 @@ export default class InstanceDownloader {
88 * @param {Object } code 代码集合
99 * @param {Object } links 外部链接
1010 * @param {Array } prep 预处理
11+ * @param {String } headTags 头部标签
1112 * @param {Boolean } dwPrep 是否下载未编译版本
1213 */
13- constructor ( code , links , prep , dwPrep ) {
14+ constructor ( code , links , prep , headTags , dwPrep ) {
1415 this . code = code
1516 this . links = links
1617 this . prep = prep
18+ this . headTags = headTags
1719 this . dwPrep = dwPrep
1820 }
1921
@@ -26,6 +28,7 @@ export default class InstanceDownloader {
2628 const prep = this . prep
2729 const { cssLinks, JSLinks } = this . links
2830 const dwPrep = this . dwPrep
31+ const headTags = this . headTags
2932 let HTMLCode ,
3033 CSSCode ,
3134 JSCode ,
@@ -49,15 +52,15 @@ export default class InstanceDownloader {
4952 extJS += linkStr
5053 }
5154 if ( type === 'single' ) {
52- this . single ( { HTMLCode, CSSCode, JSCode } , { extCss, extJS } )
55+ this . single ( { HTMLCode, CSSCode, JSCode } , { extCss, extJS } , headTags )
5356 if ( dwPrep ) {
5457 const typeObj = this . judgePrep ( )
5558 typeObj . html && this . download ( HTML , `index.${ typeObj . html } ` )
5659 typeObj . css && this . download ( CSS , `index.${ typeObj . css } ` )
5760 typeObj . js && this . download ( JavaScript , `index.${ typeObj . js } ` )
5861 }
5962 } else if ( type === 'multiple' ) {
60- this . multiple ( { HTMLCode, CSSCode, JSCode } , { extCss, extJS } )
63+ this . multiple ( { HTMLCode, CSSCode, JSCode } , { extCss, extJS } , headTags )
6164 }
6265 }
6366
@@ -66,25 +69,25 @@ export default class InstanceDownloader {
6669 * @param {Object } code 代码集合
6770 * @param {Object } links 外部链接字符串集合
6871 */
69- single ( code , links ) {
72+ single ( code , links , headTags ) {
7073 const { HTMLCode, CSSCode, JSCode } = code
7174 const { extCss = '' , extJS = '' } = links
7275 const htmlCode = `<!DOCTYPE html>
7376 <html lang="en">
7477 <head>
7578 <meta charset="UTF-8">
7679 <meta name="viewport" content="width=device-width, initial-scale=1">
80+ ${ headTags }
7781 ${ extCss }
7882 ${ extJS }
7983 <title></title>
8084 <style>
8185 ${ CSSCode }
8286 </style>
87+ </head>
8388 <body>
8489 ${ HTMLCode }
85- <script>
86- ${ JSCode }
87- </script>
90+ <script>${ JSCode } </script>
8891 </body>
8992 </html>
9093 `
@@ -96,23 +99,25 @@ export default class InstanceDownloader {
9699 * @param {Object } code 代码集合
97100 * @param {Object } links 外部链接字符串集合
98101 */
99- multiple ( code , links ) {
102+ multiple ( code , links , headTags ) {
100103 const { HTML , CSS , JavaScript } = this . code
101104 const { HTMLCode, CSSCode, JSCode } = code
102105 const { extCss, extJS } = links
103106 const zip = new JSZip ( )
104107 const zipFolder = zip . folder ( 'code' )
105108 const htmlCode = `
106109 <!DOCTYPE html>
107- <html lang="en">
110+ <html lang="en">
108111 <head>
109112 <meta charset="UTF-8">
110113 <meta name="viewport" content="width=device-width, initial-scale=1">
114+ ${ headTags }
111115 ${ extCss }
112116 ${ extJS }
113117 <link rel="stylesheet" href="./index.css">
114118 <script src="./index.js"><\/script>
115119 <title></title>
120+ </head>
116121 <body>
117122 ${ HTMLCode }
118123 </body>
0 commit comments