往期文章
目录
将素材目录下的index.html页面,拆分成三个文件,分别是:index.css,index.js,index.html
并且将拆分出的三个文件存放到clock目录中。
-
- body {
-
- background-image: linear-gradient(to bottom right, rgb(157, 30, 18), rgb(242, 197, 1));
- background-attachment: fixed;
- }
-
- .container {
- width: 50%;
- height: 50vh;
- background-color: rgb(255, 255, 255);
- opacity: 0.2;
- position: relative;
- margin: 0 auto;
- top: 25vh;
- }
-
- .container div {
- line-height: 150px;
- text-align: center;
- font-size: 50px;
- width: 50%;
- height: 150px;
- display: inline-block;
- position: absolute;
- inset: 0;
- margin: auto;
- }
-
-
- <body>
-
- body>
- <div class="container">
- <div>
- <span>
- 11:11:00
- span>
- <h2>indexh2>
- div>
- div>
-
- <script>
-
- script>


生成了一个css文件

- function resolveJS(jsStr) {
- //正则匹配js
- const r1 = rescript.exec(jsStr);
- //替换掉非必要标签
- const newJs = r1[0].replace('', '');
- //将提取内容写入到clock目录中一个index.js中
- fs.writeFile(path.join(__dirname, '/clock/index.js'), newJs, function (err) {
- if (err) {
- return console.log('导入js样式失败' + err);
- } else {
- console.log('写入样式成功');
- }
- })
-
- }
- function resolveHtml(htmlStr) {
- const newHtml = htmlStr.replace(restyle, '')
- .replace(rescript, '')
- fs.writeFile(path.join(__dirname, '/clock/index.html'), newHtml, function (err) {
- if (err) {
- console.log('导入html文件失败' + err);
- } else {
- console.log('导入成功');
- }
- })
- }

