Permalink
Browse files

add tag support

  • Loading branch information...
1 parent e807a8d commit 92ebe0e396707375101bad916249d45fa908b014 @benbalter committed Mar 1, 2013
View
@@ -25,3 +25,6 @@
var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2),GOOG_FIXURL_SITE = location.host;
</script>
<script src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>
+ <script>
+ window.is404 = true;
+ </script>
View
@@ -4,6 +4,7 @@ window.Application =
Collections: {}
Views: {}
router: {}
+ tags: {}
url: '{{ site.url }}'
name: '{{ site.name }}'
disqus:
@@ -53,6 +54,8 @@ class Application.Models.Comment extends Backbone.Model
class Application.Models.Tweet extends Backbone.Model
+class Application.Models.Tag extends Backbone.Model
+
# Collections
class Application.Collections.Comments extends Backbone.Collection
@@ -79,9 +82,8 @@ class Application.Collections.Tweets extends Backbone.Collection
class Application.Collections.Posts extends Backbone.Collection
model: Application.Models.Post
-
url: ->
- Application.url + "/" + 'posts.json'
+ Application.url + "/" + 'pages.json'
comparator: (a, b) ->
a = a.get 'date'
@@ -103,6 +105,19 @@ class Application.Collections.Pages extends Backbone.Collection
url: ->
Application.url + "/" + 'pages.json'
+class Application.Collections.Tags extends Backbone.Collection
+ model: Application.Models.Tag
+ url: ->
+ Application.url + "/tags.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
@@ -158,6 +173,7 @@ class Application.Views.Page extends Backbone.View
template: JST.page
render: =>
+ jQuery('#content').infinitescroll 'destory'
@$el.html @template @model.toJSON()
if DISQUS?
DISQUS.reset()
@@ -174,6 +190,8 @@ class Application.Views.Single extends Backbone.View
@model.on 'change', @render
render: =>
+ jQuery('#content').infinitescroll 'destory'
+
@$el.html @template @model.toJSON()
if @model.get('layout') is "post"
@@ -188,6 +206,7 @@ class Application.Views.Single extends Backbone.View
scrollTarget: ".title"
offset: -60
+
class Application.Views.Index extends Backbone.View
el: "#content"
template: $("#index_layout").html()
@@ -204,6 +223,10 @@ class Application.Views.Index extends Backbone.View
tweets = new Application.Collections.Tweets
view = new Application.Views.TweetView collection: tweets
tweets.fetch()
+ jQuery('#content').infinitescroll
+ navSelector: "nav.pagination"
+ nextSelector: "nav.pagination #next"
+ itemSelector: "article.post"
class Application.Views.CommentView extends Backbone.View
el: "#recentcomments"
@@ -225,11 +248,21 @@ class Application.Views.TweetView extends Backbone.View
render: =>
@$el.html @template tweets: @collection.toJSON()
+class Application.Views.Tag extends Backbone.View
+ el: "#content"
+ template: JST.tag
+
+ render: ->
+ jQuery('#content').infinitescroll 'destory'
+ @$el.html @template({ tag: @model.toJSON() })
+
+
# Router
class Router extends Backbone.Router
routes:
":year/:month/:day/:slug/": "post"
+ "tags/:tag/": "tags"
":slug/": "page"
"": "index"
@@ -253,6 +286,11 @@ class Router extends Backbone.Router
view.render()
@setNav 'home'
+ tags: (tag) ->
+ Application.tags = new Application.Collections.Tags
+ Application.tags.on "reset", ->
+ new Application.Views.Tag( model: Application.tags.get tag ).render()
+
redirect: ->
document.location = Application.url + "/" + Backbone.history.fragment
@@ -267,6 +305,10 @@ Application.pages = new Application.Collections.Pages
Application.router = new Router()
Backbone.history.start pushState: true, silent: true
+if is404?
+ slug = document.location.pathname.replace("/","")
+ Application.router.navigate slug, trigger: true
+
jQuery(document).ready ->
window.resume_resize = ->
@@ -277,11 +319,12 @@ jQuery(document).ready ->
$('a[href^="{{ site.url }}/"]').live 'click', (e) ->
e.preventDefault()
- Application.router.navigate $(@).attr('href').replace( '{{ site.url }}/', '' ), true
+ Application.router.navigate $(@).attr('href').replace( '{{ site.url }}/', '' ), trigger: true
false
- jQuery('#content').infinitescroll
- navSelector: "nav.pagination"
- nextSelector: "nav.pagination #next"
- itemSelector: "article.post"
+ if Backbone.history.fragment == ""
+ jQuery('#content').infinitescroll
+ navSelector: "nav.pagination"
+ nextSelector: "nav.pagination #next"
+ itemSelector: "article.post"

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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 }}/{{ term | downcase }}/">{{ term }}</a>{% endfor %}</span>
View
@@ -2,7 +2,7 @@
<div class="term-list tern-list-{{taxonomy}}">
{% for term in site[taxonomy] %}
{% assign term_slug = term[0] %}
- <h2 id="{{ term_slug | downcase }}"><a href="#{{ term_slug }}">{{ term_slug }}</a></h2>
+ <h2 id="{{ term_slug | downcase }}"><a href="{{ term_slug }}">{{ term_slug }}</a></h2>
<ul>
{% for page in site[taxonomy][term_slug] %}
<li><a href="{{ site.url }}{{ page.url }}">{{ page.title }}</a></li>
@@ -19,6 +19,9 @@ def generate(site)
def render_json(post, site)
+ puts post.inspect
+ return;
+
path = post.destination( site.source )
#only act on post/pages index in /index.html
View
@@ -22,7 +22,7 @@
</div>
<div class="post-taxonomies">
- Posted in <a href="categories/<%= category %>"><%= category %></a> | Tagged <% _.each( tags, function(tag){ %> <a href="tags/<%= tag %>"><%= tag %></a>, <% }); %>
+ Posted in <a href="{{ site.url }}/categories/<%= category %>/"><%= category %></a> | Tagged <% _.each( tags, function(tag){ %> <a href="{{ site.url }}/tags/<%= tag %>/"><%= tag %></a>, <% }); %>
</div>
</article>
@@ -12,7 +12,7 @@
</div>
<div class="post-taxonomies">
- Posted in <a href="categories/<%= category %>"><%= category %></a> | Tagged <% _.each( tags, function(tag){ %> <a href="tags/<%= tag %>"><%= tag %></a>, <% }); %>
+ Posted in <a href="{{ site.url }}/categories/<%= category %>"><%= category %></a> | Tagged <% _.each( tags, function(tag){ %> <a href="{{ site.url }}/tags/<%= tag %>"><%= tag %></a>, <% }); %>
</div>
</article>
View
@@ -0,0 +1,6 @@
+<h1>Posts tagged "<%= tag.id %>"</h1>
+<ul>
+<% tag.posts.forEach( function( post ) { %>
+ <li><a href="<%= Application.url + post.get("url") %>"><%= post.get("title") %></a></li>
+<% }); %>
+</ul>
View
@@ -0,0 +1,21 @@
+---
+layout: none
+---
+{% capture json %}
+{
+{% for tag_hash in site.categories %}
+"{{ tag_hash.first }}":[
+{% for page in tag_hash.last %}
+{
+"id":"{{ page.id }}",
+"url":"{{ page.url }}",
+"title":"{{ page.title | strip_newlines | replace:'"','' }}"
+}
+{% if forloop.last %}{% else %},{% endif %}
+{% endfor %}
+]
+{% if forloop.last %}{% else %},{% endif %}
+{% endfor %}
+}
+{% endcapture %}
+{{ json | strip_newlines }}
View
@@ -0,0 +1,15 @@
+---
+layout: page
+permalink: /tags/
+title: Tags
+json: false
+---
+
+{% for tag_hash in site.tags %}
+ <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 %}
View
@@ -0,0 +1,24 @@
+---
+layout: none
+---
+{% capture json %}
+[
+{% for tag_hash in site.tags %}
+{
+"id":"{{ tag_hash.first }}",
+"posts":[
+{% for page in tag_hash.last %}
+{
+"id":"{{ page.id | downcase }}",
+"url":"{{ page.url }}",
+"title":"{{ page.title | strip_newlines | replace:'"','' }}"
+}
+{% if forloop.last %}{% else %},{% endif %}
+{% endfor %}
+]
+}
+{% if forloop.last %}{% else %},{% endif %}
+{% endfor %}
+]
+{% endcapture %}
+{{ json | strip_newlines }}

0 comments on commit 92ebe0e

Please sign in to comment.