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.
MIT License
43 stars 11 forks source link

Dynamically build slugs dosen't work #67

Open olegmeglin opened 8 years ago

olegmeglin commented 8 years ago

My Scripts version: grunt-assemble: 0.4.0 grunt-assemble-permalinks: 0.1.0

The documentation describes how to dynamically build slugs: https://github.com/assemble/grunt-assemble-permalinks#dynamically-build-slugs

When I'm trying to render my HTML pages, the variables (<%= area %> & <%= section %>) are not resolved.

I get the following render: blog/2014/01/01/<%= area %>-<%= section %>/index.html

Instead of: blog/2014/01/01/business-finance/index.html

I also download the clear grunt-assemble-permalinks-master from Github. Then I added the variables to the file /test/fixtures/pages/articles/bar.hbs:


---
title: Bar
author: Jon Schlinkert

area: business
section: finance
slug: <%= area %>-<%= section %>

date: 2013-10-03
section: blog
tags:
- bbb

---

After that I executed grunt default. Same behavior.

Now I got the folowing render: test/actual/yfm_custom_property/articles/<%= area %>-<%= section %>/index.html

Instead of: test/actual/yfm_custom_property/articles/business-finance/index.html

Any idea how to fix the issue?

assemblebot commented 8 years ago

@meglinmedia Thanks for the issue! If you're reporting a bug, please be sure to include:

jonschlinkert commented 8 years ago

As a test, try adding the following object to the assemble options in your Gruntfile.js:

{
  data: {
    area: 'one',
    section: 'two'
  }
}

Then run it and see if that data is used in the permalinks. I want to narrow down where the issue is

olegmeglin commented 8 years ago

I'm unsure if I have understood correctly...

Like that?

    assemble: {
      options: {
        plugins: ['index.js'],
        helpers: [
          'handlebars-helper-eachItems',
          'handlebars-helper-paginate',
          'test/fixtures/helpers/*.js'
        ],
        layout: 'test/fixtures/default.hbs',
        assets: 'test/assets',
        data: {
          area: 'one',
          section: 'two'
        }
      },

      // Should modify dest path using a custom property from YAML front matter
      yfm_custom_property: {
        options: {
          permalinks: {
            // 'slug' is a custom property in YAML front matter
            structure: ':slug/index:ext'
          }
        },
        files: [
          {expand: true, cwd: 'test/fixtures/pages', src: ['**/*.hbs'], dest: 'test/actual/yfm_custom_property/', ext: '.html'}
        ]
      },

    },