用hexo创建博客

安装

输入命令:
npm install -g hexo-cli

创建hexo文件夹

创建一个博客目录,在该目录下
hexo init

安装依赖包

npm install站点配置

站点配置

必须要改动的

1
2
3
4
5
title: xxx  # 博客名,站点名称
author: xxx # 博客作者名字
description: xxx # 对站点的描述,搜索引擎会抓取,可以自定义
language: zh-Hans # 语言 简体中文
theme: next # 配置主题,后面会讲到主题配置123456789

发布必须要增加的

1
2
3
4
deploy: # 部署相关配置
type: git # 使用 Git 提交
repository: git@github.com/username/username.github.io.git # 博客仓库地址
#repository: https://github.com/xxx/xxx.github.io.git

本地查看默认站点

生成文件
hexo ghexo generate

启动服务
hexo shexo server

浏览器输入localhost:4000查看

部署到github

确认站点配置文件配置正确

1
2
3
4
deploy:
type: git
repository: https://github.com:username/username.github.io.git
branch: master

发布
hexo clean && hexo g && hexo d


hexo clean && hexo generate && hexo deploy

发布文章

1
hexo new "博客文章文件名"

或新建md文件放到
/source/_posts文件夹或其子文件夹中

文章要按照规定格式书写,如:

1
2
3
4
5
6
7
title: 个人博客搭建详解 # 这是标题
tags: # 这里写的标签会自动汇集到 tags 页面上
- 实用 # 可配置多个标签,注意格式
- 个人博客
category: # 这里写的分类会自动汇集到 categories 页面上,分类可以多级
- 实用技术 # 一级分类
- 个人博客 # 二级分类

本地预览文章

清除缓存: hexo clean
生成静态网页: hexo g
预览: hexo s

注意

  1. 已发布的文章发生修改, 可直接预览,即 不执行上述3个命令,刷新浏览器即可;
  2. 远程部署必须要执行上述命令
  3. 修改内容一旦预览与修改不一致,则需要clean

也可一次性执行:hexo clean && hexo g && hexo s

创建分类及标签页面

分类

命令:hexo new page "categories"

找到 index.md 文件增加页面类型:

type: “categories” #将页面的类型设置为categories

标签

hexo new page "tags"
index.md文件
设置页面类型:
type: “tags”

站点配置:启用分类及标签,清除缓存,生成页面,启动服务预览,无问题后发布

404页面

1
hexo new page "404"

编辑source/404.md即可