Jekyll clobbering directory in _site despite _conf

2020-03-30 02:39发布

问题:

I'm building a site with Jekyll and using Gulp to manage the assets. Since I'm using Gulp to manage my assets, I would like Jekyll to ignore ./assets in the conversion process and to leave ./_site/assets/ alone when building the rest of the site.

I've configured the _config.yml with

exclude: [assets] # Exclude assets/ from the conversion
keep: [assets]    # Don't delete _site/assets when building the site

My gulpfile.js is:

var gulp = require('gulp');
var sass = require('gulp-ruby-sass');

gulp.task('sass', function() {
  return sass('assets/stylesheets/main.scss')
    .on('error', sass.logError)
    .pipe(gulp.dest('_site/assets/'));
});

gulp.task('default', function() {
  gulp.start('sass');
});

I then run:

gulp
jekyll build

When I run gulp, the ./_sites/assets/ directory is created as expected, but when I run jekyll build ./_site/assets/ is deleted. What configuration am I missing?

回答1:

As was noted before keep_files directive is correct, instead of just keep. Following information from Jekyll's site http://jekyllrb.com/docs/configuration/

Destination folders are cleaned on site builds The contents of are automatically cleaned, by default, when the site is built. Files or folders that are not created by your site will be removed. Some files could be retained by specifying them within the configuration directive. Do not use an important location for ; instead, use it as a staging area and copy files from there to your web server.

I decided to check this by doing things from scratch step by step part that I appended to default jekyll's _config.yml file looks like this

exclude: [someFolderHere]  
keep_files: [someFolderHere]

creating new jekyll site from scratch

wolf@sloth:~/blogs$ jekyll new dummy-blog New jekyll site installed in /home/wolf/blogs/dummy-blog. wolf@sloth:~/blogs$ cd dummy-blog/ wolf@sloth:~/blogs/dummy-blog$

checking contents of site's folder

wolf@sloth:~/blogs/dummy-blog$ ll -rta
total 40
drwxr-xr-x 12 wolf wolf 4096 Jan 30 09:40 ..
-rw-r--r--  1 wolf wolf  435 Jan 30 09:40 _config.yml
drwxr-xr-x  2 wolf wolf 4096 Jan 30 09:40 _layouts
-rw-r--r--  1 wolf wolf  451 Jan 30 09:40 index.html
drwxr-xr-x  2 wolf wolf 4096 Jan 30 09:40 _includes
drwxr-xr-x  2 wolf wolf 4096 Jan 30 09:40 css
drwxr-xr-x  2 wolf wolf 4096 Jan 30 09:40 _posts
-rw-r--r--  1 wolf wolf 1292 Jan 30 09:40 feed.xml
-rw-r--r--  1 wolf wolf  470 Jan 30 09:40 about.md
drwxr-xr-x  6 wolf wolf 4096 Jan 30 09:40 .
wolf@sloth:~/blogs/dummy-blog$

running first build

wolf@sloth:~/blogs/dummy-blog$ jekyll build
Configuration file: /home/wolf/blogs/dummy-blog/_config.yml
            Source: /home/wolf/blogs/dummy-blog
       Destination: /home/wolf/blogs/dummy-blog/_site
      Generating... 
                    done.
wolf@sloth:~/blogs/dummy-blog$

checking contents of site's folder again

wolf@sloth:~/blogs/dummy-blog$ ll -rta
total 44
drwxr-xr-x 12 wolf wolf 4096 Jan 30 09:40 ..
-rw-r--r--  1 wolf wolf  435 Jan 30 09:40 _config.yml
drwxr-xr-x  2 wolf wolf 4096 Jan 30 09:40 _layouts
-rw-r--r--  1 wolf wolf  451 Jan 30 09:40 index.html
drwxr-xr-x  2 wolf wolf 4096 Jan 30 09:40 _includes
drwxr-xr-x  2 wolf wolf 4096 Jan 30 09:40 css
drwxr-xr-x  2 wolf wolf 4096 Jan 30 09:40 _posts
-rw-r--r--  1 wolf wolf 1292 Jan 30 09:40 feed.xml
-rw-r--r--  1 wolf wolf  470 Jan 30 09:40 about.md
drwxr-xr-x  5 wolf wolf 4096 Jan 30 09:41 _site
drwxr-xr-x  7 wolf wolf 4096 Jan 30 09:41 .

