Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I easily manage different base URL of Jekyll webpage on localhost and remote server?

Tags:

jekyll

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?

like image 519
Tomáš Zato - Reinstate Monica Avatar asked May 05 '16 11:05

Tomáš Zato - Reinstate Monica


People also ask

What is the URL of Jekyll?

They all start with http://localhost:4000 or http://127.0.0.1:4000 . This happens because in older versions of Jekyll (v3. 3 through 4.1) it would reset site. url to localhost:4000 when JEKYLL_ENV=development (the default environment value), overriding whatever is set in the _config.

What is base URL in GitHub?

yml”. When hosting on GitHub Pages, baseurl will be the name of your project repository. baseurl: /example-collection. If self hosting, the baseurl will be the folder where you would like to host the site (if applicable).

How to preview Jekyll site?

To preview your site, in your web browser, navigate to http://localhost:4000 .

What is Jekyll GitHub?

Jekyll is a static site generator with built-in support for GitHub Pages and a simplified build process. Jekyll takes Markdown and HTML files and creates a complete static website based on your choice of layouts. Jekyll supports Markdown and Liquid, a templating language that loads dynamic content on your site.


1 Answers

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.

like image 149
Tomáš Zato - Reinstate Monica Avatar answered Nov 11 '22 11:11

Tomáš Zato - Reinstate Monica