本站搭建记录

备忘录

本文最后更新于 <span id="expire-date"></span> 天前,文中部分描述可能已经过时。

踩坑、踩坑、踩坑… 😕

前期操作

mkdir py.loafing
hexo init py.loafing
cd py.loafing
npm install
hexo clean&&hexo g&&hexo s

安装主题使用

git clone https://xxx.xxx.git themes/xxx

以子模块方式安装主题时 Vercel 构建遇到问题。

git remote add origin git@github.com:forliuyifei/py.loafing.git

git status

On branch master

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
_config.yml
package-lock.json
package.json
scaffolds/
source/
themes/

git add .

warning: adding embedded git repository: themes/aomori
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> themes/aomori
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached themes/aomori
hint:
hint: See "git help submodule" for more information.
warning: adding embedded git repository: themes/cards
warning: adding embedded git repository: themes/minima


git rm --cached themes/aomori

error: the following file has staged content different from both the
file and the HEAD:
themes/aomori
(use -f to force removal)

git rm --cached themes/aomori -f
git rm --cached themes/cards -f
git rm --cached themes/minima -f

git push 提交至 GitHub 仓库,依然不能包含这几个主题文件夹。

再试试 git submodule 的方式安装主题

git submodule add https://github.com/ChrAlpha/hexo-theme-cards.git themes/cards

提交至 GitHub 仓库

告辞!老老实实用下载 zip 包解压至本地的方式安装 hexo 主题。
vercel 使用 git 子模块有点麻烦。


心血来潮想看看别的静态页面托管服务效果如何。

Gitlab pages

注册、登录 Gitlab,用户名 loafing,新建一个 私人 Project,命名为 loafing.gitlab.io

hexo 站点文件夹中新建 .gitlab-ci.yml 文件:

image: node:10-alpine # use nodejs v10 LTS
cache:
paths:
- node_modules/

before_script:
- npm install hexo-cli -g
- npm install

pages:
script:
- hexo generate
artifacts:
paths:
- public
only:
- master

ssh 配置

生成密钥

ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitlab -C "xxx@qq.com"

进入 .ssh 文件夹,打开 config,新增:

# gitlab
Host *gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.gitlab

打开Gitlab 新增 ssh key
将 .ssh 目录下的 id_rsa.gitlab.pub 里面复制粘贴过去,过期时间随意。

ssh -T git@gitlab.com

按要求输入 yes
显示 Welcome to GitLab, @loafing! 即表明验证成功

添加远程仓库

git remote add gitlab git@gitlab.com:loafing/loafing.gitlab.io.git

git remote -v 可以看见新增的仓库地址

一键三连提交至 Gitlab

git add .&&git commit -m " push to gitlab! "&&git push gitlab master

提交成功后,需要等待一会儿,让 Gitlab 自动生成静态博客页面(检查仓库侧栏的 CI / CD 是否正常工作)

打开 loafing.gitlab.io 试试能不能正常载入。

如果遇到页面可见性问题,在仓库的 Setting-General-Visibility 将 Page 项设置为 Everyone


如果嫌麻烦不想每次 push 两次,可以试试以下方法:

打开 .git/config 找到 [remote "origin"] ,添加对应的 url

[remote "origin"]
url = git@github.com:xxx/xxx.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@gitlab.com:loafing/loafing.gitlab.io.git

以后只要一条 git push origin master 就能同时提交推送至至 GitHub 和 Gitlab。(git pull 或者 git fetch 只从 GitHub拉取)


参考: