[关闭]
@Bios 2018-12-10T08:41:33.000000Z 字数 4480 阅读 896

免费搭建博客

hexo


更新日志:

我自己在换了公司的电脑后发现按照“换了电脑之后怎么弄弄”没有跑通。
问题在于,如果新电脑上没有全局安装hexo-cli

注册一个github

GitHub官网。按照一般的网站注册登录执行就好了,不详细说。

安装git


安装很简单,一直下一步 git安装教程

很多教程里都说要配置环境变量,我本人安装过5次左右的git,一次都没有配过,但是要配置用户名和邮箱,就是和github注册的一样


安装成功你在桌面右键,就能看到 多了两个 git命令

安装Nodejs

安装nodejs主要是为了安装npm包管理工具

Nodejs官网下载自己系统的版本安装就好了

安装也是极其简单,一直下一步就好了。
推荐Nodejs安装教程!

在github上新建一个厂库

需要把Repository name 改成你自己的哦,例如我的:finget.github.io

创建好了,来到Settings页面,开启gh-pages功能

在最后找到Github pages(我的是默认开启的,如果你不是就点击Launch automatic page generator按钮,一直下一步就行了)

完成之后,你可以在地址栏,打开yourname.github.io查看是否成功。

安装hexo

Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。

hexo官网:https://hexo.io/zh-cn/docs/

这个时候nodejs的npm就排上用场了
你可以用系统自带的命令面板(window下是cmd),也可以用git bash here(推荐)

以下的命令懂得就不说了,不懂得小伙伴可以自己去了解一下

检查一下npm是否安装成功

  1. npm -v

  1. npm install hexo-cli -g

如果npm安装很慢,被墙了,推荐使用淘宝镜像

常用指令:

  1. hexo init [folder]

新建一个网站。如果没有设置 folder ,Hexo 默认在目前的文件夹建立网站。

  1. hexo new [layout] <title>
  2. hexo new post <title>

新建一篇文章。如果没有设置 layout 的话,默认使用 _config.yml 中的 default_layout 参数代替。如果标题包含空格的话,请使用引号括起来。

  1. hexo generate

生成静态文件。

  1. hexo server

启动服务器。默认情况下,访问网址为: http://localhost:4000/

  1. hexo deploy

部署网站。

初始化blog

你可以在C、D、E、F盘任意一个地方,只要你喜欢,哪里都是可以的。新建一个文件夹来管理你的blog。
然后在这个文件夹内,右键打开git base here,就是这么神奇,哪里都有它。

  1. hexo -v

  1. hexo init
  1. npm install 或者 cnpm install(如果你用了淘宝镜像)
  1. npm install hexo-deployer-git
  1. hexo g
  1. hexo s

然后会提示你:

  1. INFO Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.

在浏览器中打开http://localhost:4000/,你将会看到:

到这里 恭喜你,你的本地blog已经搭建好了,把本地圈起来要考。哈哈哈[捂脸]

与github对接,让别人也能访问你的blog

考虑到大家可能会存在的一种情况,就是换电脑,或者在家里和公司都想写blog,管理他,该怎么做呢!

这个分支就是用来装hexo的核心源文件的!慢慢往下看,一步一步来

在你的博客文件夹内,打开git base here。如果你的文件正确的话,现在是没有.git文件的,这是个隐藏文件夹,有的小伙伴没有设置怎么查看隐藏文件,不会的可以根据你的系统去百度一下,很简单的。

  1. git init //初始化本地仓库 会生成一个.git文件
  2. git add source scaffolds themes .gitignore _config.yml package.json //将这6个文件提交到hexo分支,这就是源文件了, source里面就是装的你的博客文章
  3. git commit -m "Blog Source Hexo"
  4. git branch hexo //新建hexo分支
  5. git checkout hexo //切换到hexo分支上
  6. git remote add origin https://github.com/FinGet/finget.github.io.git(换成你自己的,如下图) //将本地与Github项目对接 很多教程说要用ssh,我这里用https也没有出错
  7. git push origin hexo //push到Github项目的hexo分支上

提交完成之后,你可以在github上的厂库里看到:

