I've set up my express site with poet recently. I can use post.url and all the locals which are provided to all views, except the url routing - for example, in my blog.jade view:
ul.blog-preview$
each post in postList$
li$
a(href=#{post.url}) #{post.title}$
The view renders fine, but the route express tries when clicking on the post.url: "http://localhost:8080/undefined/post/poet-testundefined" where the post I was trying to reach is called 'poet-test'. So, I tried printing out post.url within the view
p #{post.url}
and to my surprise it printed out fine as post/poet-test. So, obviously I tried browsing to localhost:8080/post/poet-test, but that didn't work either because of a reference error on post.title, which I suspect is a problem because the post is getting lost in routing somehow.
This is my site.js (or app.js as most are called) and I've included what I think must be relevant to solving this.
var express = require('express')
, app = module.exports = express()
, http = require('http')
, poet = require('poet')(app)
poet
.createPostRoute()
.createPageRoute()
.createTagRoute()
.createCategoryRoute()
.init(function(locals) {
locals.postList.forEach(function ( post ) {
console.log('loading post: ' + post.url)
})
})
app.configure(function(){
//...etc
app.use(app.router);
//...etc
app.use(express.static(__dirname + '/public'));
});
//Dev settings
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions:true, showStack:true }));
app.set('port', process.env.PORT || 8080);
app.use(express.logger('dev'));
});
//Production settings
//....etc
// controllers - load them
controllers = ["pages", "blog"]
for (i in controllers) {
controller = require('./controllers/' + controllers[i]);
controller.setup(app)
}
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
As you can see, I check the post.url for each post it loads in poet.init(function(post) { ... }) and each of those check out with the correct /post/title url... so, I'm a little stuck here. Perhaps logging routes somehow with app.router() or a poet specific solution.
Check out the examples in the Poet repo -- You shouldn't have to escape your hrefs.. looks like the urls in Poet are fine, just some wrestling with Jade, try this:
a(href=post.url) post.title
https://github.com/jsantell/poet/blob/master/examples/views/includes/postSnippet.jade#L3