2

I have a Jekyll setup that is working out well for me, but I would like to spice up my site by taking YouTube links that are inside their own <p> and automatically embed and image inside.

I have figured out the format for YouTube links.

https://img.youtube.com/vi/<videoid>/0.jpg

and I have found a regular expression to match the video id inside a YouTube link.

v=(\w+)">

I have figured out also I need a :post-render hook and I have the plugin set up and running.

I am a bit stuck on what to do next, I am not a ruby expert and I am absolutely terrible at regular expressions.

My algorithm should be something like

  1. for each YouTube link
  2. find the video id
  3. use the video id to make a YouTube thumbnail URL
  4. insert YouTube thumbnail URL into the link's <a>

it looks like the regular expression functions in ruby want to do everything in one line, so I am not clear on how to approach a multi-step find and replace.

I would appreciate some direction.

Weston
  • 1,481
  • 1
  • 11
  • 31

1 Answers1

0

You could follow this approach (this is js though and needs to be ported to ruby):

https://jekyllcodex.org/without-plugin/open-embed/

Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60