Skip to content

Commit

Permalink
Remove regex from EmbedCard, use Youtube ID
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickpatrickpatrick committed Feb 28, 2025
1 parent b9d6ce1 commit 127c76c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/javascripts/components/embed-card.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ class EmbedCard extends Component {

const title = placeholderText ? placeholderText.textContent : ''

const ytHref = placeholder.getAttribute('href')
const ytId = ytHref.match(
/(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^?&"'>]+)/
)[5]
const ytId = this.$root.dataset.ytEmbedId

const divIframeContainer = document.createElement('div')
divIframeContainer.className = 'app-embed-card__iframe-container'
Expand Down
2 changes: 1 addition & 1 deletion views/partials/_embed-card.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro embedCard(params) %}
<div class="govuk-grid-row" data-module="app-embed-card">
<div class="govuk-grid-row" data-module="app-embed-card" data-yt-id="{{ params.ytId }}">
<div class="govuk-grid-column-two-thirds-from-desktop">
{{- caller() if caller else params.content | safe -}}
<a class="app-embed-card__placeholder app-embed-card__placeholder-thumb-container" href="https://www.youtube.com/watch?v={{ params.ytId }}">
Expand Down

0 comments on commit 127c76c

Please sign in to comment.