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

#6809 - Enable embed codes Intranet and Main Site #1011

Merged
merged 5 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rca/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@

WAGTAILEMBEDS_FINDERS = [
{"class": "rca.utils.embed_finders.CustomOEmbedFinder"},
{"class": "rca.utils.embed_finders.WixEmbedFinder"},
]


Expand Down
31 changes: 31 additions & 0 deletions rca/utils/embed_finders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import re

import requests
from bs4 import BeautifulSoup
from wagtail.embeds.finders.base import EmbedFinder
from wagtail.embeds.finders.oembed import OEmbedFinder


Expand All @@ -20,3 +24,30 @@ def find_embed(self, url, max_width=None):
embed["html"] = str(soup)

return embed


class WixEmbedFinder(EmbedFinder):
"""Embed finder support for Wix. Wix does not have oEmbed support."""

def accept(self, url):
return re.match(r"^https?://(?:www\.)?embed.wix\.com/.+$", url)

def find_embed(self, url, max_width=None):
# Attempt to fetch the page content and scrape the title.
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")

title_tag = soup.find("title")
title = title_tag.string if title_tag else None

return {
# Title does not support None.
"title": title if title else "",
"provider_name": "Wix",
"type": "video",
"html": '<iframe src="{url}" frameborder="0" allowfullscreen title={title}></iframe>'.format(
url=url, title=title
),
"width": 800,
"height": 600,
}
Loading