git-read

Render the contents of a Commit’s Message

A Git commit message follows a loose structure:

The first line of a commit message serves as a summary. When displayed on the web, it’s often styled as a heading, and in emails, it’s typically used as the subject. As such, you should capitalize it and omit any trailing punctuation. Aim for about 50 characters, give or take, otherwise it may be painfully truncated in some contexts.

Oftentimes a subject by itself is sufficient. When it’s not, add a blank line (this is important) followed by one or more paragraphs hard wrapped to 72 characters.

Assuming that the commits adhere to that convention, the application will split out the commit’s subject line from the rest of the message, and treat it as the resulting HTML page’s title.

The call to subject.strip in the source/commits/commit template is deliberate and important. Without it, a trailing new-line character would separate the title from its underlining === syntax, which would signal to the Markdown generator that it was to be represented as a <p> element` instead of an <h1> element.

Both the /index.html and specific /commits/$SHA/index.html pages render the project’s history in a navigable sidebar. To power this feature, and to ensure that the data is shared across Middleman’s proxy templates, extract a config.rb-local variable, which is declared and shared by merging in additional template local variables as the local: key.

The history is meant to be read start-to-finish (as opposed to the typical latest-to-first output that a default git log call provides).

To achieve this order, extract the History and declare the #commits method which chains a call to Enumerable#reverse_each onto calls to repository.log. The Repository#log method receives a limit on the number of commits to provide. We want the full history, so we pass nil.

There are times when a commit’s subject line contains Markdown that we do not want to inline as raw HTML. To support this, wrap the navigation item’s text in calls to the new #markdown helper declared within config.rb. This helper utilizes the underlying Markdown engine that Middleman has registered with Tilt.