Poet – displaying an author link

I’m still fiddling around with poet, the node.js blog generator and it’s really easy to add additional meta information like an author link for collaboratively driven sites.

Assuming you want to power a site with poet as a multi-user blog, you can easily attach the meta information in the individual MarkDown files:

{{{
    "title" : "Amazing Tutorial",
    "tags"  : [ "JavaScript" ],
    "category" : "Sanity",
    "date" : "2013-07-20",
    "author" : { "nick" : "Jonathan", "url" : "http://jonathanmh.com"} // additional line
}}

After that, these informations will directly be available inside your templates when you render the posts. Assuming the views from the example repository, these are changes you could make to your template files:

post.jade:

extends layout

block content
	article.post
		h1
			a(href=post.url)
				= post.title
		span.date #{post.date.getFullYear()}.#{post.date.getMonth()+1}.#{post.date.getDate()}
		- if (typeof(post.author) != 'undefined')
			span.author
				p  by 
					a(href="#{post.author.url}") #{post.author.nick}

		div.post.content
			!= post.content
		div.tags
			- each tag in post.tags
				a(href=tagUrl(tag))
					span.label.label-info #{tag}

includes/postSnippet.jade

div.post
.script(console.log(#{post}))

	h1
		a(href=post.url)
			= post.title
	span.date #{post.date.getFullYear()}.#{post.date.getMonth()+1}.#{post.date.getDate()}
	- if (typeof(post.author) != 'undefined')
		span.author
			p  by 
				a(href="#{post.author.url}") #{post.author.nick}
	article.post.content
		!= post.preview
	div.tags
		- if (typeof(post.tags) != 'undefined')
			- each tag in post.tags
				a(href=tagUrl(tag))
					span.label.label-info #{tag}

With this method, you can add all kinds of meta information, that you might like with your posts 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *