0
votes

I'm trying to achieve something in the vein of Staticman: a static website on GitHub Pages that can use javascript and the GitHub API in order to commit to the repository it is based on, thereby acting somewhat as though it were a non-static site.

Accessing the underlying repository obviously requires the name of that repository. I could hard-code this, but that's not ideal, as I intend to fork/clone this repository, and I'd have to change that hard-code in each fork.

So I want to know if there's some way for JavaScript in a GitHub Pages website to automatically determine which repository it's been built from. Or, alternatively, to use Jekyll to insert the repository name during the static site construction.

1

1 Answers

1
votes

You can do this with {{ site.github.repository_nwo }} to get <username>/<reponame> (name with owner) or {{ site.github.repository_name }} to get just <reponame>. These Jekyll variables come from the Github Metadata plugin, which exists by default on Github Pages. The relevant part of the documentation is here.

It seems like you might want the entire repository URL, which can be extracted using {{ site.github.repository_url }}. The plugin also provides {{ site.github.clone_url }} (repositoryURL + ".git") which is the URL from which you clone the repo if it were bare.