搭建属于自己的网站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

相关推荐
mediocrep1 小时前
我的Hexo博客搭好了04 - 备份Hexo博客的源码目录,上传到Gitee仓库
hexo·博客搭建·github pages·个人技术博客
weixin_430750931 小时前
OpenMediaVault debian Linux安装配置企业私有网盘(三) 静态ip地址配置
linux·服务器·debian·nas·网络存储系统
ccino .3 小时前
【将更改从 GitHub Desktop 推送到 GitHub】
github
lpfasd1233 小时前
PyGithub用法详解
git·python·github
大房身镇、王师傅3 小时前
【VirtualBox】VirtualBox 7.1.6 RockyLinux10 配置增强功能 设置共享目录
运维·服务器·virtualbox·rockylinux10
betazhou3 小时前
rsync使用案例分析
linux·运维·服务器·rsync·同步数据
SmartBrain4 小时前
Agent 知识总结
服务器·数据库·笔记
QQ__17646198244 小时前
为Windows系统安装Codex(保姆级教程)
服务器·大模型·codex
mediocrep5 小时前
我的Hexo博客搭好了10 - 怎么插入图片和视频
hexo·博客搭建·github pages·个人技术博客
沉淀の沙5 小时前
1-20[IDEA远程链接GitHub失效问题]
github