From 7673ed2480ffe0ee27894a5b1dab42008f7f183e Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 5 Nov 2018 10:21:10 +1100 Subject: [PATCH] FIX: in some cases first_post could be missing --- plugin.rb | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/plugin.rb b/plugin.rb index 0c8fc79..d80bf19 100644 --- a/plugin.rb +++ b/plugin.rb @@ -221,23 +221,24 @@ SQL # note, we have canonicals so we only do this for page 1 at the moment # it can get confusing to have this on every page and it should make page 1 # a bit more prominent + cut down on pointless work - return "" if topic_view.post_number != 1 + return "" if !controller.guardian.allow_accepted_answers_on_category?(topic.category_id) - if first_post = topic_view.posts&.first - question_json = { - '@type' => 'Question', - 'name' => topic.title, - 'text' => first_post.excerpt, - 'upvoteCount' => first_post.like_count, - 'answerCount' => topic.reply_count, - 'dateCreated' => topic.created_at, - 'author' => { - '@type' => 'Person', - 'name' => topic.user&.name - } + first_post = topic_view.posts&.first + return "" if first_post&.post_number != 1 + + question_json = { + '@type' => 'Question', + 'name' => topic.title, + 'text' => first_post.excerpt, + 'upvoteCount' => first_post.like_count, + 'answerCount' => topic.reply_count, + 'dateCreated' => topic.created_at, + 'author' => { + '@type' => 'Person', + 'name' => topic.user&.name } - end + } page_json = { '@type' => 'QAPage',