summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axilleas@axilleas.me>2017-09-18 21:50:05 +0200
committerAchilleas Pipinellis <axil@gitlab.com>2017-09-21 17:02:27 +0200
commit5b79a7c30b9d13766d53254ffb23ad55397e0103 (patch)
tree684f1dc72091254440da2dc2a864107d93bd2722
parent727f51b8ef0af2b78087b4ac894ee728bfbabd1f (diff)
downloadgitlab-ce-hide-frontmatter-help-page.tar.gz
Do not show YAML frontmatter for doc pages under /helphide-frontmatter-help-page
We recently started adding YAML frontmatter in docs so that we can show more information, but that only works for the docs portal at docs.gitlab.com. For example, we want to add a last_updated entry https://gitlab.com/gitlab-org/gitlab-ce/issues/37677 Whereas this is useful for the docs portal, it looks ugly for docs under /help.
-rw-r--r--app/controllers/help_controller.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb
index 87c0f8905ff..67a71f08b1b 100644
--- a/app/controllers/help_controller.rb
+++ b/app/controllers/help_controller.rb
@@ -3,12 +3,17 @@ class HelpController < ApplicationController
layout 'help'
+ # Taken from Jekyll
+ # https://github.com/jekyll/jekyll/blob/3.5-stable/lib/jekyll/document.rb#L13
+ YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m
+
def index
- @help_index = File.read(Rails.root.join('doc', 'README.md'))
+ # Remove YAML frontmatter so that it doesn't look weird
+ @help_index = File.read(Rails.root.join('doc', 'README.md')).sub(YAML_FRONT_MATTER_REGEXP, '')
# Prefix Markdown links with `help/` unless they are external links
# See http://rubular.com/r/X3baHTbPO2
- @help_index.gsub!(%r{(?<delim>\]\()(?!.+://)(?!/)(?<link>[^\)\(]+\))}) do
+ @help_index.sub!(%r{(?<delim>\]\()(?!.+://)(?!/)(?<link>[^\)\(]+\))}) do
"#{$~[:delim]}#{Gitlab.config.gitlab.relative_url_root}/help/#{$~[:link]}"
end
end
@@ -22,7 +27,8 @@ class HelpController < ApplicationController
path = File.join(Rails.root, 'doc', "#{@path}.md")
if File.exist?(path)
- @markdown = File.read(path)
+ # Remove YAML frontmatter so that it doesn't look weird
+ @markdown = File.read(path).gsub(YAML_FRONT_MATTER_REGEXP, '')
render 'show.html.haml'
else