Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #7253: "Don't reset site.url to localhost:4000 by default" #8620

Merged
merged 8 commits into from
Sep 15, 2021
11 changes: 10 additions & 1 deletion docs/_docs/step-by-step/01-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,16 @@ called `_site`.
* `jekyll serve` - Does `jekyll build` and runs it on a local web server at `http://localhost:4000`, rebuilding the site any time you make a change.

{: .note .info}
When you're developing a site, use `jekyll serve`. To force the browser to refresh with every change, use `jekyll serve --livereload`.
When you're developing a site, use `jekyll serve`. To force the browser to refresh with every change, use `jekyll serve --livereload`.
If there's a conflict or you'd like Jekyll to serve your development site at a different URL, use the `--host` and `--port` arguments,
as described in the [serve command options]({{ '/docs/configuration/options/#serve-command-options' | relative_url }}).

{: .note .warning}
The version of the site that `jekyll serve` builds in `_site` is not suited for deployment. Links and asset URLs in sites created
with `jekyll serve` will use `https://localhost:4000` or the value set with command-line configuration, instead of the values set
in [your site's configuration file]({{ '/docs/configuration/' | relative_url }}). To learn about how to build your site when it's
ready for deployment, read the [Deployment]({{ '/docs/step-by-step/10-deployment/' | relative_url }}) section of this tutorial.


Run `jekyll serve` and go to
<a href="http://localhost:4000" target="_blank" data-proofer-ignore>http://localhost:4000</a> in
Expand Down
16 changes: 15 additions & 1 deletion docs/_docs/step-by-step/10-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,21 @@ to do this is to run a production build:
JEKYLL_ENV=production bundle exec jekyll build
```

And copy the contents of `_site` to your server.
And then copy the contents of `_site` to your server.

<div class="note warning">
<h5>Destination folders are cleaned on site builds</h5>
<p>
The contents of <code>_site</code> are automatically cleaned, by default, when
the site is built. Files or folders that are not created by your site's build
process will be removed.
</p>
<p>
Some files could be retained by specifying them within the <code>keep_files</code>
configuration directive. Other files could be retained by keeping them in your
assets directory.
</p>
</div>

A better way is to automate this process using a [CI](/docs/deployment/automated/)
or [3rd party](/docs/deployment/third-party/).
Expand Down
3 changes: 0 additions & 3 deletions lib/jekyll/commands/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,6 @@ def format_url(ssl_enabled, address, port, baseurl = nil)

def default_url(opts)
config = configuration_from_options(opts)
auth = config.values_at("host", "port").join(":")
return config["url"] if auth == "127.0.0.1:4000"

format_url(
config["ssl_cert"] && config["ssl_key"],
config["host"] == "127.0.0.1" ? "localhost" : config["host"],
Expand Down
6 changes: 6 additions & 0 deletions test/test_commands_serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ def serve(opts)
expect(Jekyll).to receive(:env).and_return("development")
expect(Jekyll::Commands::Serve).to receive(:start_up_webrick)
end
should "set the site url by default to `http://localhost:4000`" do
@merc.execute(:serve, "watch" => false, "url" => "https://jekyllrb.com/")

assert_equal 1, Jekyll.sites.count
assert_equal "http://localhost:4000", Jekyll.sites.first.config["url"]
end

should "take `host`, `port` and `ssl` into consideration if set" do
@merc.execute(:serve,
Expand Down