欢迎光临散文网 会员登陆 & 注册

细致讲解如何用hexo+github配置一个可以建在分目录下的个人博客(2023版)

2023-01-23 12:26 作者:蜉蝣_Adonis  | 我要投稿

提示:本文所有使用到的软件均已放置在网盘中,可以直接下载

1.下载并安装Node.js git

Node.js安装地址:https://nodejs.org/zh-cn/

Windows系统下的安装地址:https://git-scm.com/download/windows

macOS系统下的安装地址:https://git-scm.com/download/mac

(macOS系统会自带git,版本低一点但也够用了)

在cmd/终端中进行指令输入

node -v来检测Node.js是否安装成功

返回:

`v18.13.0`

git --version来检测git是否安装成功

返回:

`git version 2.37.1 (Apple Git-137.1)`

2.生成SSH密钥

输入指令

ssh-keygen -t rsa -C "user@email.com"(这里换成你注册github的邮箱)

返回:

`` Generating public/private rsa key pair.

`` Enter file in which to save the key (/Users/Adonis142857/.ssh/id_rsa): 

`` Created directory '/Users/Adonis142857/.ssh'.

接下来的passphrase可以直接留空

`` Enter passphrase (empty for no passphrase): 

`` Enter same passphrase again: 

`` Your identification has been saved in /Users/Adonis142857/.ssh/id_rsa

`` Your public key has been saved in /Users/Adonis142857/.ssh/id_rsa.pub

`` The key fingerprint is:

打开上方目录中生成的文件'id_rsa.pub'

Ctrl+a/⌘+a进行全文选中

Ctrl+c/⌘+c进行全文拷贝

3.进入github.com并登录

点击右上角人物头像
点击Settings
点击SSH and GPG keys
点击New SSH Key
在Title中输入你的github用户名,Key中输入刚才在id_rsa.pub中复制到的字符串

4.安装hexo

依赖安装慢点可以使用镜像

指令如下

清空代理

npm config set proxy null

清理缓存

npm cache clean --force

重新设置镜像源

npm config set registry https://registry.npm.taobao.org

用指令cd进入要安装hexo的目录

例:

cd  /Users/Adonis142857/Documents/website/blog

使用指令

sudo npm install hexo-cli -g

安装完后使用指令

hexo init blog

安装完后进入目录 

cd blog

使用指令安装依赖

npm install

安装完后可以使用指令

hexo s 

在本地页面上查看效果

在浏览器中进入地址localhost:4000即可查看博客界面

5.创建用于储存博客的储存库

进入网站github.com

点击New

在其中配置Repository name

这里分两种

(1)希望在username.github.io打开自己博客

那么就在Repository name中填写username.github.io(要换成自己的github用户名)

例:

希望在Adonis142857.github.io打开自己博客

那么就在Repository name中填写Adonis142857.github.io

(2)希望在username.github.io/Repository name中打开自己博客(即建在分目录的博客)

那么就在Repository name中填写自己想要建的分目录名称

例:

希望在Adonis142857.github.io/blog中打开自己博客

那么就在Repository name中填写blog

配置完后点击Create repository


6.将hexo界面发布到github上

打开blog文件夹下的_config.yml文件

改三个地方

肯定要把作者改成自己了(

改动url:

(1)希望在username.github.io打开自己博客

那么就改成url: https://username.github.io

例:

url: https://Adonis142857.github.io

(2)希望在username.github.io/Repository name中打开自己博客(即建在分目录的博客)

那么就改成url: https://username.github.io/Repository name

例:

url: https://Adonis142857.github.io/blog

这里type和branch按照图片进行填写就可以

repo还是要分两种情况进行改动

(1)希望在username.github.io打开自己博客

那么就改成repo: git@github.com:username/username.github.io.git

例:

repo: git@github.com:Adonis142857/Adonis142857.github.io.git

(2)希望在username.github.io/Repository name中打开自己博客(即建在分目录的博客)

那么就改成repo: git@github.com:username/Repository name.git

例:

repo: git@github.com:Adonis142857/blog.git

修改完成后用Ctrl+s/⌘+s进行保存

使用指令安装插件

npm install hexo-deployer-git --save

使用指令配置git的邮箱和用户名

git config --global user.email "user@email.com"

git config --global user.name "username"

(都要改成自己的邮箱和用户名哦)

接下来输入三个指令

hexo clean

hexo generate

hexo deploy

然后你的博客就已经被成功推送到github上了

可以去看看哦

细致讲解如何用hexo+github配置一个可以建在分目录下的个人博客(2023版)的评论 (共 条)

分享到微博请遵守国家法律