github.com/outbrain/consul@v1.4.5/website/config.rb (about)

     1  set :base_url, "https://www.consul.io/"
     2  
     3  activate :hashicorp do |h|
     4    h.name        = "consul"
     5    h.version     = "1.4.5"
     6    h.github_slug = "hashicorp/consul"
     7  end
     8  
     9  helpers do
    10    # Returns a segment tracking ID such that local development is not
    11    # tracked to production systems.
    12    def segmentId()
    13      if (ENV['ENV'] == 'production')
    14        'IyzLrqXkox5KJ8XL4fo8vTYNGfiKlTCm'
    15      else
    16        '0EXTgkNx0Ydje2PGXVbRhpKKoe5wtzcE'
    17      end
    18    end
    19  
    20    # Returns the FQDN of the image URL.
    21    #
    22    # @param [String] path
    23    #
    24    # @return [String]
    25    def image_url(path)
    26      File.join(base_url, image_path(path))
    27    end
    28  
    29    # Get the title for the page.
    30    #
    31    # @param [Middleman::Page] page
    32    #
    33    # @return [String]
    34    def title_for(page)
    35      if page && page.data.page_title
    36        return "#{page.data.page_title} - Consul by HashiCorp"
    37      end
    38  
    39       "Consul by HashiCorp"
    40     end
    41  
    42    # Get the description for the page
    43    #
    44    # @param [Middleman::Page] page
    45    #
    46    # @return [String]
    47    def description_for(page)
    48      description = (page.data.description || "Consul by HashiCorp")
    49        .gsub('"', '')
    50        .gsub(/\n+/, ' ')
    51        .squeeze(' ')
    52  
    53      return escape_html(description)
    54    end
    55  
    56    # This helps by setting the "active" class for sidebar nav elements
    57    # if the YAML frontmatter matches the expected value.
    58    def sidebar_current(expected)
    59      current = current_page.data.sidebar_current || ""
    60      if current.start_with?(expected)
    61        return " class=\"active\""
    62      else
    63        return ""
    64      end
    65    end
    66  
    67    # Returns the id for this page.
    68    # @return [String]
    69    def body_id_for(page)
    70      if !(name = page.data.sidebar_current).blank?
    71        return "page-#{name.strip}"
    72      end
    73      if page.url == "/" || page.url == "/index.html"
    74        return "page-home"
    75      end
    76      if !(title = page.data.page_title).blank?
    77        return title
    78          .downcase
    79          .gsub('"', '')
    80          .gsub(/[^\w]+/, '-')
    81          .gsub(/_+/, '-')
    82          .squeeze('-')
    83          .squeeze(' ')
    84      end
    85      return ""
    86    end
    87  
    88    # Returns the list of classes for this page.
    89    # @return [String]
    90    def body_classes_for(page)
    91      classes = []
    92  
    93      if !(layout = page.data.layout).blank?
    94        classes << "layout-#{page.data.layout}"
    95      end
    96  
    97      if !(title = page.data.page_title).blank?
    98        title = title
    99          .downcase
   100          .gsub('"', '')
   101          .gsub(/[^\w]+/, '-')
   102          .gsub(/_+/, '-')
   103          .squeeze('-')
   104          .squeeze(' ')
   105        classes << "page-#{title}"
   106      end
   107  
   108      return classes.join(" ")
   109    end
   110  end