I have a site hosted on GitHub pages, using Jekyll and Markdown code.
It seems like Jekyll doesn’t render any code that’s not in Markdown properly. I have custom JavaScript code to embed that’s supposed to allow users to make donations to my Stripe payment account. The JavaScript code is directly from Stripe, with HTML tags and everything. But Jekyll renders the code by printing most of it. I suppose because it’s not in Markdown code.
Unless it’s a one-off for a single page, I would include the snippet in the post’s/page’s template. If the snippet should be included on some pages, you can use a custom front matter variable to enable/disable the snippet. Alternatively, you could create an include with the snippet and include it in your markdown files where you need it.
@MichaelCurrin The link is not working. I would like to see javascript embedded in md. This is possible, and I would like to use it with jekyll. I use Pandoc to convert, but want to change the game.
I renamed the file - see below. My script tag is at the bottom of the file (It doesn’t need to be in head) but it could easily be in an includes file or a layout.
There aren’t layouts in repo to shared but I assume you shared file because header-includes variable gets inserted into the head tag.
@MichaelCurrin thanks, can I include a js file instead of pasting code at the bottom? There is header-includes in markdown, but it does not work maybe.
And if your default layout uses a head.html includes such as below, then put it in head.html.
{% include head.html %}
<body>
{% include header.html %}
{{ content }}
</body>
Remember that head is for metadata and assets the user can’t see even when they are loaded. body is what they can see - is control how images and text and assets appear for the user.
And in the body you might have a header tag which contains the navbar and site logo. And it might exist as its own header.html includes file.
See minima theme as a reference for layouts and includes
I got the header-includes from Pandoc: Pandoc - Pandoc User’s Guide
… and Pandoc is not Markdown, but a parser as probably Jekyll is.
I am trying to follow up with you, thanks for the help.
thanks, can I do: {% include foo.js %} in a .md so that the js gets interpreted? I still think that is not possible in a .md file, only in a .html.
In a md, with include I get the raw js code which I do not want.
What do you mean interpreted? Versus raw? I need to see the code you are getting and the code you expect.
Using includes means Jekyll copies the content of the includes file (whether JS or markdown or HTML) into the the current page.
And then evaluates and Liquid e.g. {{ }}
If the extension is .md then you can put markdown in it.
- [a](https://example.com)
{% include foo.md %}
There is nothing magical about the JS extension for an includes file. Jekyll will not run or convert your JavaScript. It will only copy the contents of the includes file into the page so the browser and execute it.
As I mentioned before, put your JS in an HTML file. This will cause less confusion and is more Jekyll style.