Skip to content

Commit

Permalink
Handle the README as a "special" docs file
Browse files Browse the repository at this point in the history
  • Loading branch information
EWright212 authored and nickcharlton committed Sep 21, 2020
1 parent 4207c9d commit 4bd8f45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
21 changes: 15 additions & 6 deletions spec/example_app/app/controllers/docs_controller.rb
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -87,7 +96,7 @@ def title
end

def title_suffix
metadata["home"] ? "" : " - Administrate"
metadata["home"] ? "Administrate" : " - Administrate"
end

private
Expand Down

0 comments on commit 4bd8f45

Please sign in to comment.