个人博客

基于 HEXO 的个人博客搭建教程

目录

参考文章:

基于Hexo的个人博客搭建

友情链接:

HEXO的github
HEXO官方安装指南
HEXO的主题库

基础环境配置

Hexo安装

  • 安装Hexo: npm install -g hexo-cli

Hexo配置

Hexo主题配置

  • 选择一个主题: 从HEXO的主题库选择一个你喜欢的主题, 例如: hexo-theme-next
  • 安装主题: npm install hexo-theme-next --save
  • 配置主题: 在博客根目录下的 _config.yml 文件中, 找到 theme 字段, 并将其值设置为你安装的主题名称, 例如: theme: next

Hexo部署

  • 配置github pages: 确保你有一个github账号, 并在github上创建一个新的仓库, 仓库名称为 yourusername.github.io, 其中 yourusername 是你的github用户名.

  • 配置git: 确保你已经配置了git的全局用户名和邮箱, 可以使用以下命令进行配置:

    1
    2
    git config --global user.name "yourusername"
    git config --global user.email "youremail@example.com"
  • 配置ssh密钥: 确保你已经配置了ssh密钥, 可以使用以下命令进行配置:

    1
    ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
  • 添加ssh密钥到github: 将 ~/.ssh/id_rsa.pub 文件的内容复制到github账号的ssh密钥设置中.

  • 配置部署: 在博客根目录下的 _config.yml 文件中, 找到 deploy 字段, 并根据你选择的部署方式进行配置, 例如:

    1
    2
    3
    4
    deploy:
    type: git
    repo: https://github.com/yourusername/yourusername.github.io.git
    branch: master
  • 部署: hexo deploy

博客书写及上传

  • 新建md文件: hexo new "文章标题"
  • 编辑md文件: 使用你喜欢的文本编辑器打开 source/_posts/文章标题.md 文件, 并在文件中编写你的博客内容.
  • 上传博客: hexo deploy

常用命令

  • 初始化博客: hexo init
  • 安装依赖: npm install
  • 生成静态文件: hexo generate
  • 启动本地服务器: hexo server
  • 部署到GitHub Pages:
    • 安装部署插件: npm install hexo-deployer-git --save
    • 新建md文件: hexo new "文章标题"
    • 部署:
      1
      2
      3
      hexo clean
      hexo generate
      hexo deploy