hexo + github
安装Node.js
在Node.js官网根据自己系统版本下载安装。(直接下一步下一步就好了)
安装git
安装很简单,一直下一步 git安装教程
安装成功你在桌面右键,就能看到多了两个git命令
注册一个github
GitHub官网。按照一般的网站注册登录执行就好了,不懂自行goole。
在github上新建一个厂库
需要把Repository name 改成你自己的,例如我的:15735046155.github.io
创建时记得勾上选项 Initialize this repository with a README,完成之后,你可以在地址栏,打开yourname.github.io查看是否成功。
安装hexo
Hexo是一个简单、快速、强大的基于 Github Pages 的博客发布工具,支持Markdown格式,有众多优秀插件和主题。
hexo官网:https://hexo.io/zh-cn/docs/
这个时候nodejs的npm就排上用场了,你可以用系统自带的命令面板(window下是cmd),也可以用git bash here(推荐)
检查一下npm是否安装成功
npm -v
npm install hexo-cli -g
如果npm安装很慢,被墙了,推荐使用淘宝镜像
初始化:
在电脑的某个地方新建一个名为blog的文件夹(名字可以随便取),比如我的是C:\blog,由于这个文件夹将来就作为你存放代码的地方,所以最好不要随便放。然后在这个文件夹内,右键打开git base here,就是这么神奇,哪里都有它。
检查你的hexo 是否安装成功
hexo -v
初始化hexo
hexo init #hexo会自动下载一些文件到这个目录,包括node_modules
npm install hexo-deployer-git
此时直接执行hexo d的话一般会报如下错误:(安装hexo-deployer-git的原因)
Deployer not found: github 或者 Deployer not found: git
然后依次执行以下命令:
$ hexo g # 生成
$ hexo s # 启动服务
执行以上命令之后,hexo就会在public文件夹生成相关html文件,然后会提示你
INFO Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.
hexo s是开启本地预览服务,在浏览器中打开 http://localhost:4000/ ,即可看到内容, 很多人会碰到浏览器一直在转圈但是就是加载不出来的问题,一般情况下是因为端口占用的缘故,因为4000这个端口太常见了,解决端口冲突问题请参考这篇文章:http://blog.liuxianan.com/windows-port-bind.html
连接github,让别人也能访问你的blog
考虑到大家可能会存在的一种情况,就是换电脑,或者在家里和公司都想写blog,管理他,该怎么做呢!
- 新建一个hexo分支(branches)
这个分支就是用来装hexo的核心源文件的!慢慢往下看,一步一步来
在你的博客文件夹内,打开git base here。如果你的文件正确的话,现在是没有.git文件的,这是个隐藏文件夹,有的小伙伴没有设置怎么查看隐藏文件,不会的可以根据你的系统去百度一下,很简单的。
git init //初始化本地仓库 会生成一个.git文件 git add source scaffolds themes .gitignore _config.yml package.json //将这6个文件提交到hexo分支,这就是源文件了, source里面就是装的你的博客文章 git commit -m "Blog Source Hexo" git branch hexo //新建hexo分支 git checkout hexo //切换到hexo分支上 git remote add origin https://github.com/15735046155/15735046155.github.io.git(换成你自己的) //将本地与Github项目对接 很多教程说要用ssh,我这里用https也没有出错 git push origin hexo //push到Github项目的hexo分支上
提交完成之后,你可以在github上的厂库里看到:
- 将博客文章提交到master页面
在你博客文件夹中找的C:\blog\_config.yml文件,修改以下几处 (文末附上其他配置信息介绍)
# Site
title: coder # 博客名
subtitle: # 副标题
description: # 描述
author: 只有极其努力,才能看起来毫不费力。 # 作者
language: zh-Hans # 语言,还是改成汉语吧
deploy: type: git repository: https://github.com/15735046155/15735046155.github.io.git branch: master
然后你就可以执行以下命令:
hexo g #生成静态文件。
hexo d #部署网站。
现在可以再打开yourname.github.io看看了。不出意外,就成功了。
换了电脑之后怎么弄
在新电脑上,nodejs,git,github这些都要有哦
git clone -b hexo https://github.com/15735046155/15735046155.github.io.git //将Github中hexo分支clone到本地 cd yourname.github.io //切换到刚刚clone的文件夹内 npm install //注意,这里一定要切换到刚刚clone的文件夹内执行,安装必要的所需组件,不用再init npm install -g hexo-cli // 如果电脑上没有安装这个,需要先安装 hexo new post "new blog name" //新建一个.md文件,并编辑完成自己的博客内容 git add source //经测试每次只要更新sorcerer中的文件到Github中即可,因为只是新建了一篇新博客 git commit -m "XX" //提交的注释 git push origin hexo //更新分支 hexo d -g //push更新完分支之后将自己写的博客对接到自己搭的博客网站上,同时同步了Github中的master
如果hexo d -g没有生效
可以再执行
hexo g
hexo d
你如果有多个电脑在用,每次写了blog在其他电脑上执行一下:
git pull origin hexo
next主题
git地址:https://github.com/iissnan/hexo-theme-next
- 将下载的代码放在blog/theme/目录下
- 设置站点myBlog/_config.yml的theme字段值为hexo-theme-next
- 生成新页面hexo g
- 开启服务hexo s –debug
- 发布代码hexo d
安装next主题:https://blog.csdn.net/zuoziji416/article/details/53204478
主题配置:https://segmentfault.com/a/1190000009544924
完整的配置信息如下
# Site #站点信息 title: blog Name #标题 subtitle: Subtitle #副标题 description: my blog desc #描述 author: me #作者 language: zh-CN #语言 timezone: Asia/Shanghai #时区 # URL url: http://yoururl.com #用于绑定域名, 其他的不需要配置 root: / #permalink: :year/:month/:day/:title/ permalink: posts/title.html permalink_defaults: # Directory #目录 source_dir: source #源文件 public_dir: public #生成的网页文件 tag_dir: tags #标签 archive_dir: archives #归档 category_dir: categories #分类 code_dir: downloads/code i18n_dir: :lang #国际化 skip_render: # Writing #写作 new_post_name: :title.md #新文章标题 default_layout: post #默认模板(post page photo draft) titlecase: false #标题转换成大写 external_link: true #新标签页里打开连接 filename_case: 0 render_drafts: false post_asset_folder: false relative_link: false future: true highlight: #语法高亮 enable: true line_number: true #显示行号 auto_detect: true tab_replace: # Category & Tag #分类和标签 default_category: uncategorized #默认分类 category_map: tag_map: # Date / Time format #日期时间格式 ## http://momentjs.com/docs/#/displaying/format/ date_format: YYYY-MM-DD time_format: HH:mm:ss # Pagination #分页 per_page: 10 #每页文章数, 设置成 0 禁用分页 pagination_dir: page # Extensions #插件和主题 ## 插件: http://hexo.io/plugins/ ## 主题: http://hexo.io/themes/ theme: hexo-theme-next # Deployment #部署, 同时发布在 GitHub 和 GitCafe 上面 deploy: - type: git repo: git@gitcafe.com:username/username.git,gitcafe-pages - type: git repo: git@github.com:username/username.github.io.git,master # Disqus #Disqus评论系统 disqus_shortname: plugins: #插件,例如生成 RSS 和站点地图的 - hexo-generator-feed - hexo-generator-sitemap
常用命令:
hexo clean #相当于清理下缓存
hexo g #生成public文件,相当于打包
hexo s #启动本地服务,在localhost:4000查看效果
hexo d #部署网站
评论
参考:评论功能连接

浙公网安备 33010602011771号