Hexo 博客搭建

[TOC]


博客基本搭建

环境准备

Hero 文档

Hexo is a fast, simple and powerful blog framework. You write posts in Markdown (or other markup languages) and Hexo generates static files with a beautiful theme in seconds.

安装node 和 npm

推荐使用brew install 安装node,安装node会自动安装npm

1
2
brew install node
node -v

安装hexo

1
2
3
4
5
6
npm install hexo-cli -g

# hexo 在5.0 之后把swig 删除了,需要手动安装,否则会出现加载theme 出错的问题
# https://blog.csdn.net/qq_39898645/article/details/109181736

npm install hexo-renderer-swig

利用Hexo 搭建一个博客

创建博客目录 felixyh.github.io

1
2
3
hexo init felixyh.github.io
cd felixyh.github.io
npm install

生成静态页面

1
2
hexo clean
hexo g

本地运行

打开浏览器,输入地址 localhost:4000 即可看到效果

1
hexo s

Hexo 基本使用

文章发布

  • 命令行模式

    • 生成文件

      1
      hexo new test

      在**source/_posts/**中生成test.md文件,输入内容,并且保存

    • 生成静态页面

      1
      2
      3
      hexo clean
      hexo g
      hexo s
  • 直接在**source/_posts/**创建.md文件

配置

网站的设置大部分都在**_config.yml**文件中,详细配置可以查看官方文档

下面只列出简单常用配置

  • title -> 网站标题
  • subtitle -> 网站副标题
  • description -> 网站描述
  • author -> 您的名字
  • language -> 网站使用的语言

坑:进行配置时,需要在冒号:后加一个英文空格

1
title: Droidlover

增加评论功能

gitment Demo

gitment 教程

换一个好看的主题

Hexo 中有很多主题,可以在官网查看。

我的博客使用的主题是: hexo-theme-minimalism

参考minimalism主题安装步骤:快速开始

部署到Github

  1. 创建一个xxx.github.io的public的仓库,也可以使用private 仓库,但是需要付费,参考github pages

  2. 安装git deployment 插件hexo-deployer-git

    1
    npm install hexo-deployer-git --save
  3. 网站配置git

    branch 为分支,默认为master。如果github 的分支是main,配置也要改成main

    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/one-command-deployment
    deploy:
    type: git
    repo: https://github.com/felixyh/felixyh.github.io.git
    branch: main
  4. 部署

    1
    hexo d

Github 源代码管理

使用git分支保存hexo博客源码到github

可以参考上述文章,注意最后推送博客源码到分支的时候,强制推送覆盖github分支上的博客静态页面代码为博客源代码,不然会报错。git push origin source -f


Hexo 博客搭建
https://blog.excelsre.com/2023/05/28/hexo-bo-ke-da-jian/
作者
Felix Yang
发布于
2023年5月29日
许可协议