I’m trying to remove all the inline scripts from our jekyllrb project. The inline scripts pull some values from jekyll data eg. {{site.homepage_title}} , which throws an error when moved to an external/standalone javascript file.
I try renaming the javascript file for example search.js to search.js.liquid but it doesn’t work.
Any ideas or workaround would be much appreciated. Thanks!
jekyll is a static site generator - you run it and it creates the files in the _site folder. Once that is done there is not more concept of liquid or front matter - those are both used in the process of building what is in the _site folder.
So you cannot put liquid into a JS file and expect it to do anything - other than maybe at build time in which case you would need to have front matter in the js file so it is processed.
You probably should give a specific example of what you are trying to do.
You probably should give a specific example of what you are trying to do.
What I’m trying to do is to remove inline scripts from the .md file which is later translated into a static HTML file. The inline scripts there contains a logic that pulls variable from {{}} and some other performs conditional statements {% %} making it a bit difficult to move into a separate js file.
The purpose of moving the inline scripts is for preparation of adding Content-Security-Policy: script-src 'self' header
It would be better if you could specifically share one of these scripts, how it currently works, and how you would like the site to work at the end. Please share some code, so we better understand the need.
I have posted the code here but for some reason it gone through the forum’s admin/moderator for a review and that takes a while for them to show the reply. Nonetheless, I found @ashmaroli answer to be the solution. Thank you!