Permalink
Browse files

category fixes

  • Loading branch information...
1 parent 92ebe0e commit b82fbeb27f95ff7d61ab30be2005b1c11a952b3b @benbalter committed Mar 1, 2013
View
@@ -5,6 +5,7 @@ window.Application =
Views: {}
router: {}
tags: {}
+ categories: {}
url: '{{ site.url }}'
name: '{{ site.name }}'
disqus:
@@ -56,6 +57,8 @@ class Application.Models.Tweet extends Backbone.Model
class Application.Models.Tag extends Backbone.Model
+class Application.Models.Category extends Backbone.Model
+
# Collections
class Application.Collections.Comments extends Backbone.Collection
@@ -118,6 +121,20 @@ class Application.Collections.Tags extends Backbone.Collection
tag.posts = new Application.Collections.Posts tag.posts
tags
+
+class Application.Collections.Categories extends Backbone.Collection
+ model: Application.Models.Category
+ url: ->
+ Application.url + "/categories.json"
+
+ initialize: ->
+ @fetch()
+
+ parse: (tags) ->
+ for tag in tags
+ tag.posts = new Application.Collections.Posts tag.posts
+ tags
+
# Views
class Application.Views.Post extends Backbone.View
@@ -133,6 +150,7 @@ class Application.Views.Post extends Backbone.View
@loadDisqus()
loadDisqus: ->
+ jQuery('#content').infinitescroll 'destory'
window.disqus_shortname = Application.disqus.name
window.disqus_identifier = @model.get 'id'
window.disqus_url = Application.url + '/' + @model.get 'id'
@@ -256,13 +274,21 @@ class Application.Views.Tag extends Backbone.View
jQuery('#content').infinitescroll 'destory'
@$el.html @template({ tag: @model.toJSON() })
+class Application.Views.Category extends Backbone.View
+ el: "#content"
+ template: JST.category
+ render: ->
+ jQuery('#content').infinitescroll 'destory'
+ @$el.html @template({ category: @model.toJSON() })
+
# Router
class Router extends Backbone.Router
routes:
":year/:month/:day/:slug/": "post"
- "tags/:tag/": "tags"
+ "tags/:tag/": "tag"
+ "categories/:category/": "category"
":slug/": "page"
"": "index"
@@ -286,11 +312,16 @@ class Router extends Backbone.Router
view.render()
@setNav 'home'
- tags: (tag) ->
+ tag: (tag) ->
Application.tags = new Application.Collections.Tags
Application.tags.on "reset", ->
new Application.Views.Tag( model: Application.tags.get tag ).render()
+ category: (category) ->
+ Application.categories = new Application.Collections.Categories
+ Application.categories.on "reset", ->
+ new Application.Views.Category( model: Application.categories.get category ).render()
+
redirect: ->
document.location = Application.url + "/" + Backbone.history.fragment

Large diffs are not rendered by default.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -25,7 +25,7 @@ <h2 class="title"><a href="{{ site.url}}{{ page.url }}">{{ page.title }}</a></h2
</div>
<div class="post-taxonomies">
- Posted in {% assign taxonomy = 'categories' %}{% include term-list-csv.html %} |
+ Posted in {% assign taxonomy = 'category' %}{% include term-list-csv.html %} |
Tagged {% assign taxonomy = 'tags' %}{% include term-list-csv.html %}
</div>
@@ -1,3 +1,3 @@
{% comment %}Prior to including, assign `taxonomy` to either tag or category{% endcomment %}
{% assign comma = false %}
-<span class="term-list term-list-{{taxonomy}}">{% for term in page[taxonomy] %}{% if comma == true %}, {% endif %}{% assign comma = true %}<a href="{{ site.url }}/{{ taxonomy }}/{{ term | downcase }}/">{{ term }}</a>{% endfor %}</span>
+<span class="term-list term-list-{{taxonomy}}">{% for term in page[taxonomy] %}{% if comma == true %}, {% endif %}{% assign comma = true %}<a href="{{ site.url }}/{{ taxonomy | replace "category","categories" }}/{{ term | downcase }}/">{{ term }}</a>{% endfor %}</span>
View
@@ -29,8 +29,8 @@ <h2 class="title"><a href="{{ site.url}}{{ page.url }}">{{ page.title }}</a></h2
</div>
<div class="post-taxonomies">
- Posted in {% assign taxonomy = 'category' %}{% include term-list-csv.html %} |
- Tagged {% assign taxonomy = 'tags' %}{% include term-list-csv.html %}
+ Posted in {% assign taxonomy = 'category' %}{% include term-list-csv.html %} |
+ Tagged {% assign taxonomy = 'tags' %}{% include term-list-csv.html %}
</div>
@@ -19,8 +19,10 @@ def generate(site)
def render_json(post, site)
- puts post.inspect
- return;
+ #add `json: false` to YAML to prevent JSONification
+ if post.data.has_key? "json" and !post.data["json"]
+ return
+ end
path = post.destination( site.source )
View
@@ -0,0 +1,6 @@
+<h1>Posts categorized "<%= category.id %>"</h1>
+<ul>
+<% category.posts.forEach( function( post ) { %>
+ <li><a href="<%= Application.url + post.get("url") %>"><%= post.get("title") %></a></li>
+<% }); %>
+</ul>
View
@@ -0,0 +1,15 @@
+---
+layout: page
+permalink: /categories/
+title: Categories
+json: false
+---
+
+{% for tag_hash in site.categories %}
+ <h3>{{ tag_hash.first }}</h3>
+ <ul>
+ {% for post in tag_hash.last %}
+ <li><a href="{{ site.url }}{{ post.url }}">{{ post.title }}</a></li>
+ {% endfor %}
+ </ul>
+{% endfor %}

0 comments on commit b82fbeb

Please sign in to comment.