Skip to content
Snippets Groups Projects
Commit 0a04fb54 authored by Evan Read's avatar Evan Read
Browse files

Allow /help to accept either page title in front matter or in Markdown

parent 3508b68b
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !145627. Comments created here will be created in the context of that merge request.
......@@ -74,7 +74,12 @@ def drawers
# Remove YAML frontmatter so that it doesn't look weird
helper_method :get_markdown_without_frontmatter
def get_markdown_without_frontmatter(path)
File.read(path).gsub(YAML_FRONT_MATTER_REGEXP, '')
markdown = File.read(path)
markdown_title_matches = markdown.match(/^title: (?<title>.+)$/)
output = [markdown.sub(YAML_FRONT_MATTER_REGEXP, '')]
output.unshift("# #{markdown_title_matches[:title]}\n") if markdown_title_matches
output.join("\n")
end
def redirect_to_documentation_website?
......
......@@ -31,6 +31,17 @@ For example:
If it is important that a documentation update is present in that month's release,
merge it as early as possible.
## Source files
`/help` can render Markdown files with the level 1 heading either:
- Specified in YAML front matter using `title`. For example, `title: My Markdown file`.
[Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/145627) in GitLab 16.10.
- Specified in the Markdown itself. For example, `# My Markdown file`.
You should not specify the level 1 heading for a page using both methods at the same time, otherwise the level 1 heading
is repeated.
## Linking to `/help`
When you're building a new feature, you may need to link to the documentation
......
......@@ -137,6 +137,33 @@
expect(response).not_to redirect_to(profile_two_factor_auth_path)
end
end
context 'when requesting help index' do
subject { get :index }
before do
stub_application_setting(help_page_documentation_base_url: '')
stub_doc_file_read(content: content)
end
context 'and the doc/index.md file has the level 1 heading in frontmatter' do
let(:content) { "---\ntitle: Test heading\n---\n\nTest content" }
it 'returns content with title in Markdown' do
expect(subject).to be_successful
expect(assigns[:help_index]).to eq "# Test heading\n\nTest content"
end
end
context 'and the doc/index.md file has the level 1 heading in Markdown' do
let(:content) { "# Test heading\n\nTest content" }
it 'returns content with title in Markdown' do
expect(subject).to be_successful
expect(assigns[:help_index]).to eq "# Test heading\n\nTest content"
end
end
end
end
describe 'GET #drawers' do
......@@ -290,6 +317,33 @@
expect(response).to be_not_found
end
end
context 'when requesting content' do
subject { get :show, params: { path: 'install/install_methods' }, format: :md }
before do
stub_application_setting(help_page_documentation_base_url: '')
stub_doc_file_read(content: content)
end
context 'and the Markdown file has the level 1 heading in frontmatter' do
let(:content) { "---\ntitle: Test heading\n---\n\nTest content" }
it 'returns content with the level 1 heading in Markdown' do
expect(subject).to be_successful
expect(assigns[:markdown]).to eq "# Test heading\n\nTest content"
end
end
context 'and the Markdown file has the level 1 heading in Markdown' do
let(:content) { "# Test heading\n\nTest content" }
it 'returns content with the level 1 heading in Markdown' do
expect(subject).to be_successful
expect(assigns[:markdown]).to eq "# Test heading\n\nTest content"
end
end
end
end
def stub_two_factor_required
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment