1 环境安装

1.1 安装HomeBrew

使用brew镜像安装脚本

/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"

可能会有安装提示失败,请自行Google

查看自己的MacBook是否安装brew,执行以下命令

brew
image-20221119104354687

1.2 安装Node.js

可以先查看自己的MacBook是否已经安装了Node

node -v
image-20221119104605289

如果没有安装,执行以下命令

brew install node

1.3 安装Hexo

可以直接使用node安装hexo,【-g在全局进行安装】

npm install hexo-cli -g

1.4 安装git

检查MacBook是否安装git

git --version
image-20221119105231016

如果没有安装,使用brew安装git

brew install git

GitHub账号的创建以及git的配置请自行Google

2 使用Hexo

在本地创建一个文件夹,命名为“MyBlog”,在终端里面进入该文件夹

2.1 初次使用

  1. 初始化目录
hexo init
  1. 开启本地服务
hexo s
image-20221119140403639

在浏览器中输入http://localhost:4000/,即可访问博客首页

2.2 连接GitHub

打开_config.yml文件,修改内容

image-20221119140651960

修改为自己的GitHub链接,密钥如何配置,请自行Google

image-20221119141039195

2.3 Hexo新建博客

  1. 创建一个新的博客
hexo new "新博客"
  1. MyBlogs/source/_posts中找到新博客.md文件,可以编辑内容
  2. 清理历史缓存
heco clean
  1. 产生静态网页
hexo g
  1. 部署到GitHub Page上
hexo d

或者使用一个单独命令

hexo clean && hexo g --d

3 Hexo

使用终端定位到博客文件夹

git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly

修改Hexo根目录下的_config.yml文件,把主题改为butterfly

image-20221119141937438

4 Hexo博客配置

4.1 Front-matter

Front-matter 是 markdown 文件最上方以 — 分隔的区域,用于指定个别档案的变数。

  • Page Front-matter 用于页面配置
  • Post Front-matter 用于文章页配置

如果标注可选的参数,可根据自己需要添加,不用全部都写在markdown里

4.1.1 Page Front-matter

title:
date:
updated:
type:
comments:
description:
keywords:
top_img:
mathjax:
katex:
aside:
aplayer:
highlight_shrink:
写法 解释
title 【必需】页面标题
date 【必需】页面创建日期
type 【必需】标签、分类和友情链接三个页面需要配置
update 【可选】页面更新日期
description 【可选】页面描述
keywords 【可选】页面关键字
comments 【可选】显示页面评论模块(默认 true)
top_img 【可选】页面顶部图片
mathjax 【可选】显示mathjax(当设置mathjax的per_page: false时,才需要配置,默认 false)
katex 【可选】显示katex(当设置katex的per_page: false时,才需要配置,默认 false)
aside 【可选】显示侧边栏 (默认 true)
aplayer 【可选】在需要的页面加载aplayer的js和css,请参考音乐配置
Highlight_shrink 【可选】配置代码框是否展开(true/false)(默认为设置中highlight_shrink的配置)

4.1.2 Post Front-matter

title:
date:
updated:
tags:
categories:
keywords:
description:
top_img:
comments:
cover:
toc:
toc_number:
toc_style_simple:
copyright:
copyright_author:
copyright_author_href:
copyright_url:
copyright_info:
mathjax:
katex:
aplayer:
highlight_shrink:
aside:
写法 解释
title 【必需】文章标题
date 【必需】文章创建日期
updated 【可选】文章更新日期
tags 【可选】文章标签
categories 【可选】文章分类
keywords 【可选】文章关键字
description 【可选】文章描述
Top_img 【可选】文章顶部图片
cover 【可选】文章缩略图(如果没有设置top_img,文章页顶部将显示缩略图,可设为false/图片地址/留空)
comments 【可选】显示文章评论模块(默认 true)
toc 【可选】显示文章TOC(默认为设置中toc的enable配置)
toc_number 【可选】显示toc_number(默认为设置中toc的number配置)
toc_style_simple 【可选】显示 toc 简洁模式
copyright 【可选】显示文章版权模块(默认为设置中post_copyright的enable配置)
copyright_auther 【可选】文章版权模块的文章作者
copyright_author_href 【可选】文章版权模块的文章作者链接
copyright_url 【可选】文章版权模块的文章连结链接
copyright_info 【可选】文章版权模块的版权声明文字
mathjax 【可选】显示mathjax(当设置mathjax的per_page: false时,才需要配置,默认 false)
katex 【可选】显示katex(当设置katex的per_page: false时,才需要配置,默认 false)
aplayer 【可选】在需要的页面加载aplayer的js和css,请参考文章下面的音乐 配置
highlight_shrink 【可选】配置代码框是否展开(true/false)(默认为设置中highlight_shrink的配置)
aside 【可选】显示侧边栏 (默认 true)

4.2 Hexo新建博文自定义模版

打开博客文件夹目录下的scaffolds文件夹

Hexo博客文件夹

修改post.md文件

title: {{ title }}  //文章标题
date: {{ date }} //文章创建时间
permalink: //文章显示连接
categories: //文章匪类目录
tags: [] //文章标签,可多个,用,隔开
description: //文章描述
image: //自定义的文章摘要图片,只在页面展示,文章内消失
copyright: true //增加底部的版权信息(需要配置)

5 官方资料

官网:https://hexo.io/

官方文档:https://hexo.io/docs/

文体中心:https://hexo.io/docs/troubleshooting.html

GitHub:https://github.com/hexojs/hexo/issues