搭建hexo博客系统
搭建hexo博客系统
前几天完成了一个hexo主题,便想着出一篇关于搭建hexo博客系统的博客。在正文开始之前,假设你已掌握如下技能:
- git基本操作
- hexo命令
npm install hexo-cli -g // 在你准备存放项目的路径下 hexo init blog
下载 hexo-theme-sky 主题
cd blog git clone https://github.com/iJinxin/hexo-theme-sky theme/sky
修改博客根目录下的配置文件 _config.yml ,启用 sky 主题
theme: sky
安装依赖项
npm install
npm install hexo-renderer-scss --save
运行
hexo server
启动服务后,访问 http://localhost:4000 预览主题
到目前为止,本地博客系统就已经启动完成了。
更多配置
设置站点使用语言
主题默认使用中文,可以在 _config_yml 中修改 languages 字段进行修改
languages: en
目前支持的语言:
- 简体中文:zh-cn
- 英文:en
如果你有兴趣添加其他语言在主题中可以给我发PR。
设置建站时间, 作者
底部默认的建站时间为今年
© 2018 by John Doe
修改 _config 中 author 字段,然后添加 since 字段
author: iJinxin
since: 2017
修改后的效果为
© 2017 - 2018 by iJinxin
添加标签页
新建标签页
hexo new page tags
编辑生成的 tags/index.md 文件,设置 tags 布局
layout: tags
在主题配置文件 themes/_config.yml 文件中
# menu menu: Home: / Archives: /archives Tags: /tags
添加分类页
新建分类页
hexo new page categories
编辑生成的 categories/index.md 文件,设置 categories 布局
layout: categories
添加About页面
新建about页
hexo new page about
编辑生成的 about/index.md 文件,设置 about 布局
layout: about
在主题配置文件 themes/_config.yml 文件中
# menu menu: Home: / Archives: /archives Tags: /tags About: /about
设置底部社交信息
目前仅引入了github, 微博,知乎
在配置文件 _config.yml 添加社交账号名
github_username: your github username
weibo_username:
zhihu_username:
添加评论服务
主题使用了 gitment,在使用之前,需要获取client ID,和client seret。
点击这里 注册一个新的 OAuth Application。其他内容可以随意填写,但需要保证填入正确的callback URL (一般是评论页面对应的域名,如 https://imsun.net,https://iJinxin.github.io/ 等)
然后在配置文件 _config.yml 中添加评论
comment:
owner: your github ID
repo: 存储评论的repo
id: your client ID
secret: your client seret
更多关于 gitment 的介绍,可以查看 作者博客
示例
在 source/_post 目录下新建 hello.md 文件, 内容如下
--- title: hello, date: 2018-10-29 10:10:10 tags: thinking categories: 随笔 --- 这里是文章的开头部分,在设置了“阅读全文”功能后,首页只显示该部分的文字 <!-- more --> 这里是文章的剩下部分,点击“文章标题”或者“阅读全文”后才能看见。
使用github page搭建线上版本
网上有很多教程,具体可以参考 这一篇
需要注意的是,若在本机上没有设置SSH的话,在发布时会报错,如何在本机上设置SSH可以参考 设置SSH。
## 最后
- 如果本篇教程对您有所帮助,可以去 github 上Star一下,感激不尽。
- 如果发现bug或者有更好的建议,欢迎PR
浙公网安备 33010602011771号