GitLab Pages 搭建Hexo教程

??Home:https://www.dnocm.com/articles/gitlab-pages-for-hexo

大部分情況下,都是github pages與hexo組合搭建靜態(tài)博客。但不可否認(rèn)的是,這樣存在一些問題。比如,每次文章寫完都需要要編譯,才能上傳,如果我僅僅想寫個(gè)博客,這樣的操作顯得繁瑣。又比如,你擁有多臺(tái)電腦的情況,你需要在每臺(tái)電腦上都配置一樣的環(huán)境。

所以通過持續(xù)集成CI/CD的方式,讓編譯自動(dòng)化,是一種很不錯(cuò)的解決方案。這里將介紹gitlab-ci來(lái)簡(jiǎn)化環(huán)境的搭建與編譯過程。當(dāng)然靜態(tài)資源將托管在gitlab-pages上。

There is also a tutorial in English

中文教程

環(huán)境搭建

  1. 點(diǎn)擊打開gitlab pages例子頁(yè)面
  2. fork其中的hexo項(xiàng)目到自己的賬戶(如果沒有需要?jiǎng)?chuàng)建一個(gè)新的gitlab賬戶)
  3. 刪除fork關(guān)系(點(diǎn)擊項(xiàng)目左側(cè)的settings->General,然后展開Advanced settings,刪除fork關(guān)系)
  4. 可選:修改項(xiàng)目信息,如Project name、Project description、Path等。這里建議Path和Project name一同修改。gitlab pages地址規(guī)則與github是一致的
  5. 可選:建議修改.gitlab-ci.yml中node版本為6.11.2
  6. 修改任意一文件,如readme.md或者source/_posts下的文章

當(dāng)你完成這些步驟,你可以點(diǎn)擊右側(cè)的CI/CD,可以看到如下畫面:

當(dāng)然你看到的可能是pending或running,這時(shí)請(qǐng)耐心等待。當(dāng)顯示為passed時(shí),在瀏覽器中輸入托管地址https://your-name.gitlab.io/projext-name,能訪問,就意味著搭建成功咯

修改主題

這個(gè)項(xiàng)目結(jié)構(gòu)是標(biāo)準(zhǔn)的hexo的項(xiàng)目,除了多個(gè)一個(gè).gitlab-ci.yml,如下圖

我們僅需關(guān)心script部分即可,而這部分其實(shí)是標(biāo)準(zhǔn)的hexo命令。

如果你想使用next主題(最受歡迎的hexo主題),http://theme-next.iissnan.com官網(wǎng)的網(wǎng)站上已有詳細(xì)的教程

English

Get Started

  1. Click example projects for gitlab pages
  2. Fork the project of hexo to your account(If you do not have any gitlab account, you can create a new)
  3. Remove fork relationship(Choose settings->General from the list on the left.And expand Advanced settings to remove fork relationship)
  4. Optional: modify project info,such as Project name, Project description, Path etc. Here's a suggestion about that path and Project name modify together. your website will be available at https://username.gitlab.io/projectname, it is familiar with gitlab pages.
  5. Optional: suggested modify the node's version from .gitlab-ci.yml to 6.11.2
  6. Modify any file, such as readme.md or the article under source/_posts
  7. Choose CI/CD, waiting job completion
  8. Click https://your-name.gitlab.io/projext-name

Advanced

  • you can modify script in .gitlab-ci.yml.
  • you can change the theme to next, which is most popular theme of hexo, by a official tutorial http://theme-next.iissnan.com

Updated

Command Lines

Use command lines to init a blog with gilab page, written in 2018.9.19

Init hexo project

hexo init your-blog-dir
cd your-blog-dir
hexo s

Hexo is running at http://localhost:4000, you can test it.

Git remote

Assert your project remote url is https://gitlab.com/your-gitlab-name/project-name.

git init
git remote add origin git@gitlab.com:<your-gitlab-name>/<project-name>.git
git add .
git commit -m "Initial commit"
git push -u origin master

Add CI config

Please rename <*-name> to real name, such as sed -ri 's/.*(url:.*)/url: https:\/\/jiangtj.gitlab.io/g' _config.yml

wget -O .gitlab-ci.yml https://gitlab.com/JiangTJ/hexo/raw/master/.gitlab-ci.yml?inline=false
sed -ri 's/.*(url:.*)/url: https:\/\/<your-gitlab-name>.gitlab.io/g' _config.yml

If project-name is not your-gitlab-name.gitlab.io, update root var.

sed -ri 's/.*(root:.*)/root: \/<project-name>\//g' _config.yml

Push to remote

git add .
git commit -m "CI"
git push -u origin master

Wait pipeline finish running, your hexo blog is running at https://your-gitlab-name.gitlab.io/project-name.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容