XML file is showing link as localhost

<link href="http://localhost:4000/blog/feed.xml" rel="self" type="application/atom+xml"/>
<link href="http://localhost:4000/blog/" rel="alternate" type="text/html"/>

This is showing in my XML file.
How to fix it.

probably jekyll is prepending that for you to make local dev easier - when doing jekyll serve it does that (I think to site.url?) as it assumes you are doing development . If you do jekyll build which normally you would do when deploying I don’t think it will do that.

more info:

1 Like

Can I use this Jekyll build --watch in the command prompt while developing the website.
Should I use at the time of deploying the website on server.

did you try it like that? I think it won’t have its own server if you don’t use jekyll serve.

Why not make sure it is correct once by using build, and then use serve when you doing development and build when you deploy?

Lots of different ways to do it, I use a Gulp task rather than the jekyll commands.

Well, we can use Jekyll serve and then Jekyll build.

But why to write code twice. Should be a simpler way?

I would just use serve when doing dev work, and then use build when you go to deploy it.

Just remember that when doing serve it is swapping in local host instead of the actual site settings.

I find it much better to use a Gulp file, this gives you auto-reload so the browser refreshes whenever you save a file, even works with config file changes. It is a little more complex to get setup, but once it works it just works.

Here is info on how I do it:

It does get a little complicated if you are using GH for hosting a project, as then you need the baseurl which can mess with your urls locally. To fix that I use a second config file that is only used on local dev to override the baseurl setting (this is basically what jekyll serve is doing as of 3.3). You can see a project with a gulp file and a second config file here:

Could you please elaborate on that? Where does the swapping happen and what are the side-effects (if any)?


As @rdyar stated above, running jekyll serve spins up a development server for local testing. Jekyll automatically overwrites url set in your _config.yml with localhost:4000 when doing this. Versus jekyll build which doesn’t mess with any of that.

It’s a good practice to run jekyll build when you want to prepare your files for production and deployment. You may have to use environment variables as well depending on the plugins being used.

Jekyll’s default is to set it at JEKYLL_ENV=development and can cause things like analytics and Disqus comments to be omitted. I know a few themes (like the default Minima) do things like this to only show comments when in production.

{% if page.comments != false and jekyll.environment == "production" %}
 ... stuff ...
{% endif %}

Appreciate your prompt and detailed response!

Now I see what this is all about and I should definitely educate myself on these nitty-gritty internal details of Jekyll. :slight_smile: