Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedditEmbed #1754

Merged
merged 5 commits into from
Jul 30, 2024
Merged

RedditEmbed #1754

merged 5 commits into from
Jul 30, 2024

Conversation

tim-evans
Copy link
Collaborator

Reddit has changed their embed codes from iframe embeds to a more standard blockquote + script embed code. We previously were detecting only the iframe embed versions of these and had none of the options support that Reddit provided for embedding their posts.

Reddit embed UI

<blockquote class="reddit-embed-bq" style="height:500px" data-embed-height="740"><a href="https://www.reddit.com/r/cats/comments/1cretsi/made_this_mistake_need_help_with_names/">Made this mistake. Need help with names.</a><br> by<a href="https://www.reddit.com/user/niccia/">u/niccia</a> in<a href="https://www.reddit.com/r/cats/">cats</a></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"></script>

This will turn into:

{
  "blocks": [
    {
      "attributes": {
        "content": "B00000000",
        "height": 740,
        "hidePostContent": false,
        "hideUsername": false,
        "url": "https://www.reddit.com/r/cats/comments/1cretsi/made_this_mistake_need_help_with_names/",
      },
      "id": "B00000000",
      "parents": [],
      "selfClosing": false,
      "type": "reddit-embed",
    },
    {
      "attributes": {},
      "id": "B00000001",
      "parents": [
        "reddit-embed",
      ],
      "selfClosing": true,
      "type": "line-break",
    },
  ],
  "marks": [
    {
      "attributes": {
        "url": "https://www.reddit.com/r/cats/comments/1cretsi/made_this_mistake_need_help_with_names/",
      },
      "id": "M00000000",
      "range": "(1..41)",
      "type": "link",
    },
    {
      "attributes": {
        "refs": [
          "B00000000",
        ],
      },
      "id": "M00000001",
      "range": "(1..62]",
      "type": "slice",
    },
    {
      "attributes": {
        "url": "https://www.reddit.com/user/niccia/",
      },
      "id": "M00000002",
      "range": "(46..54)",
      "type": "link",
    },
    {
      "attributes": {
        "url": "https://www.reddit.com/r/cats/",
      },
      "id": "M00000003",
      "range": "(58..62)",
      "type": "link",
    },
  ],
  "text": "Made this mistake. Need help with names. by u/niccia in cats",
}

Base automatically changed from social-media-content to main June 10, 2024 14:02
this implements Reddit embeds as separate blocks
that are identified not through
an iframe embed, but with their
blockquote embed code.
for some reason the embed code doesn't have these spaces
and it makes the textual content kind of unreadable
@tim-evans tim-evans marked this pull request as ready for review June 12, 2024 18:52
})
);
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah what was going on here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, there's a small bug with the serialize method that was eating some text

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can separate this into another PR if that helps

});
});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want any tests for handling Reddit URLs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we need some extra attributes for reddit content that cannot be inferred by url.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically, height :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're still identifying reddit embeds by URL above though, in utils/social-urls.ts. Don't we want to have some tests for that? Or if we are expecting to use oembed data for this, shouldn't that be removed from the social-urls identification above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right

}> {
static type = "reddit-embed";
static vendorPrefix = "offset";
}
Copy link
Contributor

@bachbui bachbui Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reddit embeds also have an option to display in dark mode, do we want to support that option?

<blockquote 
  class="reddit-embed-bq"
  style="height:500px"
  data-embed-theme="dark"
  data-embed-height="740"
>
  <a href="https://www.reddit.com/r/DIY/comments/1ddx4kp/whats_going_on_with_my_washer_discharge_hose_and/">[What's going on with my washer discharge hose and how can I prevent it in the future?](https://www.reddit.com/r/DIY/comments/1ddx4kp/whats_going_on_with_my_washer_discharge_hose_and/)</a>
  <br> by
  <a href="https://www.reddit.com/user/Tsiah16/">[u/Tsiah16](https://www.reddit.com/user/Tsiah16/)</a> in<a href="https://www.reddit.com/r/[DIY](https://www.reddit.com/r/DIY/)/">DIY</a>
</blockquote>
<script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"></script>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is something that is up to the calling context and not necessarily something that should be controlled by editors.

Copy link
Contributor

@bachbui bachbui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still have a Q on the social-urls test for identifying Reddit URLs, but otherwise this lgtm

@tim-evans
Copy link
Collaborator Author

@bachbui just removed that bit of code, thanks for that

@tim-evans tim-evans merged commit 204ddcf into main Jul 30, 2024
3 checks passed
@tim-evans tim-evans deleted the reddit-embed branch July 30, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants