From 204b5f4270e258c10f16ad0f1ed1274dfb78681f Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 27 Oct 2016 20:35:49 -0400 Subject: [PATCH] Add helpers for generating titles and stuff --- website/config.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/website/config.rb b/website/config.rb index 415076ccf..9df483a2a 100644 --- a/website/config.rb +++ b/website/config.rb @@ -5,3 +5,50 @@ activate :hashicorp do |h| h.version = "0.4.1" h.github_slug = "hashicorp/nomad" end + +helpers do + # Get the title for the page. + # + # @param [Middleman::Page] page + # + # @return [String] + def title_for(page) + if page && page.data.page_title + return "#{page.data.page_title} - Nomad by HashiCorp" + end + + "Nomad by HashiCorp" + end + + # Get the description for the page + # + # @param [Middleman::Page] page + # + # @return [String] + def description_for(page) + return escape_html(page.data.description || "") + end + + # Returns the id for this page. + # @return [String] + def body_id_for(page) + if name = page.data.sidebar_current && !name.blank? + return "page-#{name.strip}" + end + return "page-home" + end + + # Returns the list of classes for this page. + # @return [String] + def body_classes_for(page) + classes = [] + + if page && page.data.layout + classes << "layout-#{page.data.layout}" + end + + classes << "-displaying-bnr" + + return classes.join(" ") + end +end