Skip to content

Commit aecf176

Browse files
author
zhouhongxuan
committed
feat(build): convert md to html
1 parent 1fb335a commit aecf176

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
package-lock.json
3+
build

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "frontend-tech-list",
3+
"version": "1.0.0",
4+
"description": "学习文章的知识往往是碎片化的。而前端涉及到的面很广,这些知识如果不进行有效梳理,则无法相互串联、形成体系。因此,我结合工作体会将抽象出了一些前端基础能力,并将看过、写过的一些不错的文章进行整理,形成了一份(纯)前端技术清单。",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "node script/md2html.js"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/alienzhou/frontend-tech-list.git"
12+
},
13+
"author": "",
14+
"license": "ISC",
15+
"bugs": {
16+
"url": "https://github.com/alienzhou/frontend-tech-list/issues"
17+
},
18+
"homepage": "https://github.com/alienzhou/frontend-tech-list#readme",
19+
"devDependencies": {
20+
"picnic": "^6.5.0",
21+
"showdown": "^1.9.0"
22+
}
23+
}

script/md2html.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const showdown = require('showdown');
2+
const path = require('path');
3+
const fs = require('fs');
4+
5+
function convertMd2Html() {
6+
const md = fs.readFileSync(path.resolve(__dirname, '../README.md'), 'utf-8');
7+
showdown.setFlavor('github');
8+
const converter = new showdown.Converter();
9+
const mdHtml = converter.makeHtml(md);
10+
const buildDir = path.resolve(__dirname, '../build');
11+
if (!fs.existsSync(buildDir)) {
12+
fs.mkdirSync(buildDir)
13+
}
14+
require.resolve('picnic');
15+
16+
// const style = fs.readFileSync(path.resolve(__dirname, '../script/style.css'), 'utf-8');
17+
const style = fs.readFileSync(require.resolve('picnic'), 'utf-8');
18+
const tpl = fs.readFileSync(path.resolve(__dirname, '../script/tpl.html'), 'utf-8');
19+
20+
html = tpl
21+
.replace(/\{\{style\}\}/, `<style>${style}</style>`)
22+
.replace(/\{\{md\}\}/, mdHtml);
23+
24+
fs.writeFileSync(path.resolve(buildDir, 'index.html'), html, 'utf-8');
25+
console.log('convert md to html success!');
26+
}
27+
28+
module.exports = convertMd2Html;
29+
process.argv[1] === __filename && convertMd2Html();

script/tpl.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
{{style}}
8+
<title>Frontend Tech List: an overall frontend-tech list for developers</title>
9+
</head>
10+
<body>
11+
<main style="margin: 50px auto; max-width: 800px;">
12+
{{md}}
13+
</main>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)