diff --git a/libs/timeline.css b/libs/timeline.css index 6107483..c6a39df 100644 --- a/libs/timeline.css +++ b/libs/timeline.css @@ -141,6 +141,11 @@ img.avatar { border: none; } +.embed-video { + width: 100%; + aspect-ratio: 16/9; +} + a.author { text-decoration: none; color: var(--text); diff --git a/libs/twtxt.php b/libs/twtxt.php index 64631e1..4b2068e 100644 --- a/libs/twtxt.php +++ b/libs/twtxt.php @@ -180,8 +180,9 @@ function replaceLinksFromTwt(string $twtString) { // 1. Look into how yarnd handles this // Regular expression pattern to match URLs - $pattern = '/(?)(?\s]+)/is'; + // Replace URLs with clickable links $replacement = '$1'; $result = preg_replace($pattern, $replacement, $twtString); @@ -216,6 +217,29 @@ function replaceTagsFromTwt(string $twtString) { return $result; } +function embedYoutubeFromTwt(string $twtString) { + + // original regex source: https://gist.github.com/afeld/1254889#gistcomment-1253992 + $pattern = '/(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/mi'; + + if(preg_match_all($pattern, $twtString, $youtubeLinks)) { + + $youtubeLinks = array_unique($youtubeLinks[1]); // Remove dublicate cause by raw URLs conceverter to links + + //echo "
"; + //print_r($youtubeLinks); + //echo ""; + + foreach ($youtubeLinks as $videoID) { + $twtString .= '