使用hexo搭建博客,託管於github
配置環境: node + git
hexo
安裝hexo
npm install hexo -g
初始化hexo
hexo init 或 hexo init <文件名>
注:不加文件名會在當前目錄下下載初始文件
生成靜態頁面
hexo generate 或 hexo g
本地啓動服務
hexo server 或 hexo s
瀏覽器輸入http://localhost:4000可以看到主頁,默認主題landscape
github
新建項目
項目名稱與git賬號名稱一致
複製項目ssh地址
配置hexo+git
在本地hexo初始化後的文件找到 _config.yml
在文件中找到
deploy:
修改爲
deploy:
type: git
repo: [email protected]:yourname/yourname.github.io.git //複製的ssh地址,yourname爲賬戶名
branch: master
部署
部署前要先安裝自動部署工具
npm install hexo-deployer-git --save
部署
hexo d
瀏覽器輸入 yourname.github.io可以看到博客的主頁了(yourname爲git賬戶名)
hexo 命令
hexo init //初始化項目
hexo generate //生成靜態頁面
hexo clean //清除生成靜態頁面
hexo server //啓動本地服務
hexo deploy //部署
hexo new page 'example' //新建名爲example頁面
hexo new 'example' //新建名爲example文章
報錯處理
ERROR Deployer not found: git
解決方法:
npm install hexo-deployer-git –save
接下來就可以開啓博客之旅啦!^_^