在你博客文件夹中找的F:\hexoBlog\_config.yml文件,修改以下几处 (文末附上其他配置信息介绍)

  1. # Site
  2. title: FinGet # 博客名
  3. subtitle: 前端 —— 我一直在路上 # 副标题
  4. description: # 描述
  5. author: FinGet # 作者
  6. language: zh-Hans # 语言,还是改成汉语吧
  7. timezone:
  1. deploy:
  2. type: git
  3. // 这里可能需要密码
  4. repository: https://github.com/FinGet/finget.github.io.git
  5. branch: master

然后你就可以执行以下命令

  1. hexo g
  1. hexo d

现在可以再打开yourname.github.io看看了。不出意外,就成功了。

换了电脑之后怎么弄弄

在新电脑上,nodejs,git,github这些都要有哦

  1. git clone -b hexo https://github.com/FinGet/finget.github.io.git //将Github中hexo分支clone到本地
  2. cd yourname.github.io //切换到刚刚clone的文件夹内
  3. npm install //注意,这里一定要切换到刚刚clone的文件夹内执行,安装必要的所需组件,不用再init
  4. npm install -g hexo-cli // 如果电脑上没有安装这个,需要先安装
  5. hexo new post "new blog name" //新建一个.md文件,并编辑完成自己的博客内容
  6. git add source //经测试每次只要更新sorcerer中的文件到Github中即可,因为只是新建了一篇新博客
  7. git commit -m "XX"
  8. git push origin hexo //更新分支
  9. hexo d -g //push更新完分支之后将自己写的博客对接到自己搭的博客网站上,同时同步了Github中的master

如果hexo d -g没有生效
可以再执行

  1. hexo g
  2. hexo d

你如果有多个电脑在用,每次写了blog在其他电脑上执行一下:

  1. git pull origin hexo

next 主题

git地址:https://github.com/iissnan/hexo-theme-next

安装next主题:https://blog.csdn.net/zuoziji416/article/details/53204478

主题配置:https://segmentfault.com/a/1190000009544924

完整的配置信息如下

  1. # Site #站点信息
  2. title: blog Name #标题
  3. subtitle: Subtitle #副标题
  4. description: my blog desc #描述
  5. author: me #作者
  6. language: zh-CN #语言
  7. timezone: Asia/Shanghai #时区
  8. # URL
  9. url: http://yoururl.com #用于绑定域名, 其他的不需要配置
  10. root: /
  11. #permalink: :year/:month/:day/:title/
  12. permalink: posts/title.html
  13. permalink_defaults:
  14. # Directory #目录
  15. source_dir: source #源文件
  16. public_dir: public #生成的网页文件
  17. tag_dir: tags #标签
  18. archive_dir: archives #归档
  19. category_dir: categories #分类
  20. code_dir: downloads/code
  21. i18n_dir: :lang #国际化
  22. skip_render:
  23. # Writing #写作
  24. new_post_name: :title.md #新文章标题
  25. default_layout: post #默认模板(post page photo draft)
  26. titlecase: false #标题转换成大写
  27. external_link: true #新标签页里打开连接
  28. filename_case: 0
  29. render_drafts: false
  30. post_asset_folder: false
  31. relative_link: false
  32. future: true
  33. highlight: #语法高亮
  34. enable: true
  35. line_number: true #显示行号
  36. auto_detect: true
  37. tab_replace:
  38. # Category & Tag #分类和标签
  39. default_category: uncategorized #默认分类
  40. category_map:
  41. tag_map:
  42. # Date / Time format #日期时间格式
  43. ## http://momentjs.com/docs/#/displaying/format/
  44. date_format: YYYY-MM-DD
  45. time_format: HH:mm:ss
  46. # Pagination #分页
  47. per_page: 10 #每页文章数, 设置成 0 禁用分页
  48. pagination_dir: page
  49. # Extensions #插件和主题
  50. ## 插件: http://hexo.io/plugins/
  51. ## 主题: http://hexo.io/themes/
  52. theme: next
  53. # Deployment #部署, 同时发布在 GitHub 和 GitCafe 上面
  54. deploy:
  55. - type: git
  56. repo: git@gitcafe.com:username/username.git,gitcafe-pages
  57. - type: git
  58. repo: git@github.com:username/username.github.io.git,master
  59. # Disqus #Disqus评论系统
  60. disqus_shortname:
  61. plugins: #插件,例如生成 RSS 和站点地图的
  62. - hexo-generator-feed
  63. - hexo-generator-sitemap
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注