I'm using Jekyll to host a site on Github pages. The problem lies in referencing file paths within css files.
I'd like to do something like this:
body { {background: #FFF url('{{ site.baseurl}}/images/page_bg.JPG') center 0 no-repeat; background-attachment: fixed; color: #4b595f; }
But it doesn't seem that Jekyll process the css files, so site.baseurl never gets swapped out.
There are other situations where I can't just change it to an inline style, so assume that's not a possibility.
When you run jekyll serve locally, it starts a web server, usually at http://localhost:4000 , that you use to preview your site during development.
Base URL: The consistent part or the root of your website's address. For example, http://www.YourDomain.com. Relative URL: The remaining path given after the base URL. For example, /contact_us, /seo/blog/new_post.
When you deploy to GitHub Pages, the base URL of your website has the following structure: https://{org}.github.io/{repo} . A subdomain is created for your GitHub organization and your repository's name is appended as a fixed path.
Using the trick from Brian Willis' answer won't work with SASS in @import
-ed files.
Instead, you can do this:
main.scss
---
---
$baseurl: "{{ site.baseurl }}";
@import "myfile";
_sass/_myfile.scss
myclass {
background: url($baseurl + "/my/image.svg");
}
Don't forget
"{{ site.baseurl }}"
(important in case of empty site.baseurl
, and probably more robust) and$baseurl + "/my/image.svg"
.Jekyll processes all files that have YAML front matter. Stick a front matter section (even if it's empty) at the beginning of your file, and Jekyll will transform it correctly. Try using this at the start of the file:
---
title: CSS stylesheet
---
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With