Is there a route to get a cooked post, but without rendered oneboxes?

For an external Facebook Instant Article generator, we need the cooked HTML posts but without rendered oneboxes…

Does any such route or API endpoint for posts exist already?

1 Like

Maybe this can help https://github.com/discourse/raw-post-button

1 Like

Hi @adopilot, many thanks for your feedback. Kindly can you elaborate?

Looks like a component to view the raw post.

We’re looking for something to render a cooked post, but without the oneboxes.

Apologies, i thought that you need raw post, later I did realised that I was wrong and it was posted allready.

1 Like

Anybody? Can this somehow be achieved?

Hey @Terrapop

You could write a plugin to hide (or remove) the DOM element for the One Box when the requesting User Agent string matches the User Agent string of the FB bot.

Hope this helps.

1 Like

You will need to post process the HTML, the cooked posts already contains all the HTML for oneboxes expanded.

2 Likes

That is exactly the problem. As the cooked posts contain the oneboxes (which don’t have the original media links anymore, only raw has the original links) we can’t transform them into a FB IA valid format.

Iframely is producing IA valid IFRAMEs from the standalone links. We tried to use the raw posts and use a PHP markdown parser (Markdown-It for PHP) plus Iframely for the standalone links, but the Discourse markdown parsing does a lot more, and we don’t want to replicate all the magic Discourse does to the markdown. Thus, we are looking for a route to get cooked posts, but without parsed oneboxes (as we want to post-process those via Iframely instead).

Our current approach works for simple posts ie. take raw as a basis, use PHP Mardown-It to transform into HTML, and use Iframely to produce IA valid media cards (oneboxes aren’t), then transform the HTML into Facebook IA HTML and transmit via the FB PHP SDK, but as Discourse applies a lot of additional rules to the markdown parsing, it would be great to somehow get the parsed HTML directly from Discourse, but just without the oneboxes.

1 Like

You don’t need to cook you post outside discourse. Just monkey patch the responsible method and exclude the part where oneboxes are generated. General idea.

2 Likes

Well, we don’t want to change the cooking behavior in general on Discourse but need an endpoint (API) that produces a cooked post but without oneboxes (but leave the original standalone links inside e.g. as ahrefs).

1 Like

Just hide or remove the DOM element. It’s quite a simple task.

  1. Match User Agent string with Ruby and set a boolean on a match**.
  2. Javascript to hide the DOM element if the boolean is true.

This is basically the “standard” way to do this and similar tasks where a developer does not want to show (or wants to remove) any DOM element.


**Note:

Using the ‘gon’ Ruby gem makes passing any Ruby variable to Javascript very simple, but I have only used it on a Rails app, not with EmberJS in the stack (anyway, there are many ways to pass a Ruby variable to JS)…