assemble / assemble-permalinks

Permalinks plugin for assemble (0.6+)
MIT License
5 stars 2 forks source link

Permalinks not rendering pages added using glob or filename #9

Open markdorrill opened 8 years ago

markdorrill commented 8 years ago

Hi,

I've been learning assemble all week (previously knowing the grunt version), it really looks like powerful set of tools.

I've just been attempting to get a basic site outline set using the blog example from the main assemble repo. My aim is to use and this and submit a pr of a working example for other beginners.

The possible bug: It looks like pages are not rendering with permalinks when they have been added to a collection using a glob or single filename.

Also; what is the method to define new permanlink variables as :site.base returns a Failed to read error?

Here is my assemblefile that outlines a scenario to demonstrate this:

'use strict';

var path = require('path');
var extname = require('gulp-extname');
var permalinks = require('assemble-permalinks');
var getDest = require('view-get-dest');
var assemble = require('assemble');
var app = assemble();

/**
 * Plugins
 */

app.use(getDest());
app.use(permalinks());

app.data({
  site: {
    base: 'setfromdata'
  }
});

/**
 * Create views collection for our site pages and blog posts.
 * Posts will be written in markdown.
 */

app.create('pages');
app.create('posts', {
  pager: true,
  renameKey: function(key, view) {
    return view ? view.basename : path.basename(key);
  }
});

// add a page

/**
 * Register a handlebars helper for processing markdown.
 * This could also be done with a gulp plugin, or a
 * middleware, but helpers are really easy and provide
 * the most control.
 */

app.helper('markdown', require('helper-markdown'));
app.helper('link-to', require('helper-link-to'));
//app.helper('helper-not', require('assemble-helper-not'));

app.helper('log', function(val) {
  console.log(val);
});

/**
 * Tasks for loading and rendering our templates
 */

app.task('load', function(cb) {
  console.log('hello from load');

  app.page('thisis.md', {content: '...'}); // permalinks - works
  app.page('home.md', {content: '...'}); // permalinks - works

  app.page('src/templates/pages/blog.hbs'); // permalinks - not working

  app.partials('src/templates/includes/*.hbs'); // permalinks - not working
  app.layouts('src/templates/layouts/*.hbs'); // permalinks - not working
  app.pages('src/templates/pages/*.hbs'); // permalinks - not working
  app.posts('src/content/*.md'); // permalinks - working ** but rendering outside the dest folder **
  cb();
});

/**
 * Default task
 */

app.task('default', ['load'], function() {

  return app.toStream('pages')
    .pipe(app.toStream('posts'))
    .on('error', console.log)
    .pipe(app.renderFile('md'))
    .on('error', console.log)
    .pipe(extname())
    .pipe(app.permalink(app.data('site.base') + '/site/:name.html'))
    //.pipe(app.permalink(app.data(':site.base/site/:name.html'))) // Failed to read: :site.base/site/:name.html
    .pipe(app.dest('dest-example'));
    /*
    .pipe(app.dest(function(file) {
      file.path = file.data.permalink;
      file.base = path.dirname(file.path);
      return file.base;
    }));*/
});

/**
 * Expose your instance of assemble to the CLI
 */

module.exports = app;
assemblebot commented 8 years ago

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

markdorrill commented 8 years ago

Additionally, posts are getting rendered outside the set dest folder. I don't understand why this is?

markdorrill commented 8 years ago

Version: npm assemble -v 2.15.5

Output: [14:25:47] using cwd ~/workspace/md-digital-frontend/example [14:25:48] using assemblefile ~/workspace/md-digital-frontend/example/assemblefile.example.js [14:25:49] starting assemble [14:25:49] starting assemble:default task [14:25:49] starting assemble:load task hello from load [14:25:49] finished assemble:load task [14:25:50] finished assemble:default task [14:25:50] finished assemble 1s [14:25:50] ✔ finished

doowb commented 8 years ago

Hi @markdorrill will you clean up the formatting of the code examples? You can edit the original post and use 3 ticks for blocks of code:

```js
var foo = 'bar';


I'll take a closer look in a little bit. I think some things have changed since the blog example was done, so it might just be a documentation update that's needed.
markdorrill commented 8 years ago

Thanks, that would be a great help.

I've cleaned up the op. Btw, I'm not using the blog example verbatim as I could see some bits were outdated (view events) so reduced it down in simplicity to where it is working.

When the permalinks line is disabled used in the default task, a full list of files is rendered (just comment out the .pipe(app.permalink in default task), hence the issue in this repo.

markdorrill commented 8 years ago

UPDATE: I took another look and everything is being rendered, just in 3 different locations I didn't notice

pages added by object in assemblefile: dest (desired location) glob added posts ../../ from dest glob added pages ../../../ from dest

looks like its something to do with paths that I don't understand.