From 4bd8f455e759a6049677ded457a76a5995948527 Mon Sep 17 00:00:00 2001 From: Student Date: Tue, 14 Jul 2020 11:02:15 +0100 Subject: [PATCH] Handle the README as a "special" docs file --- README.md | 5 +---- .../app/controllers/docs_controller.rb | 21 +++++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4ae484b411..6b8ba012cf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,4 @@ ---- -title: Administrate -home: true ---- +# Administrate [![CircleCI](https://img.shields.io/circleci/project/github/thoughtbot/administrate.svg)](https://circleci.com/gh/thoughtbot/administrate/tree/master) [![Gem Version](https://badge.fury.io/rb/administrate.svg)](https://badge.fury.io/rb/administrate) diff --git a/spec/example_app/app/controllers/docs_controller.rb b/spec/example_app/app/controllers/docs_controller.rb index bdea74c234..865eb4a617 100644 --- a/spec/example_app/app/controllers/docs_controller.rb +++ b/spec/example_app/app/controllers/docs_controller.rb @@ -1,9 +1,14 @@ class DocsController < ApplicationController SPECIAL_FILES = [ { - file: 'CONTRIBUTING', - page: 'contributing' - } + file: "CONTRIBUTING", + page: "contributing", + }, + { + file: "README", + page: "index", + home: true, + }, ].freeze REDCARPET_CONFIG = { @@ -44,7 +49,7 @@ def render_page(name) render layout: "docs", html: contents.body.html_safe # rubocop:enable Rails/OutputSafety else - render file: "#{Rails.root}/public/404.html", + render file: Rails.root.join("/public/404.html"), layout: false, status: :not_found end @@ -63,7 +68,11 @@ class DocumentParser def initialize(source_text) front_matter_parsed = FrontMatterParser::Parser.new(:md).call(source_text) @source_text = front_matter_parsed.content - @metadata = front_matter_parsed.front_matter + @metadata = if front_matter_parsed.front_matter.empty? + { "home" => true } + else + front_matter_parsed.front_matter + end end def body @@ -87,7 +96,7 @@ def title end def title_suffix - metadata["home"] ? "" : " - Administrate" + metadata["home"] ? "Administrate" : " - Administrate" end private