本文介绍了Jekyll 破坏了 _site 中的目录,尽管 _config.yml.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我已经用 _config.yml 配置了

exclude: [assets] # 从转换中排除 assets/keep: [assets] # 建站时不要删除 _site/assets

我的 gulpfile.js 是:

var gulp = require('gulp');var sass = require('gulp-ruby-sass');gulp.task('sass', function() {return sass('assets/stylesheets/main.scss').on('错误', sass.logError).pipe(gulp.dest('_site/assets/'));});gulp.task('default', function() {gulp.start('sass');});

然后我运行:

gulp杰基尔构建

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

解决方案

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

目标文件夹在站点构建中被清理默认情况下,当站点被自动清理时建成.不是由您的站点创建的文件或文件夹将删除.可以通过在配置指令.不要使用重要的位置为了 ;相反,将其用作暂存区并复制文件从那里到您的网络服务器.

我决定从头开始一步一步地检查这一点我附加到默认 jekyll 的 _config.yml 文件的部分看起来像这样

排除:[someFolderHere]keep_files:[someFolderHere]

从头开始创建新的 jekyll 站点

wolf@sloth:~/blogs$ jekyll new dummy-blog安装在/home/wolf/blogs/dummy-blog 中的新 jekyll 站点.wolf@sloth:~/blogs$ cd dummy-blog/wolf@sloth:~/blogs/dummy-blog$

检查站点文件夹的内容

wolf@sloth:~/blogs/dummy-blog$ ll -rta共 40 个drwxr-xr-x 12 wolf 狼 4096 Jan 30 09:40 ..-rw-r--r-- 1 wolf 狼 435 Jan 30 09:40 _config.ymldrwxr-xr-x 2 wolf 狼 4096 Jan 30 09:40 _layouts-rw-r--r-- 1 wolf 狼 451 Jan 30 09:40 index.htmldrwxr-xr-x 2 wolf 狼 4096 Jan 30 09:40 _includesdrwxr-xr-x 2 wolf 狼 4096 Jan 30 09:40 cssdrwxr-xr-x 2 wolf 狼 4096 Jan 30 09:40 _posts-rw-r--r-- 1 wolf 狼 1292 Jan 30 09:40 feed.xml-rw-r--r-- 1 wolf 狼 470 Jan 30 09:40 about.mddrwxr-xr-x 6 wolf 狼 4096 1 月 30 日 09:40.wolf@sloth:~/blogs/dummy-blog$

运行第一个构建

wolf@sloth:~/blogs/dummy-blog$ jekyll build配置文件:/home/wolf/blogs/dummy-blog/_config.yml来源:/home/wolf/blogs/dummy-blog目的地:/home/wolf/blogs/dummy-blog/_site生成...完毕.wolf@sloth:~/blogs/dummy-blog$

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

wolf@sloth:~/blogs/dummy-blog$ ll -rta共 44drwxr-xr-x 12 wolf 狼 4096 Jan 30 09:40 ..-rw-r--r-- 1 wolf 狼 435 Jan 30 09:40 _config.ymldrwxr-xr-x 2 wolf 狼 4096 Jan 30 09:40 _layouts-rw-r--r-- 1 wolf 狼 451 Jan 30 09:40 index.htmldrwxr-xr-x 2 wolf 狼 4096 Jan 30 09:40 _includesdrwxr-xr-x 2 wolf 狼 4096 Jan 30 09:40 cssdrwxr-xr-x 2 wolf 狼 4096 Jan 30 09:40 _posts-rw-r--r-- 1 wolf 狼 1292 Jan 30 09:40 feed.xml-rw-r--r-- 1 wolf 狼 470 Jan 30 09:40 about.mddrwxr-xr-x 5 wolf 狼 4096 Jan 30 09:41 _sitedrwxr-xr-x 7 wolf 狼 4096 1 月 30 日 09:41.

现在我们有了 _site 文件夹

wolf@sloth:~/blogs/dummy-blog$ ll _site/共 32 个drwxr-xr-x 3 wolf 狼 4096 Jan 30 09:41 jekyll-rw-r--r-- 1 wolf 狼 5816 Jan 30 09:41 index.html-rw-r--r-- 1 wolf 狼 2954 Jan 30 09:41 feed.xmldrwxr-xr-x 2 wolf 狼 4096 Jan 30 09:41 cssdrwxr-xr-x 2 wolf 狼 4096 Jan 30 09:41 关于drwxr-xr-x 7 wolf 狼 4096 Jan 30 09:41 ..drwxr-xr-x 5 wolf 狼 4096 1 月 30 日 09:41.wolf@sloth:~/blogs/dummy-blog$

在_site下创建一些文件夹

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

正在检查该文件是否存在...

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

再次运行构建

wolf@sloth:~/blogs/dummy-blog$ jekyll build配置文件:/home/wolf/blogs/dummy-blog/_config.yml来源:/home/wolf/blogs/dummy-blog目的地:/home/wolf/blogs/dummy-blog/_site生成...完毕.wolf@sloth:~/blogs/dummy-blog$

检查文件 toasttoast123 是否仍然存在

wolf@sloth:~/blogs/dummy-blog$ ll _site/someFolderHere/toasttoast123ls: 无法访问 _site/someFolderHere/toasttoast123: 没有这样的文件或目录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.ymlwolf@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 @@# 构建设置降价:kramdown固定链接:漂亮--排除:[someFolderHere]-keep_files:[someFolderHere]wolf@sloth:~/blogs/dummy-blog$

再次创建 someFolderHere 和虚拟 toasttoast123 文件

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

运行构建

wolf@sloth:~/blogs/dummy-blog$ jekyll build配置文件:/home/wolf/blogs/dummy-blog/_config.yml来源:/home/wolf/blogs/dummy-blog目的地:/home/wolf/blogs/dummy-blog/_site生成...完毕.wolf@sloth:~/blogs/dummy-blog$

检查文件是否还在

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

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?

解决方案

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

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]

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$

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 .
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$ 
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$
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$ 
wolf@sloth:~/blogs/dummy-blog$ 
wolf@sloth:~/blogs/dummy-blog$ cp -p _config.yml _config.yml.somebackup
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$ 
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$ 

这篇关于Jekyll 破坏了 _site 中的目录,尽管 _config.yml.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 19:44