Jiang Wu Data Engineer @ Adyen (NL)

Adding 'Edit on GitHub' links to GitHub Pages using Jekyll

If you’re using Jekyll on GitHub Pages you can have your Jekyll blog posts or collection document pages with extra “Edit on GitHub”, “View source” and even “View revision history” links. Here’s how you can have those:

If you’re hosting the site on GitHub Pages using Jekyll, they inject the source repository into a variable called {{ site.github.repository_url }} which you can use in combination with {{ page.path }} to wire up the URL on github.com.

For a blog post


<a href="{{ site.github.repository_url }}/edit/{{ site.branch }}/{{ page.path }}">
  Edit this page on GitHub
</a>

Example for output URL of above input URL:


<a href="http://github.com/username/username.github.io/edit/master/_posts/yyyy-mm-dd-your-post-title.md">
  Edit this page on GitHub
</a>

For a collection document

For a collection document, you’ll need to use {{ page.relative_path }} instead of {{ page.path }} to get the desired behavior.


<a href="{{ site.github.repository_url }}/edit/{{ site.branch }}/{{ page.relative_path }}">
  Edit this page on GitHub
</a>

On Prose

If you are using Prose to manage your content:


<a href="http://prose.io/#{{ site.repo }}/edit/{{ site.branch }}/{{ page.path }}">
  Edit this page
</a>

You can add link of a source code of a post or doc on GitHub.

For a blog post


<a href="{{ site.github.repository_url }}/blob/{{ site.branch }}/{{ page.path }}">
  View source
</a>

For a collection document


<a href="{{ site.github.repository_url }}/blob/{{ site.branch }}/{{ page.relative_path }}">
  View source
</a>

Like ways you can also add view revision history link which shows all the commitments of a post or doc.

For a blog post


<a href="{{ site.github.repository_url }}/commits/{{ site.branch }}/{{ page.path }}">
  View revision history
</a>

For a collection document


<a href="{{ site.github.repository_url }}/commits/{{ site.branch }}/{{ page.relative_path }}">
  View revision history
</a>