win下jekyll調試博客不方便,還有很多錯誤。而博客每次寫完或調試完需要重複git add, git commit, git push,即使有了github desktop,一樣是很不方便。而在jekyll官網上我們知道jekyll博客支持本地調試,麻煩的是搭建環境,相比於windows,Linux下的環境搭建就方便的多了,本文就介紹怎麼用安卓手機來搭建環境本地調試博客程序。舊手機搞他,再做個代理和內網穿透,實現手機服務器搭建博客,解決百度蜘蛛摸github燙腿的問題。
這裏接上一篇,請參考舊手機建立自己的博客網站之踩坑記||在舊手機上建立自己的服務器(2)||2020年新貨
安卓裝Linux ,坑真的多,Linux deploy&Termux踩坑記||在舊手機上建立自己的服務器(1)||2020年新貨
這篇博文的前提是你已經在手機上裝好的Linux系統,這裏以ubuntu18LTS版本爲例說明:
打開jekyll安裝官網https://www.jekyll.com.cn/docs/installation/ubuntu/
根據提示進行環境配置 ,首先安裝依賴
sudo apt-get install ruby-full build-essential zlib1g-dev
最好避免將 Ruby Gem 安裝爲根用戶。因此,我們需要爲您的用戶帳戶設置 Gem 安裝目錄。以下命令將環境變量添加到文件中,以配置 Gem 安裝路徑。立即運行它們:~/.bashrc
echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc
echo 'export GEM_HOME="$HOME/gems"' >> ~/.bashrc
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
安裝 jekyll
gem install jekyll bundler
至此你已經準備好使用jekyll了 ,如果有以下 錯誤說明你的鏡像源錯誤,這時候你需要準備梯子或者修改鏡像源 。
- 更新國內鏡像源
$ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
- 查看鏡像源
gem sources -l
既然要將網站部署在Github Page上,那自然少不了使用git,可以使用如下命令安裝git:
sudo apt-get install git
在終端中輸入git –version,出現git version 1.9.1,則說明git安裝成功:
就像官網所說的簡單的只需要四步
快速開始
gem install jekyll bundler
jekyll new my-awesome-site
cd my-awesome-site
bundle install
bundle exec jekyll serve
# => 打開瀏覽器 http://localhost:4000
關於環境配置問題這裏推薦intzero大神的方式和處理,下面補充介紹在網站clone主題下來本地調試容易出現的問題。
這裏推薦使用手機的內部存儲作爲博客的存放地即sdcard(前提是你掛載了)
如果你是代碼暈的話,跟着走吧,首先在主題網站選擇好你的主題,並找到github倉庫,點擊右側下載zip文件後,解壓拷到手機的內部儲存,就是數據線連接你看到 的那個,然後在ssh客戶端連接你的Linux,輸入以下命令:
sudo apt-get install ruby-full # Debian 或 Ubuntu 系統
gem install jekyll bundler
cd /sdcard/your-site #your-site即你的博客文件夾
bundle install
bundle exec jekyll serve
最後 打開瀏覽器 http://localhost:4000
如果你遇到以上問題:首先要確保你安裝了’jekyll-paginate’,可以執行以下命令嘗試:
sudo gem install jekyll-paginate
如果已安裝,那根據ensure that you have included the jekyll-paginate gem in your Gemfile as well. 報錯來說你需要在你的 Gemfile 中添加 gem jekyll-paginate
字段如下面所示:
source "https://rubygems.org"
# Hello! This is where you manage which Jekyll version is used to run.
# When you want to use a different version, change it below, save the
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
#
# bundle exec jekyll serve
#
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
gem "jekyll", "~> 4.0.0"
# This is the default theme for new Jekyll sites. You may change this to anything you like.
gem "minima", "~> 2.5"
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
# gem "github-pages", group: :jekyll_plugins
# If you have any plugins, put them here!
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.12"
end
# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
install_if -> { RUBY_PLATFORM =~ %r!mingw|mswin|java! } do
gem "tzinfo", "~> 1.2"
gem "tzinfo-data"
end
# Performance-booster for watching directories on Windows
gem "wdm", "~> 0.1.1", :install_if => Gem.win_platform?
gem 'jekyll-paginate'
如果你遇到了下面的問題:
說明你的配置文件中沒有配置擴展文件。在_config.yml配置文件的擴展選項中添加以下字段,則分別可以支持在X86架構的ubuntu和arm64架構下本地調試。
# Plugins
plugins: [jekyll-paginate]
plugins_dir: [jekyll-paginate]
gems: [jekyll-paginate]
修改以上問題後,如果看見了以下界面,那麼恭喜你,在瀏覽器輸入http://localhost:4000/即可看到的站點。之後就可以直接在舊手機上本地調試。