jnordberg / wintersmith

A flexible static site generator
http://wintersmith.io/
MIT License
3.5k stars 332 forks source link

Showing a thumbnail for each post #305

Closed SimplGy closed 8 years ago

SimplGy commented 8 years ago

I'd like to show an image thumbnail for each post on my home page. I could use an absolute path easily, but wintersmith assembles local images so nicely already I'd like to re-use that feature.

Here's what I'm trying:

each article in articles
  article.article.intro
    img(src='articles/'+ article.dir +'/'+ article.metadata.thumb)

Where article.metadata.thumb is:


---
title: How to Install Click Flooring in a van
template: article.jade
thumb: click-flooring-in-van.jpg

---

And the article uses that local image elsewhere so it gets put into the content tree just fine.

The missing piece is the article.dir -- is there a good way to get that?

jnordberg commented 8 years ago

Try this, didn't test it but should work

each article in articles
    article.article.intro
      img(src=env.plugins.MarkdownPage.resolveLink(article, article.metadata.thumb, env.config.baseUrl))
SimplGy commented 8 years ago

Wow you're fast. I did this:

img(src=article.filepath.relative.split('/').slice(0, -1).join('/') +'/'+ article.metadata.thumb)

Works, but let me try your way, looks much better.

SimplGy commented 8 years ago

Fantastic. I'd probably recommend others who do this guard the thumbnail path because resolveLink doesn't like to get an undefined, but it works great:

if article.metadata.thumb
  img(src=env.plugins.MarkdownPage.resolveLink(article, article.metadata.thumb, env.config.baseUrl))