Post Cooking Process with Landing Pages

AI-generated summary

sharewoodsDavid is experiencing issues with post cooking in the Landing Pages plugin on their Discourse instance. They’ve installed PDF-Preview and Discourse-Chart plugins, but when rendering a post in a landing page, it doesn’t appear to be cooked or take into account existing plugins and theme components. They’ve identified the relevant code in discourse-landing-pages/lib/landing-pages/post.rb and html.erb, specifically the post.cooked method which returns pre-cooked text, but are unsure how to proceed. They’re seeking help to resolve this issue without modifying the plugin if possible.

Hello,

I’m trying to figure why post cooking isn’t working for the Landing Pages plugin and how I could get it working (if possible) without altering the plugin but if I had to, what could I do ? Ruby is not my forte.

On my discourse instance I have installed the PDF-Preview component as well as the Discourse-Chart plugin. However, when rendering the post it isn’t cooked whatsoever. Or at least not taking into consideration existing plugins and theme components.

To render the post in the landing pages the following code is applied and executed.

In the html.erb file:

::LandingPages::Post.html(@topic_view.posts.first).html_safe

which calls the following code in discourse-landing-pages/lib/landing-pages/post.rb:

class ::LandingPages::Post
  def self.html(post, remove_topic_image: true)
    fragment = Nokogiri::XML.fragment(post.cooked)

    if remove_topic_image && topic_image_sha1 = post.topic&.image_upload&.sha1
      if image_node = fragment.css("a[href*='#{topic_image_sha1}']").first
        image_node.parent.remove
      end
    end

    fragment.to_html
  end
end

From here, I’m not sure what’s going on. I suppose post.cooked is just returning the post cooked text but this means that it was already executed on page load…

Thanks for your help !

1 Like