与本地路径 运行 jekyll 网站混淆

Confused with paths running jekyll website locally

我在 GitHub 页面上托管我的网站,因此我在 URL 页面中使用了 site.github.url(如文档中所述)。像这样:

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

在文档中也说

This way you can preview your site locally from the site root on localhost, but when GitHub generates your pages from the gh-pages branch all the URLs will resolve properly.

现在我尝试在本地预览,但是所有的链接前面都有http://my-username.github.io/

我做错了什么?也许我遗漏了什么?

您可以在本地使用 _config_local.yml 覆盖默认 URL 值。

将此添加到您的 _config_local.yml 中:

github:
  url: http://localhost:4000

然后您可以启动 Jekyll 并要求像这样解析两个配置文件:

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

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

可选:您可以为命令添加别名或使用 rake 启动任务。

rake gem 添加到您的 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 而无需传递选项。