github+hexo

GitHub设置

  1. 已经有了账号,本地也有sshkey,所以需要把id_rsa.pub文件的内容复制到账号–setting–”SSH and GPG keys”下面

  2. 验证是否成功的方式:ssh -T git@github.com

  3. 进入github.com的网站,选择Repositories旁边的 New,输入name.github.io作为Repository name,下面选择 Add a README file,最后选 Create repository  

  4. 进入后选择 Settings,注意在GeneralDefault branch这里写的是什么,我的是main

  5. 选择Pages后,Source这里选择Deploy from a branch, Branch 这里选择main

  6. 同时上面的GitHub Pages这里会显示访问的地址:https://name.github.io

name必须是用户名

本地设置

  • 下载nodejs: https://nodejs.org/

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

  • 设置好本地目录:比如我的blog

1
2
3
4
hexo init blog
cd blog
npm install
npm install hexo-deployer-git --save

hexo命令:

1
2
3
4
5
hexo clean // 清空
hexo g // g=generate 生成静态目录
hexo d // d=deploy 发布
hexo s // s=server 本地调试,浏览器localhost:4000
hexo new test //发一篇文章

也可以使用一条命令发布
hexo clean && hexo g && hexo d

  • 网站设置在文件 _config.yml中,下面是配置说明:
    • title: 网站标题
    • subtitle: 副标题
    • description: 网站描述
    • author: 作者名字
    • language: zn-CN 网站语言

每一个冒号后面跟一个英文的空格

配置主题:
git clone https://github.com/cjquines/hexo-theme-ascent themes/ascent

修改 _config.ymlDeployment部分:

1
2
3
4
5
6
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: 'git'
repo: git@github.com:name/name.github.io.git
  branch: main
  • repo的部分在github的 Code下面的 SSH中复制

  • branch必须跟settings中 GitHub Pages 指定的Branch一样

    1. 修改 themes 部分:theme: ascent
    2. 文章发布在 source/_posts中存为md格式
    3. source 目录下新建CNAME文件,里面写上绑定的二级域名it.leon.vc,然后在settingsPages下的Custom domain中验证域名,这样可以绑定域名.
    4. 设置域名A记录指向如下ip之一:

      185.199.108.153
      185.199.109.153
      185.199.110.153
      185.199.111.153

默认目录如下

├── .deploy         # 需要部署的文件
├── node_modules    # Hexo依赖
├── public          # 生成的静态网页文件
├── scaffolds       # 模板,当您新建文章时,Hexo 会根据 scaffold 来建立文件。
├── source          # 博客正文和其他源文件,404、favicon、CNAME 都应该放在这里
| ├── _drafts       #   草稿
| └── _posts        #   文章
├── themes          # 主题,Hexo 会根据主题来生成各种各样的静态页面。
├── _config.yml     # 全局配置文件,您可以在此配置大部分的参数。
└── package.json    # npm 依赖配置文件

一些配置

更改永久链接:

permalink: :year-:month-:day-:name.html