How would you handle blog posts? #23

Closed
superplussed opened this Issue Sep 3, 2012 · 10 comments

Comments

Projects
None yet
4 participants
@superplussed
Contributor

superplussed commented Sep 3, 2012

Given the current architecture how would you handle blog posts? The only way that I see to do it is to have a json object that references an array of mustache partials, like:

{
  "posts": [
    {
      "partial": "2012-9-1-test"
    }
  ]
}

Then have a partial named _2012-9-1-test.mustache

And in my blog.mustache have mustache loop through and include the partials like:

{{#posts}}
  {{>.}}
{{/posts}}

So two questions:

  • I'd rather have my blog posts be markdown files that are in the content/_blog folder, is this possible?
  • If its not possible, is there any consideration being given to having punch be "blog-aware" in a similar way that jekyll is? The way I could see doing that would be to have in the config.json a setting for "models" to "catalog". So you could say "catalog": ["blog", "portfolio"]. And then node will search the _blog and _portfolio directory for files that fall under a certain format, say year-month-day-title, and then it adds entries to the blog.json and portfolio.json with the parsed contents of the files, along with other data such as num_entries, snippets, etc.

I'd be willing to work on this if you agree on this architecture. If you don't agree, let me know what would make more sense to you.

@laktek

This comment has been minimized.

Show comment Hide comment
@laktek

laktek Sep 3, 2012

Owner

You can create an extended directory for each blog post and include the markdown file inside it. It will look like this:

  • content/blog/_2012-9-1-first-post/content.markdown
  • content/blog/_2012-9-4-second-post/content.markdown

This way it will the render following pages:

  • /blog/2012-9-1-first-post.html
  • /blog/2012-9-4-second-post.html

Then, when generating the site, you can use a generator hook to create the blog index. Generator hooks aren't currently documented. But basically, they are callbacks that will run after generating each page (check this basic console output hook). Its first argument would be the path of the file that was generated (eg. /blog/2012-9-1-first-post). You can use the path to build the link and title of the post and append to a custom blog index page.

Also, we can follow your approach and introduce a special content handler for blogs, which would fetch the posts inside a single directory and create the pages. (Again, content handlers is a cool feature that I need to document. For now you can check the spec of the default content handler and also this example with a custom content handler, if you plan to write a custom content handler)

Anyway, I will be starting to port my own blog to Punch during this weekend. It would allow me to review the process more closely and introduce a more idiomatic way to handle blogs in Punch.

Owner

laktek commented Sep 3, 2012

You can create an extended directory for each blog post and include the markdown file inside it. It will look like this:

  • content/blog/_2012-9-1-first-post/content.markdown
  • content/blog/_2012-9-4-second-post/content.markdown

This way it will the render following pages:

  • /blog/2012-9-1-first-post.html
  • /blog/2012-9-4-second-post.html

Then, when generating the site, you can use a generator hook to create the blog index. Generator hooks aren't currently documented. But basically, they are callbacks that will run after generating each page (check this basic console output hook). Its first argument would be the path of the file that was generated (eg. /blog/2012-9-1-first-post). You can use the path to build the link and title of the post and append to a custom blog index page.

Also, we can follow your approach and introduce a special content handler for blogs, which would fetch the posts inside a single directory and create the pages. (Again, content handlers is a cool feature that I need to document. For now you can check the spec of the default content handler and also this example with a custom content handler, if you plan to write a custom content handler)

Anyway, I will be starting to port my own blog to Punch during this weekend. It would allow me to review the process more closely and introduce a more idiomatic way to handle blogs in Punch.

@superplussed

This comment has been minimized.

Show comment Hide comment
@superplussed

superplussed Sep 4, 2012

Contributor

Ah cool, thanks for that explanation. The thing I left out of my description is that I'd ideally like to have all of the blog posts displayed on a single page with pagination, and then have a permalink that looks like what you described above.

I think I might actually solve this using firebase, I think a Punch+BAAS option would be pretty cool.

Contributor

superplussed commented Sep 4, 2012

Ah cool, thanks for that explanation. The thing I left out of my description is that I'd ideally like to have all of the blog posts displayed on a single page with pagination, and then have a permalink that looks like what you described above.

I think I might actually solve this using firebase, I think a Punch+BAAS option would be pretty cool.

@laktek

This comment has been minimized.

Show comment Hide comment
@laktek

laktek Sep 5, 2012

Owner

Yep, Content Handler for Firebase would be really interesting. Feel free to
share your code when done. Also, ping me if you need any help along the way.

On Tue, Sep 4, 2012 at 9:52 PM, Jeremy Smith notifications@github.comwrote:

Ah cool, thanks for that explanation. The thing I left out of my
description is that I'd ideally like to have all of the blog posts
displayed on a single page with pagination, and then have a permalink that
looks like what you described above.

I think I might actually solve this using firebase, I think a Punch+BAAS
option would be pretty cool.


Reply to this email directly or view it on GitHubhttps://github.com/laktek/punch/issues/23#issuecomment-8269249.

Owner

laktek commented Sep 5, 2012

Yep, Content Handler for Firebase would be really interesting. Feel free to
share your code when done. Also, ping me if you need any help along the way.

On Tue, Sep 4, 2012 at 9:52 PM, Jeremy Smith notifications@github.comwrote:

Ah cool, thanks for that explanation. The thing I left out of my
description is that I'd ideally like to have all of the blog posts
displayed on a single page with pagination, and then have a permalink that
looks like what you described above.

I think I might actually solve this using firebase, I think a Punch+BAAS
option would be pretty cool.


Reply to this email directly or view it on GitHubhttps://github.com/laktek/punch/issues/23#issuecomment-8269249.

@pdlug

This comment has been minimized.

Show comment Hide comment
@pdlug

pdlug Sep 29, 2012

I'm wondering if you had any followup thoughts on this use case. I'm looking at the same sort of set up and the content handler approach is interesting but I would like to be able to mix it with the default content handler. The use case I'm thinking of is where there are pages and other assets with the regular content setup in the filesystem and blog posts or some other dynamic content in a database or other JSON filestore. Is there a way to delegate the content handlers to a path like /blog or /posts? I didn't see anything obvious in the docs or source.

pdlug commented Sep 29, 2012

I'm wondering if you had any followup thoughts on this use case. I'm looking at the same sort of set up and the content handler approach is interesting but I would like to be able to mix it with the default content handler. The use case I'm thinking of is where there are pages and other assets with the regular content setup in the filesystem and blog posts or some other dynamic content in a database or other JSON filestore. Is there a way to delegate the content handlers to a path like /blog or /posts? I didn't see anything obvious in the docs or source.

@laktek

This comment has been minimized.

Show comment Hide comment
@laktek

laktek Sep 29, 2012

Owner

@pdlug I'm currently working on a similar setup for my personal blog based on Punch. I will provide a detailed example when it's done (probably within next 2 weeks).

Owner

laktek commented Sep 29, 2012

@pdlug I'm currently working on a similar setup for my personal blog based on Punch. I will provide a detailed example when it's done (probably within next 2 weeks).

@pdlug

This comment has been minimized.

Show comment Hide comment
@pdlug

pdlug Nov 18, 2012

@laktek wondering if you had any further thoughts on this? This use case keeps coming up in my use of punch. I'm especially finding the need for shared data scoped to a section of the site, for example content/events needs a list of events shared with all subpages but I don't really want to add this to the toplevel shared.json

pdlug commented Nov 18, 2012

@laktek wondering if you had any further thoughts on this? This use case keeps coming up in my use of punch. I'm especially finding the need for shared data scoped to a section of the site, for example content/events needs a list of events shared with all subpages but I don't really want to add this to the toplevel shared.json

@laktek

This comment has been minimized.

Show comment Hide comment
@laktek

laktek Nov 18, 2012

Owner

@pdlug I'm actually working on this task at this very moment :) I just finished porting my blog to Punch and now extracting the blog handler to its own plugin. Hoping to release it this week.

BTW, is that event list contained in a JSON file? If so, you can add a symlink to it from the extended directory of each subpage. Then you should be able to use the event data as you'd normally do with other page specific data. Not a perfect solution but it should work.

Actually the better way to go about it would be to write a custom content handler. The blog content handler I'm working could be used as an example on how to write a custom content handler for specific sections, while delegating the handling of other content to default handler.

I'll update this thread as soon as I push the changes to GitHub.

Owner

laktek commented Nov 18, 2012

@pdlug I'm actually working on this task at this very moment :) I just finished porting my blog to Punch and now extracting the blog handler to its own plugin. Hoping to release it this week.

BTW, is that event list contained in a JSON file? If so, you can add a symlink to it from the extended directory of each subpage. Then you should be able to use the event data as you'd normally do with other page specific data. Not a perfect solution but it should work.

Actually the better way to go about it would be to write a custom content handler. The blog content handler I'm working could be used as an example on how to write a custom content handler for specific sections, while delegating the handling of other content to default handler.

I'll update this thread as soon as I push the changes to GitHub.

@pdlug

This comment has been minimized.

Show comment Hide comment
@pdlug

pdlug Nov 22, 2012

Yes, the list is in JSON, I hadn't considered symlinks that works just fine in this case.

pdlug commented Nov 22, 2012

Yes, the list is in JSON, I hadn't considered symlinks that works just fine in this case.

@paddykontschak

This comment has been minimized.

Show comment Hide comment
@paddykontschak

paddykontschak Nov 22, 2012

@laktek How about RSS/Atom feeds for a "punched" blog? Are normal feeds even possible with the way punch works? Or will we have to use an extra tool (Jekyll for example needs jsrss for feeds)?

@laktek How about RSS/Atom feeds for a "punched" blog? Are normal feeds even possible with the way punch works? Or will we have to use an extra tool (Jekyll for example needs jsrss for feeds)?

@laktek

This comment has been minimized.

Show comment Hide comment
@laktek

laktek Nov 26, 2012

Owner

If you want to run a blog with Punch, checkout the Punch Blog Boilerplate.

For more details about the implementation, check this post - http://www.laktek.com/2012/11/26/a-fast-intuitive-blogging-tool-based-on-punch

Owner

laktek commented Nov 26, 2012

If you want to run a blog with Punch, checkout the Punch Blog Boilerplate.

For more details about the implementation, check this post - http://www.laktek.com/2012/11/26/a-fast-intuitive-blogging-tool-based-on-punch

@laktek laktek closed this Apr 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment