vuepress.vuejs.org/zh/javascript
話很少說先貼一張圖👀前端
# 將 VuePress 做爲一個本地依賴安裝
yarn add -D vuepress # 或者:npm install -D vuepress
# 新建一個 docs 文件夾
mkdir docs
# 新建一個 markdown 文件
echo '# Hello VuePress!' > docs/README.md
# 開始寫做
npx vuepress dev docs
複製代碼
{
"scripts": {
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs"
}
}
複製代碼
.
├─ docs
│ ├─ README.md
│ └─ .vuepress
| ├─components // 自定義組件
├─override.styl // 覆蓋樣式
│ └─ config.js // 配置文件
└─ package.json
複製代碼
module.exports = {
title: 'Hello VuePress',
description: 'Just playing around'
}
複製代碼
主要是config.js中的配置vue
const path = require('path');
const fs = require('fs');
module.exports = {
title: 'BLOG',
description: 'Curriculum Vitae',
markdown: {
lineNumbers: true
},
themeConfig: {
nav: [
{ text: '首頁', link: '/' },
{ text: '技術', link: '/learning-notes/' },
{ text: '讀書', link: '/reading/' },
{ text: '面試題', link: '/interview/' },
{ text: '關於', link: '/about/' },
{ text: 'github', link: 'https://github.com/zhaotbj' }
],
sidebar: {
'/learning-notes/': [
{
title: "Node.js",
collapsable: true,
children: genSidebarConfig("learning-notes/node", true)
},
{
title: "Vue",
collapsable: true,
children: genSidebarConfig("learning-notes/vue", true)
},
{
title: "React",
collapsable: true,
children: genSidebarConfig("learning-notes/react", true)
},
{
title: "JS",
collapsable: true,
children: genSidebarConfig("learning-notes/js", true)
},
{
title: "微信小程序",
collapsable: true,
children: []
}
],
'/interview/': [
{
title: "Vue面試題",
collapsable: true,
children: genSidebarConfig("interview/vue", true)
},
{
title: "慕課網前端跳槽面試必備技巧",
collapsable: true,
children: genSidebarConfig("interview/muke", true)
},
],
'/reading/': [
{
title: "讀書筆記",
collapsable: true,
children: genSidebarConfig("reading/reading-notes", true)
}
]
}
}
}
function genSidebarConfig(dir, hasSub) {
let p = path.join(__dirname, '../', dir);
let files = fs.readdirSync(p);
let subDir = hasSub ? dir.split('/')[1] : '';
files = files.map(item => {
item = subDir ? subDir + '/' + path.basename(item, '.md') : path.basename(item, '.md');
return item;
});
return files;
}
複製代碼
若是你打算髮布到 https://<USERNAME>.github.io/
java
首先在GitHub創建一個倉庫node
// 生成靜態文件
npm run docs:build
// 進入生成的文件夾
cd docs/.vuepress/dist
git init
git add -A
git commit -m 'deploy'
// 若是發佈到 https://<USERNAME>.github.io
git remote add origin git@github.com:zhaotbj.github.io.git
git push -f git@github.com:zhaotbj/zhaotbj.github.io.git
// or git push -f git@github.com:zhaotbj/zhaotbj.github.io.git master
// 訪問
https://zhaotbj.github.io
複製代碼
恭喜你,運行到這裏就能夠訪問啦! zhaotbj.github.ioreact
GitHub地址 github.com/zhaotbj/vue…git
若是喜歡,給個贊啦🙏~github
歡迎加入大前端學習交流羣 😎🔥🔥🔥 面試