hexo自建博客的步骤

299 阅读3分钟

自建博客

先交下试卷 yu-1120.github.io/

推荐一个B站的教程

www.bilibili.com/video/BV1mU…

P1

1.视频中的文本文件

MODEJS下载地址:原地址失效了,自己上官网找最新版(●'◡'●) 安装教程:www.cnblogs.com/zhouyu2017/…

2.GIT下载:太长了,自己找官网下

教程:www.cnblogs.com/xueweisuoyo…

这篇教程的git版本太低了,建议结合下面教程一起看

乱乱的代码blog.csdn.net/m0_37802038…

node -v

npm -v

git --version

hexo下载:npm install express -g

hexo -v

小声bb:笔记的markdown好难用啊换个行都要再打一次

P2

需要自己去注册一个

github账号注册:www.bilibili.com/read/cv5107…

P3

随便点开一个有文件夹(这个无所谓主要是生成文件夹)

生成ssh:ssh-keygen -t rsa -C "邮箱地址" 邮箱是你github的邮箱地址

然后连按四个空格,会生成一个.ssh文件

image-20220730145428958

.ssh生成路径:C:\Users\你他娘的用户名.ssh

如果找不到,下个everything(一个软件)然后找

image-20220730145331593

image-20220730145320173

image-20220730145349879

测定ssh是否绑定成功:ssh -T git@github.com

image-20220730150007741

如果一直出现ssh: connect to host github.com port 22: Connection refused的话具体看这个教程

解决ssh: connect to host github.com port 22: Connection refused - Biile - 博客园 (cnblogs.com)


解决方法如下:(命令不行就直接右键新建一个文本不带后缀的)

在终端输入以下命令:
1. cd ./.ssh
2. sudo touch config
3. sudo gedit config

在config文件中写下面的信息:

1. Host github.com  
2. User xxxxx@xx.com  	//注册github的邮箱
3. Hostname ssh.github.com  
4. PreferredAuthentications publickey  
5. IdentityFile ~/.ssh/id_rsa  
6. Port 443

P4

hexo init #初始化hexo博客

如果报错SyntaxError: Unexpected token ...

建议更新一下node.js版本

hexo s #静态生成hexo页面

P5

配置文件修改(_config.yml) 初始化hexo的文件夹

deploy:

     type: git

      repository: [https://github.com/](https://github.com/)你的名字/仓库的名字.git

       branch: 分支  前面要有一个空格

这里的repository写git,不行就改成ssh的

安装hexo-deployer-git自动部署发布工具:

npm install hexo-deployer-git --save

hexo g #生成页面

hexo d #上传

Hexo部署过程中可能会出现错误

Hexo部署出现错误err: Error: Spawn failed解决方式 (icode9.com)

fatal: unable to access 'https://github.com/a956551943/a956551943.github.io/': Encountered end of file
FATAL {
  err: Error: Spawn failed
      at ChildProcess.<anonymous> (/usr/local/src/hexo/hanyubolg/node_modules/hexo-util/lib/spawn.js:51:21)
      at ChildProcess.emit (events.js:376:20)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
    code: 128
  }
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html

解决方法一

##进入站点根目录,你自己用hexo建的那个文件夹
cd /usr/local/src/hexo/hanyubolg/

##删除git提交内容文件夹
rm -rf .deploy_git/

##执行
git config --global core.autocrlf false

##最后
hexo clean && hexo g && hexo d

解决方式二:有可能是你的git repo配置地址不正确,可以将http方式变更为ssh方式

##进入站点根目录
cd /usr/local/src/hexo/hanyubolg/

##删除git提交内容文件夹
vim _config.yml

##修改
deploy:

type: git

repo: https://github.com/yourname/yourname.github.io.git -> git@github.com:a956551943/weixiaohui.github.io.git

branch: master

##最后
hexo clean && hexo g && hexo d

Hexo

Install Hexo

 npm install hexo-cli -g

Setup your blog

hexo init blog
cd blog

Start the server

 hexo server

Create a new post

 hexo new "Hello Hexo"

Generate static files

 hexo generate
hexo clean & hexo generate &  hexo deploy
hexo c & hexo g &  hexo d

Openblock-Gui 安装失败 npm ERR! Cannot read properties of null (reading 'pickAlgorithm') 解决方案

解决方案

​
执行命令行   npm cache clear --force  
执行        npm install  
执行        npm start
​

查看全局安装过的包命令:

npm list -g --depth 0
npm install -g yarn
yarn install

安装hexo-deployer-git自动部署发布工具:

npm install hexo-deployer-git --save
deploy:
  type: git

  repository: git@github.com:Yu-1120/Yu-1120.github.io.git

  branch: main

hexo同时部署到GitHub和gitee

站点配置文件修改

  • 主要添加gitee和github的http链接、SSH链接到配置文件中即可。

  • 重新执行,配置完后第一次执行hexo d会提示输入gitee的账户密码,填写即可,第二次就不需要填写了。

hexo clean && hexo g && hexo d