Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding a directory from Jekyll watch

Tags:

jekyll

I'm using Jekyll 3.1.1 to generate a blog and I recently introduced a Git hook to automatically publish changes pre-push.

After introducing this hook, I have started getting the following error when I run jekyll serve:

Configuration file: /Users/egillespie/Projects/blog.givingjar.org/_config.yml
            Source: /Users/egillespie/Projects/blog.givingjar.org
       Destination: /Users/egillespie/Projects/blog.givingjar.org/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
                    done in 0.223 seconds.
        ** ERROR: directory is already being watched! **

        Directory: /Users/egillespie/Projects/blog.givingjar.org/node_modules/git-scripts/bin/hooks

        is already being watched through: /Users/egillespie/Projects/blog.givingjar.org/node_modules/git-scripts/bin/hooks

        MORE INFO: https://github.com/guard/listen/wiki/Duplicate-directory-errors
 Auto-regeneration: enabled for '/Users/egillespie/Projects/blog.givingjar.org'
Configuration file: /Users/egillespie/Projects/blog.givingjar.org/_config.yml
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

What's peculiar is that I am excluding node_modules in _config.yml:

exclude:
  - Gemfile
  - Gemfile.lock
  - LICENSE
  - README.md
  - package.json
  - Gruntfile.js
  - node_modules

node_modules is correctly being excluded from building (i.e. there is no node_modules subdirectory in _site).

I'm also excluding node_modules in .gitignore:

# project
node_modules
_site*
.sass-cache
.jekyll-metadata

# general
.DS_Store
Thumbs.db
ehthumbs.db

Based on this GitHub issue and this commit it seems like node_modules should be excluded from the watch, but it's not. I can't decipher from the documentation if there's another way to exclude files from the watch.

What is the proper way for me to exclude a directory from the watch and avoid the error described above?

like image 723
Erik Gillespie Avatar asked Feb 09 '16 20:02

Erik Gillespie


3 Answers

Try this to your _config.yml:

keep_files: [node]

where node is a folder to exclude from the --watch. What this will do is keeping the folder node untouched by jekyll build. Then add all files that you want to keep in the site root but not rendered by Jekyll.

like image 50
Virtua Creative Avatar answered Nov 20 '22 11:11

Virtua Creative


The value for exclude parameter in _config.yml should be an array i.e.

exclude: ['_site', 'node_modules', ...]

Source: Jekyll Documentation - Configuration

like image 2
Jabran Rafique Avatar answered Nov 20 '22 12:11

Jabran Rafique


Judging by the paths displayed in your output, you're on macOS. The jekyll-watch gem is responsible for this area (watch/rebuild features), which itself depends on the 'listen' gem. The listen gem itself uses the rb-inotify gem as a dependency, which has several issues with macOS specifically and its filesystem. This results in several bugs in regeneration behaviour that aren't not easy to fix. Background and relevant bugs:

  • https://github.com/guard/listen/issues/274
  • https://github.com/guard/listen/pull/273

You can try using the 'polling' method: https://github.com/guard/listen#listen-adapters instead, but it's much slower.

like image 1
cmaceachern Avatar answered Nov 20 '22 12:11

cmaceachern