Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the "blog listing logic" out of index.jade #45

Closed
vitch opened this issue Aug 24, 2012 · 6 comments
Closed

Move the "blog listing logic" out of index.jade #45

vitch opened this issue Aug 24, 2012 · 6 comments

Comments

@vitch
Copy link

vitch commented Aug 24, 2012

Firstly, thanks for wintersmith - it looks like a really nice approach to the static site generation problem.

I'm trying to use wintersmith and the swig plugin to build a blog. However it seems like on the default generated site the logic to gather the articles for the homepage and archive page is included in the .jade templates. I can't see how I could replicate this with a swig template.

Should I be creating a content plugin which somehow massages the data into a format which can be output by a logic-less templating language? Or is there some other way to make it so that the index/archive templates are passed just the data they need already sorted/ filtered?

@vitch
Copy link
Author

vitch commented Aug 25, 2012

I had a little look into this to see if I could figure out how to implement it myself and I have created a wintersmith-archive plugin:

https://github.com/vitch/wintersmith-archive

I've never written coffee script before so it's quite possibly a dumb implementation (not understanding coffee script made it tricky for me to get my head around the wintersmith sourcecode as well). But hopefully it is a starting point to discuss whether it is possible to move logic from templates into a ContentPlugin

To use add to your project and then reference in config.json. Now you can replace contents/archive.md from the default example install with contents/archive.json containing the following:

{
  "template": "archive.jade",
  "filename": "archive.html"
}

Then templates/archive.jade becomes:

extends layout

block content

  section.archive
    ul
      each dateData in sortedArticleDates
        li.year= dateData.year
        ul
          each month in dateData.months
            li
              strong= articlesByDate[dateData.year][month].monthName
              each article in articlesByDate[dateData.year][month].articles
                br
                a(href=article.url)= article.title

What do you think? Do you like the idea of making the templates dumber and simpler and having any required logic in a ContentPlugin?

@joefiorini
Copy link

@vitch I just went through this myself. I ended up hacking wintersmith-swig to allow me to pass a custom filters module, then created a file with swig filters to handle most of the logic that is currently done in the Jade template. I'd be happy to share some of the code here next time I'm at my computer; don't have access to it right now unfortunately. Would that help?

@joefiorini
Copy link

@vitch Also, your plugin looks good as long as I want the specific configuration (sorted by date, etc) you return. My solution allows you to define that in your app. However, it's not very "wintersmithy" whereas yours is, so maybe we can find a way to combine approaches?

@vitch
Copy link
Author

vitch commented Aug 30, 2012

@joefiorini I actually moved to DocPad in the meantime... This was one of the problems I ran into while evaluating wintersmith so I decided to have a looks at some other options and I'm currently preferring that...

Agree that my plugin is limited to the specific requirements at hand. It would be great to have it configurable in some manner (rather than a separate plugin for each way you want to slice the data)...

@jnordberg
Copy link
Owner

#56

jnordberg added a commit that referenced this issue May 22, 2013
Fixes #93, #89, #84, #86, #79, #78, #83, #56, #34, #45, #46
@jnordberg
Copy link
Owner

Fixed in 2.0, now everything is PERFECT! ⛵

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants