Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Jekyll for github PROJECT pages

I am at my wits end here. I've been trying to look at all other example github project pages I could find and even the blogs but none exhibit the problems I am getting. First, I am trying to create a project page for my repo. I did this by following the usual tutorials, creating a gh-pages branch in my project repo and pushing.

I managed to do these and template my files. I even managed to use HAML and SASS(they still both get converted to html/css and that's what I push to the repo so no problem there). I just think that I am configuring my jekyll wrong. First, I don't see any configurations in other people's pages that use baseurl or url on config.yml.

The problem with mine is when looping through my posts:

{% for post in site.posts %}
  <a href="{{ post.url }}">{{ post.title }}</a>
{% endfor %}

It always generates the href as href="/post-title"

my _config.yml btw only has this:

permalink: /exercises/:title

The problem with this when I click the link, it always points to http://corroded.github.com/exercises/title-here when it should actually be http://corroded.github.com/projectname/exercises/title-here

I have actually tried hard coding the path by doing:

<a href="http://corroded.github.com{{ post.url }}"> and this works. It goes to the post BUT it shows it as plain text and not as the generated html. I know I am missing something very simple here but I can't seem to find it and I've been wrestling with this the whole weekend.

Oh and I forgot to add: doing this in my localhost, I can access everything at:

http://localhost:4000/ and clicking on links will get me to http://localhost:4000/exercises/title-here and IT WORKS. So I have a pretty good guess that it has something to do with the configuration.

like image 786
corroded Avatar asked May 14 '12 15:05

corroded


People also ask

How does Jekyll work with GitHub Pages?

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.

Does GitHub Pages have to use Jekyll?

Prerequisites. Before you can use Jekyll to create a GitHub Pages site, you must install Jekyll and Git.


1 Answers

EDIT: This answer has been added to the Jekyll documentation at http://jekyllrb.com/docs/github-pages/.


I finally figured out the trick, if you're looking for a solution with the standard URL for GitHub Pages (username.github.io/project-name/). Here's what to do:

In _config.yml, set the baseurl option to /project-name -- note the leading slash and the absence of a trailing slash.

Now you'll need to change the way you do links in your templates and posts, in the following two ways:

When referencing JS or CSS files, do it like this: {{ site.baseurl }}/path/to/css.css -- note the slash immediately following the variable (just before "path").

When doing permalinks or internal links, do it like this: {{ site.baseurl }}{{ post.url }} -- note that there is no slash between the two variables.

Finally, if you'd like to preview your site before committing/deploying using jekyll serve, be sure to pass an empty string to the --baseurl option, so that you can view everything at localhost:4000 normally (without /project-name getting in there to muck everything up): jekyll serve --baseurl ''

This way you can preview your site locally from the site root on localhost, but when GitHub generates your pages from the gh-pages branch all the URLs will start with /project-name and resolve properly.

More conversation about this problem on issue #332.

like image 72
mjswensen Avatar answered Nov 04 '22 09:11

mjswensen