尽管_config.yml,_site中的Jekyll clobbering目录。

时间:2016-01-27 04:45:33

标签: gulp jekyll

我正在与Jekyll建立一个网站并使用Gulp来管理资产。由于我正在使用Gulp来管理我的资产,我希望Jekyll在转换过程中忽略./assets并在构建网站的其余部分时单独留下./_site/assets/。

我已经使用

配置了_config.yml
for (i=1; i<3; i++) { for (j=1; j<3; j++) 
{ 
    div2.innerHTML = div1.innerHTML.replace("^",i).replace("!",j); 
} 

我的gulpfile.js是:

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

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');
});

当我运行gulp jekyll build 时,会按预期创建./_sites/assets/目录,但是当我运行gulp时,会删除./_site/assets/。我缺少什么配置?

1 个答案:

答案 0 :(得分:2)

如前所述,keep_files指令是正确的,而不仅仅是保持。以下来自Jekyll网站http://jekyllrb.com/docs/configuration/

的信息
  

在网站构建上清理目标文件夹的内容    默认情况下,站点何时自动清除   建成。不是由您的站点创建的文件或文件夹   除去。某些文件可以通过在其中指定来保留    配置指令。不要使用重要的位置   为相反,将其用作临时区域并复制文件   从那里到你的网络服务器。

我决定通过一步一步的做法来检查这一点 我附加到默认jekyll的_config.yml文件的部分看起来像这样

exclude: [someFolderHere]  
keep_files: [someFolderHere]
  

从头开始创建新的jekyll网站

wolf @sloth:〜/ blogs $ jekyll new dummy-blog     新的jekyll网站安装在/ home / wolf / blogs / dummy-blog中。     狼@懒惰:〜/ blogs $ cd dummy-blog /     狼@sloth:〜/ blogs / dummy-blog $

  

检查网站文件夹的内容

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$
  

运行第一次构建

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$
  

再次检查网站文件夹的内容

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 .
  

现在我们有_site文件夹

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$ 
  

在_site

下创建一些文件夹
wolf@sloth:~/blogs/dummy-blog$ mkdir _site/someFolderHere
wolf@sloth:~/blogs/dummy-blog$ touch _site/someFolderHere/toasttoast123
wolf@sloth:~/blogs/dummy-blog$
  

检查这个文件是否在那里......

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$ 
  

再次运行构建

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$
  

检查文件toasttoast123是否仍然存在

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$ 
  

在修改之前为_config.yml创建备份

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

添加exclude和keep_files指令并将编辑后的文件与备份进行比较

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$ 
  

再次创建someFolderHere和dummy toasttoast123文件

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

运行构建

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$
  

检查文件是否仍然存在

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$