assemble / grunt-assemble-permalinks

Permalinks middleware for Assemble, the static site generator for Grunt.js and Yeoman. This plugin enables powerful and configurable URI replacement patterns, presets, uses Moment.js for parsing dates, and much more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't get exclusions to work

andymcfee opened this issue · comments

I have a small project where I have 3 pages:

  • index.hbs
  • about.hbs
  • 404.hbs

I'm using assemble permalinks to get a :basename/index.html structure. Works great for index.hbs and about.hbs. But I want 404.hbs to put 404.html in the root, not 404/index.html.

This is my current configuration:

Folder structure

app/
└── assemble/
    ├── layouts/
    ├── partials/
    └── pages/
          ├── index.hbs
          ├── about.hbs
          └── error-page/
               └── 404.hbs

Gruntfile.js

assemble: {
  options: {
    flatten: true,
    layout: 'default.hbs',
    layoutdir: '<%= yeoman.app %>/assemble/layouts',
    assets: 'dist/img',
    partials: ['<%= yeoman.app %>/assemble/partials/*.hbs'],
    helpers: ['helper-path'],
    plugins: ['permalinks'],
    permalinks: {
      exclusions: ["404.hbs", "404"],
      structure: ':basename/index.html'
    }
  },
  pages: {
    files: {
      '.tmp/': [
        '<%= yeoman.app %>/assemble/pages/*.hbs'
      ]
    }
  },
  root: { // These pages should go in the root directory
    option: {
      permalinks: {
        structure: ':basename.html'
      }
    },
    files: {
      '.tmp/': [
        '<%= yeoman.app %>/assemble/pages/error-pages/*.hbs'
      ]
    }
  }
},

But it still builds the 404 page to `404/index.html

I tried moving the permalinks options into the pages target like so:

pages: {
  option: {
    plugins: ['permalinks'],
    permalinks: {
      structure: ':basename/index.html'
    }
  }
  files: {
    '.tmp/': [
      '<%= yeoman.app %>/assemble/pages/*.hbs'
    ]
  }
},

But then permalinks didn't work at all.

I'm sure I'm going something wrong here, but I've tried everything. Thanks in advance for any help.

I'll look into it today, thanks for reporting this

Ah, wait, I know why it's not working. The exclusions feature is for properties on the root context, like basename, ext, etc.

You should be able to do what you need with normal minimatch exclusion patterns:

Gruntfile.js

assemble: {
  options: {
    flatten: true,
    layout: 'default.hbs',
    layoutdir: '<%= yeoman.app %>/assemble/layouts',
    assets: 'dist/img',
    partials: ['<%= yeoman.app %>/assemble/partials/*.hbs'],
    helpers: ['helper-path'],
    plugins: ['permalinks'],
    permalinks: {
      structure: ':basename/index.html'
    }
  },
  pages: {
    files: {
      '.tmp/': [
        '<%= yeoman.app %>/assemble/pages/*.hbs',
        '!<%= yeoman.app %>/**/404.*'
      ]
    }
  }
},

Let me know if this works for you

Great, I've got it working now. I swear I tried it a similar way to this once before... Must have had a syntax error or something..

Thanks for your help!

No worries! I'm happy to help