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
Make the ignoring of 'index' files an option #53
Conversation
Can you describe the use case(s) for this? What are some scenarios where you would want file paths for index files to be re-written? I don't remember and haven't had a chance to look, but will this effect calculation of file paths, such as related:
Also, before we consider merging this we'll need to have tests (just additional targets in the Gruntfile) to show that it doesn't break anything else. I'm not too keen on the semantics either, but it's probably better than |
My use case is that, I have a separate build task for blog posts (mostly because I use a different layout file for them). My structure is
Like I said, this may not be useful for anyone but me, and there might be better ways to handle this. When I was playing around with older versions of Assemble, I used the |
thanks for the detail! and no problem, I'm open to whatever makes sense, I just want to understand the use case a little better first. Interesting, so
to clarify, do you mean a separate "target"? something like:
How are you defining layouts? And how are you actually defining the src-dest stuff in the task? Maybe we should start with these things and go from there. |
it would be great if you could post an example of your |
Yes, that how i use the I use Gulp, hence the "task" terminology, but yes, same thing as using multiple targets in Grunt. Here's a simplified version of my var path = require('path');
var gulp = require('gulp');
var assemble = require('gulp-assemble');
var assembleOptions = {
assets: 'public/assets',
layoutdir: 'src/templates/layouts',
partials: 'src/templates/partials/*.hbs',
layout: 'default.hbs',
helpers: ['src/helpers/*.js'],
middleware: ['assemble-middleware-permalinks'],
permalinks: {
structure: ':mybasename/index.html',
replacements: [
{
// Custom replacements to work around the final filename being set as 'index/index.html'
pattern: ':mybasename',
replacement: function() {
var basename = this.basename;
if (basename === 'index') {
basename = path.basename(path.dirname(this.src));
}
return basename;
}
}
]
}
};
gulp.task('assemble-pages', function() {
return gulp.src('src/pages/**/*.{hbs,md}')
.pipe(assemble(assembleOptions))
.pipe(gulp.dest('public'));
});
gulp.task('assemble-posts', function() {
var options = _.extend({}, assembleOptions, {
layout: 'post.hbs',
permalinks: _.extend({}, assembleOptions.permalinks, {
ignoreIndexFiles: false
})
});
return gulp.src('src/posts/**/*.{hbs,md}')
.pipe(assemble(options))
.pipe(gulp.dest('public/posts'));
}); I'm feeling more and more like I'm going about things entirely the wrong way here. I don't want you to waste your time on this if I'm way off target :) |
thanks again for the detail! you're not at all wasting anyone's time - it's great to have an opportunity to hear how assemble is being used. I wish I could get more users to share what they're doing! Let me think about this, I'll try playing around with similar gulp configs locally. In the meantime, have you tried defining layouts in the yaml front matter posts? this would eliminate the need for two different tasks. there are other things we can do if that's not ideal. also, fwiw in v0.5.0 you'll be able to define the actual destination for each file in the front matter as well :-) IMO that's pretty awesome, but I leverage the heck out of front matter - I know some folks have an aversion to it. |
Great to hear that more things will be configurable in the front matter! I love front matter, but I really like my stuff as DRY as possible, so I'd rather not have to add a layout directive to every post. I might write a super small Assemble middleware though, doing something like ("if source file is in the posts folder and doesn't have a layout set in its front matter, set the layout to post.hbs") :) |
that's a good idea. I don't mind writing it up if you want. |
Nah, that's fine. I might look into it later if I feel I need it. Thanks though! |
Not sure if this is useful to anyone else, but… I made the ignoring of 'index' files (as described in #20) an option,
ignoreIndexFiles
. If it is set to false, the definedstructure
will be used to construct the permalink, even for files with a basename ofindex
.