搭建属于自己的网站HEXO静态页(二)发布网站到gihub

配置发布到github

安装插件并修改配置

复制代码
npm install hexo-deployer-git --save

配置_config.xml,修改如下内容

复制代码
deploy:
  type: git
  repo:  git@github.com:it-xusir/it-xusir.github.io.git
  branch: master

repo替换成你的github新建的repo

branch默认master就可以

配置github仓库

进入官网 https://github.com/

点击右上角的 Sign up(注册),不是Sign in(登录)。

填写自己的邮箱、密码、用户名等信息,然后用邮箱验证即可完成。

创建仓库

点击右上角的+按钮,选择New repository,创建一个<用户名>.github.io的仓库

找不到创建入口的,访问:https://github.com/new

仓库的格式必须为:<用户名>.github.io

Description:为描述仓库(选填)

注意选择public仓库

勾选 Initialize this repository with a README 初始化一个 README.md 文件

点击 Creat repository 进行创建

配置git

执行命令

复制代码
git config --global user.name "你的github用户名"  
git config --global user.email "你的邮箱"

通过git config -l 检查是否配置成功,至此git安装及配置全部完成。

复制代码
D:\it-xusir.github.io>git config -l
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=schannel
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.name=it-xusir
user.email=huiyangxu@hotmail.com
core.autocrlf=false

生成ssh公钥

复制代码
ssh-keygen -t rsa -C "你的邮箱"

之后打开C盘下用户文件夹下的.ssh的文件夹,会看到 id_rsa.pub

用记事本打开上述图片中的公钥(id_rsa.pub),复制里面的内容,然后开始在github中配置ssh密钥。

进入github,点击右上角头像 选择settings

进入设置页后选择 SSH and GPG keys

title自己起个名,然后把密钥复制粘贴到key的框内,最后add sshkey

测试

复制代码
D:\it-xusir.github.io>ssh -T git@github.com
Hi it-xusir! You've successfully authenticated, but GitHub does not provide shell access.

上传代码

还有一步配置别忘记了,把_config.xml里的url改成的你域名,如果你还没申请域名,就用github的博客地址。

复制代码
url: https://itxusir.com/

然后

复制代码
hexo clean
hexo generate
hexo deploy

每次你在本地修改完,再重复执行上面的命令,同步到github

配置域名解析

购买域名后,实名认证进入阿里云控制台,点云解析进去,找到你刚买的域名,

点进去添加两条解析记录:

1、cname记录添加,主机www,记录值就是你的github博客地址(我这里是it-xusir.github.io

2、添加A记录, 主机记录@,记录值填github的IP地址(185.199.111.153、185.199.110.153、185.199.109.153、185.199.108.153)

打开博客/source目录,我的是D:\it-xusir.github.io\source,新建CNAME文件,注意没有后缀。然后在里面写上你的域名(例如:itxusir.com),保存。最后运行hexo g、hexo d上传到github。这样到最后当你在地址栏输入xxx.github.io时,才会自动跳转到你的域名。

打开你的github博客项目,点击settings,点击Pages,拉到下面Custom domain处,填上你自己的域名 ,保存。

最后勾选enforcehttps记录。让你的网站变成HTTPS

相关推荐
sunny86535 分钟前
Claude Code 跨会话上下文恢复:从 8 次纠正到 0 次的工程实践
人工智能·开源·github
codingWhat2 小时前
整理「祖传」代码,就是在开发脚手架?
前端·javascript·node.js
ServBay2 小时前
Node.js、Bun 与 Deno,2026 年后端运行时选择指南
node.js·deno·bun
ZengLiangYi5 小时前
Git Tag + Semver + CI/CD:从打标签到自动发布的完整实践
github
徐小夕7 小时前
JitWord Office预览引擎:如何用Vue3+Node.js打造丝滑的PDF/Excel/PPT嵌入方案
前端·vue.js·github
程序员鱼皮7 小时前
离大谱,我竟然在 VS Code 里做了个视频!
github·aigc·ai编程
码路飞9 小时前
Node.js 中间层我维护了两年,这周终于摊牌了——成本账单算完我人傻了
node.js
答案answer10 小时前
一个非常实用的Three.js3D模型爆破💥和切割开源插件
前端·github·three.js