Embed code from GitHub to GitHub Pages blog like Gist

2017-11-28

Gist-It · Github-Pages · Jekyll

1 minute

I’ve found this nifty little tool that can embed codes directly from your GitHub repositories without using Gist. It’s very easy to use. For example, if you want to embed, say, this whole file, you only need to add this snippet somewhere in your post.md file.

<script charset="UTF-8" src="https://gist-it.appspot.com/github.com/flowerinthenight/rusttrace/blob/master/src/main.rs?footer=minimal"></script>

The ?footer=minimal part is optional. It will look something like this:

It can also embed just a section of code based on line numbers. For example, to embed line 234 to line 257 of this file, this snippet will do.

<script charset="UTF-8" src="https://gist-it.appspot.com/github.com/flowerinthenight/rmq/blob/master/rabbitmq.go?slice=233:257&footer=minimal"></script>

It will look something like this:

Just note that the slice= parameter is zero-based and GitHub’s line numbering starts at 1.

Finally, if you have an HTTPS blog, make sure to use https://gist-it.appspot.com/..., not http://gist-it.appspot.com/....