Best way of linking Github repo code from Github Pages

Dear All,

I am using Github pages and jekyll to write a scientific tutorial, with code that is also hosted on Github. In my Github repo I have a “codes” folder and a “docs” folder. The former hosts the code, the latter hosts my jekyll website, as recommended on GitHub and Jekyll websites.

In my tutorial I want to discuss/display code that is hosted on the GitHub repo, under “codes”, and I would like to avoid copy/pasting code from the repo to the page. I think it would be much easier to link directly to one of the files in the Github repo.

Is there a way to do this automatically, so that if I change any of the files in “codes”, the changes will be reflected in the Jekyll website?

I know that there exists a Jekyll-gist plugin, but I don’t think I am allowed to use it on GitHub pages. Also I don’t know if this requires me to setup another layer (“a gist”) for each file I want to link to.

Do you know if this can be done at all?

This is an interesting one! Surprised GitHub haven’t offered the option to embed files from repos into sites, I guess the overhead would be quite large. I did a bit of googling and found this which allows you to embed files and chunks of code into pages

Hopefully this is good enough to solve your problem :star: