I'm getting started with Jekyll static site generator and I would like to use Live Reload with it. I know Jekyll has a generator and server commands, and Live Reload can run various compilers and custom commands. How do I configure these to work together?
LiveReload is built into Jekyll 3.7+.
jekyll serve --livereload
You can also set LiveReload's port, delay, and ignored files. See jekyll help serve.
UPDATE: As pointed out in other answers, LiveReload is built into Jekyll 3.7+.
jekyll serve --livereload
For older versions:
The simplest approach I've found that works is to use two terminal windows: One for jekyll serve --watch and one for guard.
I tried the guard-jekyll-plus approach suggested by Nobu but I had a bunch of errors.
As shumushin pointed out, Jekyll can handle the automatic rebuilding process, you simply launch it using jekyll serve --watch
Now to get LiveReload working run guard with guard-livereload in a second terminal window. This is basically the same as Jan Segre's answer, but without guard-jekyll.
My Guardfile looks like this:
guard 'livereload' do
watch(/^_site/)
end
And my Gemfile:
gem 'jekyll'
gem 'guard'
gem 'guard-livereload'
Note: You still need to include the livereload script in your index.html page; it is the "glue" that binds guard-livereload and the browser together.
<script src="http://localhost:35729/livereload.js"></script>
There's guard-livereload which you can use with guard-jekyll and centralize the watching process with guard, an example would be (I haven't tested it):
Install guard-jekyll, either through gem or bundler
Install guard-livereload, either through gem or bundler
Init guard-jekyll
guard init jekyll
Add this to your Guardfile:
guard 'livereload' do
watch(%r{_site/.+})
end
You can adapt the above to suit better your project, and
you probably already know you have to include the livereload
script on your page:
<script src="http://localhost:35729/livereload.js"></script>
Oh, and to start the whole watching mess:
guard
For jekyll 1.0+ use:
jekyll serve --watch
See Jekyll: Basic Usage for more details and options.
UPDATE: this no longer works with the latest version of Jekyll
cd your/site/folder
jekyll --server --auto
This post explains a cleaner way - Setting Up LiveReload With Jekyll
Gemfile:
gem 'jekyll'
gem 'guard'
gem 'guard-jekyll-plus'
gem 'guard-livereload'
Guardfile:
guard 'jekyll-plus', :serve => true do
watch /.*/
ignore /^_site/
end
guard 'livereload' do
watch /.*/
end
Install any LiveReload browser extension. Then run guard.
I wrote a Jekyll plugin called Hawkins that incorporates LiveReload into the Jekyll watch process. It works with Jekyll 3.1 and up.
Simply add
group :jekyll_plugins do
gem 'hawkins'
end
to your Gemfile (and then a bundle install). From there you can run jekyll liveserve. Hawkins will modify the head sections of your pages to include the necessary components for LiveReload, and when Jekyll detects a page change, Hawkins will push a message to your browser via WebSockets. Please note that you will need a browser that supports WebSockets. For very fast reloads, you can use Jekyll's new --incremental option that will only regenerate the changed pages.
Start by running jekyll normally in your site folder:
cd your/site/folder
jekyll
By default Jekyll generates a folder called _site inside it (your/site/folder/_site).
Tell LiveReload to watch that _site folder.
This command will open your website in the browser and uses jekyll built-in livereload server.
bundle exec jekyll serve -l -o
You need a latest jekyll version.
I just started using GitHub Pages today, and wanted to be able to use live reload with Jekyll. Got it working & written my first post on Creating GitHub Pages with Jekyll & LiveReload.
It uses Grunt with the grunt-contrib-watch plugin instead of Jekyll's serve command - works well for me. Hope it works for you as well.
You can use just jekyll serve -w, an option I prefer as I am lazy.
For Live Reload,
Remove Jekyll Admin from Gemfile in the root directory of your project and it works like charm.
If you're running it frequently, the Repla macOS app makes it easy to startup Jekyll so it automatically refreshes. After Repla is installed, you run it from the Jekyll blog's root directory and pass it the jekyll serve command. For example:
repla server "bundle exec jekyll serve --watch --drafts" -r "...done"
Repla will be configured to refresh each time ...done is printed in the console, which Jekyll prints when it finishes compiling your site.
Repla runs the Jekyll server process in a split below a browser split showing your site:
After Jekyll is running in Repla, you can also save the configuration to a file with ⌘S, shut it down by closing the window, and run it again just by double-clicking the file. In other words, you can start your Jekyll blog again next time just by opening the file, without involving the terminal at all.
Disclosure: I maintain the Repla app.
Related
I have a github pages site using the jekyll cayman theme, and I set up a sass stylesheet at assets/css/style.scss
Its contents begin:
---
# Front matter comment to ensure Jekyll properly reads file.
---
//DON'T DELETE THE ABOVE
#import "jekyll-theme-cayman";
and then I have the rest of my sass.
I then run bundle exec jekyll serve.
This used to work to start a server, and watch changes to the sass file and compile them to _site/assets/css/style.css.
I can see that it is picking up that there are changes in the sass file - the console logs: Regenerating: 1 file(s) changed at 2022-10-28 21:22:54 assets/css/style.scss - but nothing gets output to the style.css file. I've tried running bundle exec jekyll serve --watch.
That no longer works, and I'm not sure why. I noticed when I tried to run this for the first time in a while, it complained about nokogiri, so I ran bundle install - maybe that messed things up?
Try bundle exec jekyll clean && bundle exec jekyll serve or one command after the other. Clean removes files and cleans Sass and Jekyll caches. See https://jekyllrb.com/docs/usage/
I have recently made a foray into the Jekyll world. I'm currently exploring this on a local Apache2 server running Bootstrap 3 with a simple responsive layout.
Installation Summary
I just installed ruby, ruby-dev, gcc, make and all appropriate gems. The Jekyll installation guide was great to get it installed and such. I went ahead and create a new blog, 'sudo jekyll new blog' in /var/www/html. Now as, /var/www/html/blog.
Installation Directory
about.md
_config.yaml
Gemfile
Gemfile.block
.gitignore
index.md
_posts
.sass-cache
_site/
Post Installation Configuration
I've edited the _config.yaml file to establish base directories and such, everything looks appropriate.
I fire up the Jekyll instance via: sudo exec jykll serve, which is currently producing.
WARN: Unresolved specs during Gem::Specification.reset:
jekyll-watch (~> 1.1)
rouge (~> 1.7)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Configuration file: /var/www/html/blog/_config.yml
Configuration file: /var/www/html/blog/_config.yml
Source: /var/www/html/blog
Destination: /var/www/html/blog/_site
Incremental build: disabled. Enable with --incremental
Generating...
done in 0.458 seconds.
Auto-regeneration: enabled for '/var/www/html/blog'
Configuration file: /var/www/html/blog/_config.yml
Server address: http://127.0.0.1:4000/blog/
Server running... press ctrl-c to stop.
Issue
The issue that I am having is that when I navigate to localhost/blog, instead of seeing a 'homepage' or index, all I'm seeing is the directory structure as noted above. It's as if the index file isn't rendering or such. However, if I click into _site/, I get something that looks a bit like a classic landing page for the sample post.
Question
What am I missing? Did I mis-configure something? Is this expected behavior?
Thanks!
The problem is that you are looking at the generated files without a web server.
You can run a webserver at the folder that contains _config.yml, just to see that everything goes fine, then you need a "real" web server to serve your pages: $ jekyll serve
After running jekyll serve you will be able to access your website at: http://localhost:4000
Up until a few hours ago, I had my jekyll install working as normal. Having created 26 different posts using my current setup, I'm not expecting something to suddenly not work at all. Ran jekyll build to see the results of a new post I created for my blog. I got an error saying it could not find redcarpet; weird since I have never touched my config or anything since I created it. I ran bundle install no new gems added. For sanity's sake I ran bundle show redcarpet, it could not be found. Okay that's weird. So I run gem install redcarpet v 3.1.0 which was the version I was using pretty much the entire time. I then run bundle install again, checking to see if redcarpet was added...and nope.
I decided to go into my config and switch markdown parser and add kramdown, then run jekyll serve...and now I get that I'm missing kramdown and like redcarpet even if I install via gem install jekyll refuses to acknowledge it's existence.
I tried deleting my gemfile and rebuilding it unfortunately that does nothing. If I run bundle exec jekyll serve it works however redcarpet isn't activated and thus the markdown isn't parsed correctly (And new entries aren't added to the index page).
I'm probably missing something obvious, any direction or advice would be much appreciated.
I've been trying to setup SASS (and Bourbon.io) with jekyll for a personal blog on github pages.
I've changed the name of the css folder that is installed with jekyll to stylesheets and within stylesheets I have two folders, css and sass.
I start my jekyll server locally with: jekyll serve --watch
Then in another terminal window: sass --watch stylesheets/sass:stylesheets/css
But I am now getting the following message:
`/' not found.
Prior to attempting to setup SASS with my jekyll project, my site was displaying. Any links for setting up sass with jekyll would be helpful. Thanks.
New in Jekyll 2.0 is native processing of Sass and CoffeeScript:
http://jekyllrb.com/docs/assets/#sassscss
hope not being to late, for what you are pretending there are many approaches for example i use bourbon, neat in a jekyll project and use grunt tasks for local development.
Another option is to use a rakefile with some task to handle both programs (jekyll and sass) or as favrizio suggested use jekyll's pluging.
I reccomend you to take a look to grunt.
This happens usually if you have messed with the site baseurl in the _config.xml and it can no longer resolve itself to find the index.html.
I am using this guide to add liveReload to Octopress.
http://www.erikzaadi.com/2012/09/16/using-live-reload-with-octopress/
Once I get to 'rake generate && rake watch',
The command line spits out I am missing a specific gem; i.e.'rake-0.9.6', which is strange because I thought by installing the bundle took care of that.
I suspect that bundle is being saved elsewhere; but shouldn't that bundle be saved in the directory of my choosing (i.e. Sites/myproject?)
Add these two entries to your Gemfile, in the :development group:
gem 'guard'
gem 'guard-livereload'
Create a file called Guardfile containing something like:
guard 'livereload' do
watch(%r{public/generated})
watch(%r{public/.+\.(css|js|html)})
end
Start 2 shell tabs running these commands: rake generate && rake watch and guard
`
rake generate && rake watch
`
start guard LiveReload
`
guard
`
It’s neat to get LiveReload working with Octopress. However, the generation can finish after your page does a reload, so you won’t see your latest changes. I’ll update this blog post when I figure out a solution to that one. Until then, you may find it more convenient to manually refresh the blog page yourself.
It’s worth noting that if you’re running any other instance of guard- LiveReload, then one of these two copies will win and one won’t work. If you run a rails server this way, then this can bite you. It took me a bit of time to figure out why guard wasn’t working.
source
http://www.railsonmaui.com/blog/2013/04/27/octopress-setup-with-github-and-org-mode/#sec-4