I am going to post a solution that I am setting up to take advantage of the fact that GitHub Pages is already using Jekyll with an automatic page generator.
git checkout gh-pagesmkdir _layoutsmv index.html _layoutsgit checkout master -- README.mdmv README.md index.md- Prepare the following text for
index.md
You also need to open the index.html file and make the following changes:
Remove the displayed HTML from the markdown in your README.md file. This usually happens between the <section> or <article> tags. Replace this HTML with the text {{ content }} , this will allow us to use this file as jekyll. The file to which we apply the layout will be placed where the content tag is located.
Find CSS for the project page theme. for me it was a line like the following:
<link rel='stylesheet' href='stylesheets/stylesheet.css' />
It needs to be changed to
<link rel='stylesheet' href='{{ site.path }}/stylesheets/stylesheet.css' />
- Any other assets stored on your site that will be used in this layout must also be prefixed with
{{ site.path }} .
Having done this, Jekyll will display the markup file as the contents of the index.html layout in the _layouts directory. To automate this process not only for the README.md file, but also for other documents that may be in your main branch, I took the following steps:
Created a file called post-commit containing the following:
#!/bin/bash
EDIT: I updated the above script for the README.md file and markdowns in docs/* to use the same layout file. This is much better than before. This script is in your .git/hooks/ directory. bash should be in your path.
Create a _config.yml file with the following
markdown: redcarpet path: http:
The aforementioned script also synchronizes the markup files found in the docs/* directory of the master branch so that they can be viewed on the GitHub Pages website. Relative binding to these documents works if you include the following jQuery function to separate the .md extension from the anchors on the gh-pages branch. You can add the following script in index.html to the _layouts directory:
$(document).on('ready', function () { $('a').each(function (i, e) { var href = e.href; if (href.search('.md') > 0) $(this).attr('href', href.split('.md')[0]); }); });
EDIT: I changed the code above in my repository, it was a quick and dirty way to do this, but it will not work correctly in all cases if you know what I mean. For example, the markdown file company.mdata.md will not be processed correctly. To fix this, I updated it to the next script, which checks href more carefully and removes the extension if it is found. I also made the script more general, allowing you to use it to remove other extensions by changing the ext variable. Here is the code:
$(function () { $('a').each(function () { var ext = '.md'; var href = $(this).attr('href'); var position = href.length - ext.length; if (href.substring(position) === ext) $(this).attr('href', href.substring(0, position)); }); });
I am installing a repo example in CoryG89 / docsync , which has a project page here if you want to see how it all works together.