mbigras mbigras - 1 year ago 91
Git Question

How to avoid having to change site.baseurl -> site.github.url between master/gh-pages?

I'm using github to host my blog built with jekyll.

I read in another post and the documentation that I need to change

to get my static resources to be served. So that's what I did and now everything is working. See diff below between

enter image description here

It wasn't too much of a pain to do, I just project-wide replaced using atom; however, I'm wondering, is there a better workaround? Ideally I'd like my workflow to be so I can just work on my blog using a normal branching model and then merge with
as if it's a release branch and not have to worry about making the search and replace every time.

Thanks for your help :)

Edit: So strange, I just merged
and it seems like git just automagically handled the whole thing for me. So different question. Does git really know not to change
when I make the merge? How does that work?

Answer Source

You can do this by using jekyll.environment:

{% if jekyll.environment == "production" %}
  <a class="post-link" href="{{ post.url | prepend: site.github.url }}">{{ post.title }}</a>
{% else %}
  <a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
{% endif %}

In your build command you then have to set JEKYLL_ENV=production . This is done automatically by GitHub. For other platforms, you may have to do this manually (in a Rakefile for example):

JEKYLL_ENV=production jekyll build

By default, JEKYLL_ENV equals development.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download