Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add frontmatter error-handling (#1797)
  • Loading branch information
aspittel authored and maestromac committed Feb 13, 2019
1 parent 7b21a3a commit 7492783
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/models/article.rb
Expand Up @@ -60,7 +60,7 @@ class Article < ApplicationRecord

serialize :ids_for_suggested_articles

scope :cached_tagged_with, -> (tag) { where("cached_tag_list ~* ?", "^#{tag},| #{tag},|, #{tag}$|^#{tag}$") }
scope :cached_tagged_with, ->(tag) { where("cached_tag_list ~* ?", "^#{tag},| #{tag},|, #{tag}$|^#{tag}$") }

scope :active_help, -> {
where(published: true).
Expand Down Expand Up @@ -312,8 +312,13 @@ def evaluate_markdown

def has_frontmatter?
fixed_body_markdown = MarkdownFixer.fix_all(body_markdown)
parsed = FrontMatterParser::Parser.new(:md).call(fixed_body_markdown)
parsed.front_matter["title"]
begin
parsed = FrontMatterParser::Parser.new(:md).call(fixed_body_markdown)
parsed.front_matter["title"]
rescue Psych::SyntaxError
# if frontmatter is invalid, still render editor with errors instead of 500ing
true
end
end

def class_name
Expand Down

0 comments on commit 7492783

Please sign in to comment.