基于Hexo自建一个github托管的静态网页


基于Hexo自建一个github托管的静态网页

建立github密钥

git config --global user.name wolfvoid
git config --global user.email 1055320990@qq.com
三个回车,根据提示内容找到密钥储存地址,复制密钥在github上的ssh部分添加
ssh git@github.com

经历如下过程,出现如下结果

y@LAPTOP-S8GDLRKI MINGW64 ~/Desktop
$ ssh git@github.com
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ED25519 key fingerprint is 密码.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
PTY allocation request failed on channel 0
Hi wolfvoid! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

y@LAPTOP-S8GDLRKI MINGW64 ~/Desktop
$ ssh git@github.com
PTY allocation request failed on channel 0
Hi wolfvoid! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

第二次表示匹配成功

确保node和npm已安装

安装Hexo

命令行如下

npm install -g hexo-cli 
hexo init My_blog
cd My_blog
hexo new test_my_site
hexo g
hexo s

接下来在本地localhost:4000可见初始网页

Hexo常用命令

npm install hexo -g #安装Hexo
npm update hexo -g #升级
hexo init #初始化博客

命令简写
hexo n "我的博客" == hexo new "我的博客" #新建文章
hexo g == hexo generate #生成
hexo s == hexo server #启动服务预览
hexo d == hexo deploy #部署

hexo server #Hexo会监视文件变动并自动更新,无须重启服务器
hexo server -s #静态模式
hexo server -p 5000 #更改端口
hexo server -i 192.168.1.1 #自定义 IP
hexo clean #清除缓存,若是网页正常情况下可以忽略这条命令

推送网站

blog根目录里的_config.yml文件称为站点配置文件

themes文件夹,里面也有个_config.yml文件,这个称为主题配置文件

打开站点的配置文件_config.yml,翻到最后修改为:

deploy:
  type: git
  repo: https://github.com/wolfvoid/wolfvoid.github.io.git
  branch: master

这里应该是有问题的,后面会修改

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

报错如下

(base) PS E:\My_blog\My_blog> npm install hexo-deployer-git --save
npm ERR! Cannot read properties of null (reading 'matches')

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\y\AppData\Local\npm-cache\_logs\2023-08-24T17_51_02_435Z-debug-0.log

原因:我的node版本太高了,反正就是不符合要求

补救方法:安装适合版本的node。为了方便管理,直接安装nvm

安装nvm

https://www.rstk.cn/news/1475977.html?action=onClick

注意在E:\nvm\nvm\settings.txt中替换镜像源为

node_mirror:https://npm.taobao.org/mirrors/node/
npm_mirror:https://npm.taobao.org/mirrors/npm/

注意路径为

image-20230825151837550

出现安装nvm后node和npm无法正常显示的问题

https://blog.csdn.net/taylorzun/article/details/105471841

★基本搭建结束符★

至此网站基本的工作完成了,主题为landscape,太low了,我想要更换主题

闪烁之狐主题

hexo-theme-matery的示例网站:http://blinkfox.com/

介绍网站https://zhuanlan.zhihu.com/p/35668237

★详见“闪烁之狐”主题的README

根据该README文件完成了新建所有页的操作

并完成了插件构建

解决更换主题后无法显示的问题

hexo更换主题后出现问题:WARN No layout: index.html

https://blog.csdn.net/weixin_44460555/article/details/111866191

主要来说就是下载的包名字是hexo-theme-matery-master,而设置里面是用的hexo-theme-matery,它找不到了。把它对应起来就好了。

解决无法连接github的问题

解决无法连接github的 Connection was reset问题

fatal: unable to access 'https://github.com/wolfvoid/wolfvoid.github.io.git/': Recv failure: Connection was reset
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Error: Spawn failed
    at ChildProcess.<anonymous> (E:\My_blog\blog\node_modules\hexo-util\lib\spawn.js:51:21)
    at ChildProcess.emit (node:events:390:28)
    at ChildProcess.cp.emit (E:\My_blog\blog\node_modules\cross-spawn\lib\enoent.js:34:29)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)

解决方法:

_config.yml文件修改为

deploy:
  type: git
  repo: git@github.com:wolfvoid/wolfvoid.github.io.git
  branch: master

如何向github仓库上传文件

(使用github作为图床)

git init #把这个文件夹变成git
git status #查看文件夹里的文件的情况
git add xxxx #添加东西
git commit -m '我提交了xxx' #注释
建立github密钥联系
建立GitHub上的仓库
git remote add origin git@github.com:wolfvoid/pictures.git
#若初次上传
git push -u origin master
若已经有过东西
git pull --rebase origin master
git push origin master

使用上述方法出错如下

$ git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'github.com:wolfvoid/pictures.git'

错误原因是git上的master和github上的main不符合(有病吧)

https://blog.csdn.net/gongdamrgao/article/details/115032436?spm=1001.2014.3001.5502

操作流程:

git clone git@github.com:wolfvoid/pictures.git #先把远程仓库扒下来
git add xxxx #添加东西
git commit -m '我提交了xxx' #注释
git push origin main

这样应该就没问题了


文章作者: wolf void
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 wolf void !
  目录