Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何不处理source目录下某个子目录的所有文件,仅仅是将其copy到public目录中对应目录? #1146

Closed
gejiawen opened this issue Mar 25, 2015 · 14 comments

Comments

@gejiawen
Copy link

现在有这样一个需求,这里的所有文件包括html、css、js、md等等任何一种文件。我需要的仅仅是希望hexo在generator的时候简单的将这个目录copy到public目录中而不做任何处理。

在官网上有看到skip_render这个配置,但是毫无示例,不知如何下手。

望知道如何做的告知。 @tommy351

@Xuanwo
Copy link
Contributor

Xuanwo commented Mar 26, 2015

http://xuanwo.org/2014/08/14/hexo-usual-problem/
通过另外一种方法实现了,你可以Ctrl+F搜索在主目录下添加README.md文件或者html文件

@gejiawen
Copy link
Author

@Xuanwo 这方法我知道,不过太搓太猥琐。还是想要一种比较normal的方法来做。

@gejiawen
Copy link
Author

skip_render这个参数,我看了下源码,发现做的事仅仅是跳过检测,除此之外貌似没有做其他的事情。

@Xuanwo
Copy link
Contributor

Xuanwo commented Mar 26, 2015

我去看了一下官网的配置,猜测应该是source/norender这个样子,你试试看?

@Alex1990
Copy link

@Xuanwo 我在主题的source目录下添加了README.md,但还是渲染成了README.html,并删除了README.md

@Xuanwo
Copy link
Contributor

Xuanwo commented Apr 1, 2015

尝试了X种可能之后,我总算研究出来了= =。

比如说现在source下有两个文件夹,一个是_post,一个是haha,里面各有一个名为hello-world.md的文档,然后我的skip_render参数为:
skip_render: haha/*.md
那么,hexo g之后的结果为:

INFO  Files loaded in 503 ms
INFO  Generated: js/script.js
INFO  Generated: fancybox/jquery.fancybox.pack.js
INFO  Generated: fancybox/jquery.fancybox.js
INFO  Generated: fancybox/jquery.fancybox.css
INFO  Generated: fancybox/helpers/jquery.fancybox-thumbs.js
INFO  Generated: fancybox/helpers/jquery.fancybox-thumbs.css
INFO  Generated: fancybox/helpers/jquery.fancybox-media.js
INFO  Generated: fancybox/helpers/jquery.fancybox-buttons.js
INFO  Generated: fancybox/helpers/jquery.fancybox-buttons.css
INFO  Generated: fancybox/helpers/fancybox_buttons.png
INFO  Generated: fancybox/fancybox_sprite@2x.png
INFO  Generated: fancybox/fancybox_sprite.png
INFO  Generated: fancybox/fancybox_overlay.png
INFO  Generated: fancybox/fancybox_loading@2x.gif
INFO  Generated: fancybox/fancybox_loading.gif
INFO  Generated: fancybox/blank.gif
INFO  Generated: css/style.css
INFO  Generated: css/images/banner.jpg
INFO  Generated: css/fonts/fontawesome-webfont.woff
INFO  Generated: css/fonts/fontawesome-webfont.ttf
INFO  Generated: css/fonts/fontawesome-webfont.svg
INFO  Generated: css/fonts/fontawesome-webfont.eot
INFO  Generated: css/fonts/FontAwesome.otf
INFO  Generated: haha/hello-world.md    //看这里!看这里!
INFO  Generated: 2015/03/26/hello-world/index.html
INFO  Generated: archives/index.html
INFO  Generated: archives/2015/index.html
INFO  Generated: archives/2015/03/index.html
INFO  Generated: index.html
INFO  29 files generatd in 1.28 s

也就是说,skip_render参数的使用需要注意两点:

  • 此处的位置是相对于你的source_dir的位置,一般来说,就是以source为根的位置
  • 这里的文件匹配是基于正则的,大致上可以参考这个,也就是说*.html可以忽略所有html文档,hello-wordl.md的话,就能忽略掉名字为hello-wordl.md的文件。

以上。

updated1:
skip_render使用了minimatch,开始匹配的位置是基于你的source_dir的,一般来说,是你的source文件夹下。下面我分别列举几种常见的情况进行说明:

请注意yml中的文件格式,输入单个数据请注意空格,输入数组请进行缩进

  1. 单个文件夹下全部文件:skip_render: test/*
  2. 单个文件夹下指定类型文件:skip_render: test/*.html
  3. 单个文件夹下全部文件以及子目录:skip_render: test/**
  4. 多个文件夹以及各种复杂情况:
skip_render:
    - `test1/*.html`
    - `test2/**`

@Alex1990
Copy link

Alex1990 commented Apr 1, 2015

Thanks!
我下班回去试试,不过skip_render参数好像3.0.0之后才支持吧,目前我还是用的2.8.3。

@gejiawen
Copy link
Author

gejiawen commented Apr 2, 2015

@Xuanwo 官网文档太简略的锅。

@Xuanwo
Copy link
Contributor

Xuanwo commented Apr 10, 2015

解决了就close掉吧,遇到相似问题再ref就是。

其实,也不能怪官方文档,这玩意儿想说清楚确实有点。。。费劲。。

@shawlang
Copy link

shawlang commented Aug 9, 2015

@Xuanwo 您好,我也遇到这个问题。我的需求是:展示一些前端小项目,所以我需要跳过全部source一整个文件夹。

但是skip_render: project 这个怎么配置都不行,试了:source/project project project/* project/*.*等各种配置,都提示404错误。 然后把文件夹下html文件 开头添加一个layout:false反而管用。

有什么办法不? 😊

@Xuanwo
Copy link
Contributor

Xuanwo commented Aug 9, 2015

你可以尝试一下project/**

我之前的回复已经更新了~

@tiodot
Copy link

tiodot commented Apr 8, 2017

更新最新版hexo 后,需要跳过多个目录或者文件:

skip_render: ['*.html', demo/**, test/*]

亲测可用,自用~

@xu-song
Copy link
Contributor

xu-song commented Oct 25, 2018

怎样跳过 任何以 "abc"开头的文件和文件夹

_posts/**/abc** 不起作用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants
@gejiawen @shawlang @Alex1990 @JLHwung @Xuanwo @tiodot @xu-song and others