Windows 版本: 10.0
Ruby 版本: 2.5.1
Gem 版本: 2.7.6
Jekyll 版本: 3.8.3
Bundle 版本: 1.16.2
Powershell 版本: 5.1
Code Page: In computing, a code page is a table of values that describes the character set used for encoding a particular set of characters, usually combined with a number of control characters.
從Wiki的描述來看,Code Page相當於字符編碼集合構成的頁表。
那麼,在Win10系統中安裝Jekyll容易出現Code Page的錯誤,亦即不同的字符集編碼不兼容。
錯誤表現:
運行:bundle exec jekyll serve
報錯:
Conversion error: JekyllConverters::Scss encountered an error while converting 'assets/css/main.scss':
Invalid GBK character "xE2" on line 54
查看當前系統的Code Page方法有兩種:
- 打開Powershell,運行
chcp,顯式Active code page: 65001,即Code Page為65001 (UTF-8),此時Jekyll可以正常運行; - 打開Powershell,右鍵上部標題欄,左鍵點擊“屬性” --> 點擊“選項”, 在選項頁面查看當前代碼頁;
若查看到的Code Page為:936 (GBK),則會與Jekyll出現字符集不兼容的問題。
修改當前系統的Code Page方法:
- 非長久方法:直接在Powershell中運行
chcp 65001,但是退出Powershell之後,將恢復默認的Code Page,故而每次在運行bundle exec jekyll serve命令時候,都需要進行chcp 65001; -
長久方法:修改Powershell配置文件。
- 運行:
Get-ExecutionPolicy獲取當前Powershell執行策略等級; - 若等級為Restricted或AllSigned,運行
Set-ExecutionPolicy RemoteSigned修改策略等級為RemoteSigned - 創建Powershell啓動加載的腳本。
New-Item -Path $Profile -ItemType file -Force - 打開創建的腳本文件,將
chcp 65001命令寫入,然後保存退出文件; - 重啓Powershell,此後Powershell每次啓動即會運行
chcp 65001; - 若不想每次啓動Powershell顯式"Active code page: 65001",可改寫命令為
chcp 65001 >$null,將輸出丟棄;
- 運行:
以上的解決方案,主要參考setup-jekyll-on-windows