now we have _site folder

wolf@sloth:~/blogs/dummy-blog$ ll _site/
total 32
drwxr-xr-x 3 wolf wolf 4096 Jan 30 09:41 jekyll
-rw-r--r-- 1 wolf wolf 5816 Jan 30 09:41 index.html
-rw-r--r-- 1 wolf wolf 2954 Jan 30 09:41 feed.xml
drwxr-xr-x 2 wolf wolf 4096 Jan 30 09:41 css
drwxr-xr-x 2 wolf wolf 4096 Jan 30 09:41 about
drwxr-xr-x 7 wolf wolf 4096 Jan 30 09:41 ..
drwxr-xr-x 5 wolf wolf 4096 Jan 30 09:41 .
wolf@sloth:~/blogs/dummy-blog$ 

creating some folder under _site

wolf@sloth:~/blogs/dummy-blog$ mkdir _site/someFolderHere
wolf@sloth:~/blogs/dummy-blog$ touch _site/someFolderHere/toasttoast123
wolf@sloth:~/blogs/dummy-blog$

checking if this file is this there...

wolf@sloth:~/blogs/dummy-blog$ ll _site/someFolderHere/toasttoast123 
-rw-r--r-- 1 wolf wolf 0 Jan 30 09:42 _site/someFolderHere/toasttoast123
wolf@sloth:~/blogs/dummy-blog$ 

running build again

wolf@sloth:~/blogs/dummy-blog$ jekyll build
Configuration file: /home/wolf/blogs/dummy-blog/_config.yml
            Source: /home/wolf/blogs/dummy-blog
       Destination: /home/wolf/blogs/dummy-blog/_site
      Generating... 
                    done.
wolf@sloth:~/blogs/dummy-blog$

checking if file toasttoast123 is still present

wolf@sloth:~/blogs/dummy-blog$ ll _site/someFolderHere/toasttoast123 
ls: cannot access _site/someFolderHere/toasttoast123: No such file or directory
wolf@sloth:~/blogs/dummy-blog$ 

creating backup for _config.yml before modification

wolf@sloth:~/blogs/dummy-blog$ 
wolf@sloth:~/blogs/dummy-blog$ cp -p _config.yml _config.yml.somebackup

adding exclude and keep_files directives and comparing edited file with backup

wolf@sloth:~/blogs/dummy-blog$ rvim _config.yml
wolf@sloth:~/blogs/dummy-blog$ diff -u _config.yml _config.yml.somebackup 
--- _config.yml 2016-01-30 09:44:26.238366056 +0200
+++ _config.yml.somebackup  2016-01-30 09:40:08.422370474 +0200
@@ -10,6 +10,3 @@
 # Build settings
 markdown: kramdown
 permalink: pretty
-
-exclude: [someFolderHere]
-keep_files: [someFolderHere]    
wolf@sloth:~/blogs/dummy-blog$ 

creating someFolderHere and dummy toasttoast123 file again

wolf@sloth:~/blogs/dummy-blog$ mkdir _site/someFolderHere
wolf@sloth:~/blogs/dummy-blog$ touch _site/someFolderHere/toasttoast123

running build

wolf@sloth:~/blogs/dummy-blog$ jekyll build
Configuration file: /home/wolf/blogs/dummy-blog/_config.yml
            Source: /home/wolf/blogs/dummy-blog
       Destination: /home/wolf/blogs/dummy-blog/_site
      Generating... 
                    done.
wolf@sloth:~/blogs/dummy-blog$

checking if file is still there

wolf@sloth:~/blogs/dummy-blog$ ll _site/someFolderHere/toasttoast123 
-rw-r--r-- 1 wolf wolf 0 Jan 30 09:45 _site/someFolderHere/toasttoast123
wolf@sloth:~/blogs/dummy-blog$ 
wolf@sloth:~/blogs/dummy-blog$ 


标签: gulp jekyll