Github+Hexo搭建个人博客

本文介绍如何使用Hexo生成静态站点并部署到Github的过程,包括环境搭建、主题配置及常见错误处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


title: Github+Hexo搭建个人博客
tags: HEXO
category: 个人博客

首发网址:https://tiansztiansz.github.io/2022/01/29/Github+Hexo搭建个人博客/

安装git

https://npm.taobao.org/mirrors/git-for-windows/

往下滑找到最新版本下载安装即可

安装node.js

https://tiansztiansz.github.io/2022/01/27/安装并配置nodejs/

在Github新建仓库

注意仓库名称为用户名.github.io

安装Hexo

在D盘新建blog文件夹,或者其他位置都行

然后打开 git bush 程序,执行以下命令:

cd /d/blog
npm install -g hexo-cli
hexo init
hexo g
hexo s

然后按命令窗口提示打开网页进行预览

将Hexo部署到Github

打开blog文件夹下的_config.yml,将如下内容进行修改。注意在配置文件中,键值对中间一定要加空格,否则会报错

deploy:
  type: git
  repository: 
    github: https://github.com/tiansztiansz/tiansztiansz.github.io.git  #你的仓库地址
    gitee: https://gitee.com/a1866/a1866.git
  branch: master

按如上方法可以实现github和gitee的双部署

然后再在 git bush中输入如下命令:

npm install hexo-deployer-git --save
hexo clean
hexo g
hexo d

以上即可将网站部署到远端,然后打开网址https://tiansztiansz.github.io/,即可看到网站已部署成功,其中tiansztiansz更改为自己的github用户名

更改主题为Next

继续在git bush执行如下命令,下载next主题:

git clone https://github.com/theme-next/hexo-theme-next themes/next

打开blog文件夹下的_config.yml,修改主题

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next

进行本地预览:

hexo s

然后将更改部署到远端:

hexo clean
hexo g
hexo d

常见错误

若出现如下报错,是由于网络原因,再重复执行几次命令就好

fatal: unable to access 'https://github.com/hexojs/hexo-starter.git/': OpenSSL SSL_read: Connection was reset, errno 10054
WARN  git clone failed. Copying data instead
FATAL {
  err: [Error: EPERM: operation not permitted, mkdir 'D:\'] {
    errno: -4048,
    code: 'EPERM',
    syscall: 'mkdir',
    path: 'D:\\'
  }
} Something's wrong. Maybe you can find the solution here: %s http://hexo.io/docs/troubleshooting.html

参考文献

https://www.zhihu.com/column/c_1201860091307458560
https://www.runoob.com/git/git-install-setup.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宁静_致远_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值