git-read

Navigate to next commit

When one commit comes after another in a sequence, it can be referred to as its child.

Unfortunately, the concept of a child in a directed graph like a Git tree (especially a reversed Git tree, like in our case) does not apply.

To counteract this limitation, introduce a adjacent_commits helper method to iterate through the history with a three commit-wide window, determining whether or not the page’s current commit’ SHA matches the middle element of the window’s SHA.

In order to add a buffer to either side of the “window”, this approach utilizes the Enumerable#chain method to combine the Array of Git commits with extra leading and trailing indices, to give the windowing function space to execute.

When viewing the final commit, the commit won’t have a child.

To account for this, guard the render block with a presence checking conditional.

Desktop: Only Next

git-read navigation with only "Next" in desktop dimensions

Desktop: Only Previous

git-read navigation with only "Previous" in desktop dimensions

Mobile: Only Next

git-read navigation with only "Next" in mobile dimensions

Mobile: Only Previous

git-read navigation with only "Previous" in mobile dimensions