5

On my computer, I access my test webpage on URL http://127.0.0.1:4000. On server, it will be on GitHub pages, that means https://username.github.io/repo-name/.

In the _config.yml I see following relevant settings:

# Uncomment if you are planning to run the blog in a subdirectory
# Note - if you enable this, and attempt to view your site locally you have to use the baseurl in your local path.
# Example, you must use http://localhost:4000/path/to/blog
#baseurl: /path/to/blog 
baseurl: 

# The URL of your actual domain. This will be used to make absolute links in the RSS feed.
url: http://yourdomain.com/

So for GitHub server I need it to be:

baseurl: /repo-name/
url: https://username.github.io/

But on localhost, it must be:

baseurl: 
url: http://127.0.0.1:4000

These settings are necessary because without them, I will get 404 errors for resources that are using relative paths:

<script src="js/ghapi.js"></script>

"NetworkError: 404 Not Found - http://127.0.0.1:4000/download/js/ghapi.js"

The path should be http://127.0.0.1:4000/js/ghapi.js but since the page was /download it was added to relative URL of the script file.

I need to deal with this issue, how do I do that?

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • Would be another config.yml for the local development defined as a serve parameter a solution for you? There is a [similar question](http://stackoverflow.com/a/20587233/1456318) on SO. – michaPau May 05 '16 at 12:43
  • 1
    Possible duplicate of [Change site.url to localhost during jekyll local development](http://stackoverflow.com/questions/27386169/change-site-url-to-localhost-during-jekyll-local-development) – David Jacquel May 05 '16 at 13:30

3 Answers3

12

The best solution was to have two config files. The additional one, debug.yml, overrides some settings from the basic one. Both setting files can be loaded using this command:

jekyll serve --config _config.yml,debug.yml

The debug file can contain:

name: MySite [DEBUG MODE]
debug: true
url: http://127.0.0.1:4000

The advantage here is that no setting files need to be changed, you just use different command to run jekyll.

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
1

For me the best option is having in config.yml the baseurl used in Github pages and when you launch your site locally, override this value with an empty one:

bundle exec jekyll serve --baseurl=

That way, the site will work on localhost and in ghpages.

pglez82
  • 489
  • 5
  • 11
0

you can add a branch and change url line in config.yml
url: http://127.0.0.1:4000

kaanosman
  • 11
  • 3