快速閱讀
如何用github 和hexo 創建一個blog
1.github中要新建一個與用戶名同一樣的倉庫, 如:homehe.github.io
- - 必須是io后綴。一個帳戶 只能建立一個
2. 綁定域名 , A記錄指向ip, cname記錄指向homehe.github.io
3. 配置sshkey
- 個人設置 -> SSH and GPG keys -> New SSH key
- 測試 是否成功 ssh -T git@github.com =》You've successfully authenticated 表示成功
3.2 配置用戶名和郵件
$ git config --global user.name "liuxianan"// 你的github用戶名,非昵稱 $ git config --global user.email "xxx@qq.com"// 填寫你的github注冊郵箱
4.安裝hexo
npm install -g hexo
在要目錄下進行初始化 hexo init=>會花費時間 長一點。
$ hexo g # 生成
$ hexo s # 啟動服務hexo就會在public文件夾生成相關html文件,這些文件將來都是要提交到github去的:hexo s是開啟本地預覽服務,打開瀏覽器訪問 http://localhost:4000 即可看到內容
如果端口被占用:
這里我們以8081端口為例講解。
按下Win+R調出命令行窗口,輸入netstat -aon|findstr "8081",找到指定行最后一列的數字(PID),我們這里是9548. 輸入tasklist|findstr "9548",發現是javaw.exe占用了8081端口。 再次輸入taskkill /f /t /im javaw.exe結束該進程。
修改主題
//下載主題到themes/yilia 目錄
$ git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia
修改_config.yml中的theme: landscape改為theme: yilia,然后重新執行hexo g來重新生成
關于yilia目錄的生成
在根目錄下運行
$ npm i hexo-generator-json-content --save
在根目錄下的_config.yml 中增加
jsonContent:meta: falsepages: falseposts:title: truedate: truepath: truetext: falseraw: falsecontent: falseslug: falseupdated: falsecomments: falselink: falsepermalink: falseexcerpt: falsecategories: falsetags: true
部署之前要安裝有關部署的
$ npm install hexo-deployer-git -save
關于部署的配置 ,注意:號后面一定要有空格 。
deploy:type: gitrepository: git@github.com:homehe/homehe.github.io.gitbranch: master
友情提示
? 我對我的文章負責,發現好多網上的文章 沒有實踐,都發出來的,讓人走很多彎路,如果你在我的文章中遇到無法實現,或者無法走通的問題。可以直接在公眾號《愛碼農愛生活 》留言。必定會再次復查原因。讓每一篇 文章的流程都能順利實現。