Ubuntu 20.04+Hexo搭建个人主页(含gitee镜像网站)

Ubuntu20.04本地配置

安装Git

sudo apt-get install git-core

安装node.js和npm

sudo apt-get install nodejs
sudo apt-get npm

创建一个目录

cd ~/Documents
sudo mkdir hexo
cd hexo

之后就在这个目录中工作

搭建hexo

sudo hexo init

更改镜像源并下载

为了加快npm下载的速度

sudo npm config set registry http://registry.npm.taobao.org
sudo npm install -g hexo-cli
sudo npm install hexo-generator-index --save
sudo npm install hexo-generator-archive --save
sudo npm install hexo-generator-category --save
sudo npm install hexo-generator-tag --save
sudo npm install hexo-server --save
sudo npm install hexo-deployer-git --save
sudo npm install hexo-deployer-heroku --save
sudo npm install hexo-deployer-rsync --save
sudo npm install hexo-deployer-openshift --save
sudo npm install hexo-renderer-marked --save
sudo npm install hexo-renderer-stylus --save
sudo npm install hexo-generator-feed --save
sudo npm install hexo-generator-sitemap --save
sudo npm install hexo-admin --save 

下载已有的hexo主题

e.g.: 我使用的是butterfly主题,在/hexo根目录下执行以下命令,就可以在/source下看到butterfly

git clone jerryc127/hexo-theme-butterfly themes/Butterfly

更多主题详见Hexo Themes
/hexo/_config.yml将主题改为butterfly

...
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: butterfly
...

输入hexo s,进入localhost:4000查看效果

(附:hexo常用命令)

hexo clean
//清空缓存
hexo generate 
hexo g //简写
//重新编译
hexo server
hexo s //简写
//打开本地访问
hexo new <layout> "文章title"
hexo n "文章title"
//新建文章
hexo deploy
hexo d //简写

部署到git

配置GitHub账号

首先注册Github账号,点击New repository创建仓库,Repository name填自己的用户名username.github.io
在根目录下输入以下命令:

git config --global user.name "username"
git config --global user.email "username@example.com" //注册GitHub时使用的主邮箱
ssh-keygen -t rsa -C "username@example.com"

密钥保存到id_rsa.pub,使用gedit打开其中内容并复制
接着在GitHub中找到settings,选择SSH and GPG keys->New SSH key
随便起个名字,然后粘贴密钥
测试sshkey是否添加成功

ssh -T git@github.com

出现以下内容即成功

Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

修改deploy选项

修改/hexo/_config.yml

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
  type: git
  repo: 
    github: git@github.com:username/username.github.io.git
  branch: master

在根目录中deploy

hexo cl && hexo g && hexo d

即可在https://username.github.io查看效果

搭建gitee镜像网站(以防github突然崩掉)

配置gitee账号

首先注册Gitee账号,点击New repository创建仓库,Repository name填自己的用户名
注意,这里不要填gitee.io,否则后面生成的网页地址会不好看

修改deploy选项

修改/hexo/_config.yml

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
  type: git
  repo: 
    github: git@github.com:username/username.github.io.git
    gitee: https://gitee.com/username/username.git
  branch: master

重新hexo d一下,会提示输入Username for 'https://gitee.com'Password for 'https://username@gitee.com',依次输入即可

deploy Gitee

进入gitee中新建的那个repository,选择Services->Gitee Pages开始生成页面
(注:首次使用Pages需要使用身份证注册)
branch选择master,勾选Enforce HTTPS,点击部署即可
部署完毕后可在https://username.gitee.io查看效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值