2016-09-23 80 views
1

我在GitHub頁面上託管我的網站,因此我在我的URL中使用了site.github.url(如文檔中所述)。就像這樣:與在本地運行jekyll網站的路徑混淆

<a href="{{ page.url | prepend: site.github.url }}">{{ page.title }}</a> 

在文檔中,也說

這種方式,你可以從網站根局部預覽你的網站在本地主機上,但在GitHub上產生從GH-頁面分支頁面所有的網址都能正確解析。

現在我嘗試在本地預覽它,但所有鏈接都在其前面有http://my-username.github.io/

我在做什麼錯?也許我錯過了什麼?

回答

1

在本地,您可以使用_config_local.yml覆蓋默認的URL值。

_config_local.yml補充一點:

github: 
    url: http://localhost:4000 

然後你就可以啓動化身,並要求解析這兩個配置文件是這樣的:

bundle exec jekyll build --config _config.yml, _config_local.yml 

bundle exec jekyll serve --config _config.yml,_config_local.yml 

可選:您可以使用該命令的別名或使用rake來啓動任務。

rake寶石添加到您的Gemfile

group :development do 
    gem 'rake' 
end 

安裝與bundle install

創建Rakefile:在

touch Rakefile

拷貝內容您Rakefile

require 'jekyll' 

task :build do 

options = { 
    'trace'  => true, 
    'verbose'  => true, 
    'config' => %w(_config.yml _config_local.yml) 
} 
Jekyll::Commands::Build.process(options) 
end 

task :serve do 
options = { 
    'serving'  => true, 
    'watch'  => true, 
    'incremental' => true, 
    'config'  => %w(_config.yml _config_local.yml) 
} 
Jekyll::Commands::Build.process(options) 
Jekyll::Commands::Serve.process(options) 
end 

現在您可以使用bundle exec rake buildbundle exec rake serve而不必通過選項。

+0

It works :)非常感謝! –