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

Make the ignoring of 'index' files an option #53

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions Gruntfile.js
Expand Up @@ -220,6 +220,18 @@ module.exports = function(grunt) {
{expand: true, cwd: 'test/fixtures/pages', src: ['**/*.hbs'], dest: 'test/actual/index_pages/', ext: '.html'}
]
},
// Should add basename to index if told to
index_pages_override: {
options: {
permalinks: {
ignoreIndexFiles: false,
structure: ':basename/index:ext'
}
},
files: [
{expand: true, cwd: 'test/fixtures/pages', src: ['**/*.hbs'], dest: 'test/actual/index_pages/', ext: '.html'}
]
},
// Should properly calculate dest path for collections
collections_pretty: {
options: {
Expand Down
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -325,7 +325,17 @@ options: {

#### 'index' pages

Note that permalink structures will be ignored for files with the basename `index`. See [Issue #20](https://github.com/assemble/permalinks/issues/20) for more info.
Note that permalink structures will be ignored by default for files with the basename `index`. See [Issue #20](https://github.com/assemble/permalinks/issues/20) for more info.

If you don't want to ignore `index` files, you can set the option `ignoreIndexFiles` to `false`:

```js
options: {
permalinks: {
ignoreIndexFiles: false
}
}
```


### preset
Expand Down
7 changes: 6 additions & 1 deletion index.js
Expand Up @@ -46,6 +46,11 @@ module.exports = function (assemble) {
// Slugify basenames by default.
opts.slugify = true;

// Ignore files with a basename of 'index' by default
if (_.isUndefined(opts.ignoreIndexFiles)) {
opts.ignoreIndexFiles = true;
}

// Get the permalink pattern to use from options.permalinks.structure.
// If one isn't defined, don't change anything.
var structure = opts.structure;
Expand Down Expand Up @@ -97,7 +102,7 @@ module.exports = function (assemble) {
if(_.isUndefined(opts.structure) && _.isEmpty(permalink)) {
page.data.dest = page.dest = page.data.dest || page.dest;
} else {
if (page.data.basename === 'index') {
if (opts.ignoreIndexFiles && page.data.basename === 'index') {
page.data.dest = page.dest = page.data.dest || page.dest;
} else {
page.data.dest = page.dest = path.join(page.data.dirname, permalink).replace(/\\/g, '/');
Expand Down