From 533eefa935bcfa6565deef44e2939a3065602654 Mon Sep 17 00:00:00 2001 From: Neetpone <132411956+Neetpone@users.noreply.github.com> Date: Wed, 3 Apr 2024 05:18:15 -0400 Subject: [PATCH] fix: fix duplicate title --- app/controllers/chapters_controller.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/chapters_controller.rb b/app/controllers/chapters_controller.rb index f63f8ac..1ab16be 100644 --- a/app/controllers/chapters_controller.rb +++ b/app/controllers/chapters_controller.rb @@ -5,10 +5,25 @@ class ChaptersController < ApplicationController @story = Story.find(params[:story_id]) @chapter = @story.chapters.find_by(number: params[:id]) - @rendered_html = markdown.render(@chapter.body) + @rendered_html = render_story end private + + def render_story + body = @chapter.body + body.lstrip! + body = body.split "\n" + + # This is fucking bad, this gets rid of the redundant title - this should be fixed upstairs, + # in the actual generation of the Markdown. + if body.length >= 2 && body[0] == @chapter.title && body[1].length > 0 && body[1][0] == '=' + body = body[2..] + end + + markdown.render body.join("\n") + end + def markdown @@markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)