搭建 hexo 博客并部署到 github

搭建 hexo 博客并部署到 github

建立本地项目

  • 新建空文件夹
  • 右键点击 git bash here
  • 安装 hexo 框架:npm install -g hexo-cli
  • 初始化文件夹:hexo init
  • 安装依赖:npm install
  • 启动服务器:hexo server

将博客推到远程仓库

  • 新建 git 仓库,名称为:.github.io (好处是:通过https://username.github.io/就可以访问到你的仓库/blog/project主页, 而不需要在 github.io/后面再加上仓库名)

  • 安装插件:npm install hexo-deployer-git --save  为了能够使Hexo部署到GitHub上,需要安装一个插件:(在项目目录下执行命令)

  • 创建一个 SSH key:ssh-keygen -t -rsa -C "email address"

  • 将密钥添加到 github,验证是否添加成功:ssh -T git@github.com

  • 在 _config.yml 文件最后修改为:

    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/one-command-deployment
    deploy:
    type: git
    repo: git@github.com:Rodma1/Rodma1.github.io.git
    branch: master

    注意 type: 后面一定要有空格,不然会报错,仓库地址写 ssh 地址(以后提交时不用输用户名密码)

  • 推送到 github:hexo g hexo d

hexo clean && hexo deploy

网站的配置

网站

设置 描述
title 网站标题
subtitle 网站副标题
description 网站描述
keywords 网站的关键词。 支持多个关键词。
author 您的名字
language 网站使用的语言。 使用 2 个字母的 ISO-639-1 代码,或 它的变体。 默认为 en
timezone 网站时区。 Hexo 默认使用您电脑的时区。 请参考 时区列表 进行设置,如 America/New_York, Japan, 和 UTC 。 一般的,对于中国大陆地区可以使用 Asia/Shanghai

网址

设置 描述 默认值
url 网址, 必须以 http://https:// 开头
root 网站根目录 url's pathname
permalink 文章的 永久链接 格式 :year/:month/:day/:title/
permalink_defaults 永久链接中各部分的默认值
pretty_urls 改写 permalink 的值来美化 URL
pretty_urls.trailing_index 是否在永久链接中保留尾部的 index.html,设置为 false 时去除 true
pretty_urls.trailing_html 是否在永久链接中保留尾部的 .html, 设置为 false 时去除 (对尾部的 index.html无效) t

一些问题

  • 推送失败:错误码 443 ,配置一下 host 文件

  • 仓库找不到:重新配置 github 用户名、邮箱等(注意没有下划线)

然后创建一个私有仓库保存我们自己的hexo文件

1
2
3
4
5
6
7
echo "# hexo" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:Rodma1/hexo.git
git push -u origin main

访问地址

https://rodma1.github.io/

官方文档: https://hexo.io/zh-cn/docs/


搭建 hexo 博客并部署到 github
https://rodma1.github.io/2024/10/12/blog/搭建hexo博客并部署到github/
作者
神唱
发布于
2024年10月12日
许可协议