I was wondering about integrating JavaScript into my Software Design blog and Markdown clearly didn’t support HTML… at least that was what I thought. I still made Jekyll import my JavaScript code on my request.
There are several ways to include JavaScript on demand using Jekyll.
- RAW HTML which looked messy but it does work
- Modify the header code generated by Jekyll to import JavaScript into the Post
- Modify the header code generated by Jekyll to use a script element
I rejected option 1, though I may use it one day, because it is just messy. Everything must be tightly aligned on the left of the text which is okay for something short but terrible for longer scripts.
I rejected option 2 because I seem to prefer having my javascript loaded remotely rather than having it embedded into my page. In the end it isn’t much different than option 3.
I took the option of having Jekyll generate a separate script element to import multiple scripts from a remote location. I just add a tag at the top of the post and my script is loaded and ready to run.