Created
May 17, 2013 09:07
-
-
Save hengkiardo/5597925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// Configure Disqus with ...pshaw... globals. | |
var disqus_shortname = 'your shortname goes here TODO'; | |
</script> | |
<div class="row-fluid"> | |
<section class="blog"> | |
{{#posts}} | |
<article> | |
<h3><a href="/blog/{{id}}">{{title}}</a></h3> | |
<!-- Using rel="author" is part of getting your face in Google results :) --> | |
<div class="author"><a href="http://kun.io/" rel="author">William P. Riley-Land</a></div> | |
<time>{{date}}</time> | |
<div>{{{body}}}</div> | |
<div class="tags-wrapper"> | |
<em>tags</em> | |
<ul class="tags"> | |
{{#tags}} | |
<li class="label label-inverse">#{{.}}</li> | |
{{/tags}} | |
</ul> | |
</div> | |
{{^singleArticle}} | |
<div class="count-wrapper"> | |
<a href="http://kun.io/blog/{{id}}#disqus_thread">comments</a> | |
</div> | |
{{/singleArticle}} | |
{{#singleArticle}} | |
<div class="share-wrapper"> | |
<!-- TODO probably best for you to regenerate these to get the look and feel you want, | |
and to make sure they are configured properly. Also, this Facebook button is deprecated. | |
http://developers.facebook.com/docs/reference/plugins/like/ | |
https://dev.twitter.com/docs/tweet-button | |
https://developer.linkedin.com/plugins/share-plugin-generator | |
https://developers.google.com/+/plugins/share/ | |
--> | |
<!-- Begin Twitter share button --> | |
<a href="https://twitter.com/share" class="twitter-share-button" | |
data-via="xyz TODO" data-related="xyz TODO">Tweet</a> | |
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> | |
<!-- End Twitter share button --> | |
<!-- begin LinkedIn share button --> | |
<script src="//platform.linkedin.com/in.js" type="text/javascript"></script> | |
<script type="IN/Share" data-counter="right"></script> | |
<!-- End LinkedIn share button --> | |
<!-- Begin Google+ share button --> | |
<!-- Place this tag where you want the share button to render. --> | |
<div class="g-plus" data-action="share" data-annotation="bubble"></div> | |
<!-- Place this tag after the last share tag. --> | |
<script type="text/javascript"> | |
(function() { | |
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; | |
po.src = 'https://apis.google.com/js/plusone.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); | |
})(); | |
</script> | |
<!-- End Google+ share button --> | |
<!-- Begin Facebook share button --> | |
<div class="fb-like" data-send="false" data-layout="button_count" | |
data-width="450" data-show-faces="false" | |
data-font="lucida grande"> | |
</div> | |
<!-- End Facebook share button --> | |
</div> | |
<div class="comments"> | |
<div id="disqus_thread"> </div> | |
<!-- start Disqus comments --> | |
<script type="text/javascript"> | |
(function() { | |
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; | |
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; | |
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); | |
})(); | |
</script> | |
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> | |
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> | |
<!-- end Disqus comments --> | |
</div> | |
{{/singleArticle}} | |
</article> | |
{{/posts}} | |
</section> | |
</div> | |
<script type="text/javascript"> | |
(function () { | |
// Split up the URL and get the last piece, if it doesn't === 'blog', display | |
// only the article references by ID, instead of a list. | |
var urlParts = document.location.pathname.split('/'); | |
var articleId = urlParts[ urlParts.length - 1 ]; | |
var isSingleArticle = (articleId !== 'blog'); // TODO error check or summin' | |
var setDisqusCount = function () { | |
var s = document.createElement('script'); s.async = true; | |
s.type = 'text/javascript'; | |
s.src = 'http://' + disqus_shortname + '.disqus.com/count.js'; | |
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); | |
}; | |
$(document).ready( function () { | |
// If in list view, make set comment count for each article | |
if (!isSingleArticle) setDisqusCount(); | |
}); | |
})(); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mikeal's awesome request package (manipulates http requests) | |
var request = require('request'); | |
// I have some boilerplate controller code that takes objects like this and makes express routes | |
module.exports = { | |
view: 'blog.html', | |
routes: ['/blog/:id?'], | |
pre: function ( options, callback ) { // this is run before other middleware on the route | |
// options.request | |
var id = options.request.params.id; | |
var querystring = { | |
api_key: 'your Tumblr API key TODO' | |
}; | |
if (id) { | |
// Don't load the list of articles, load the one specified by ID... | |
// set some locals for the mustache template and edit the query string | |
// to only fetch one article. | |
options.locals.singleArticle = true; | |
querystring.id = id; | |
querystring.limit = 1; | |
} | |
request( | |
{ | |
uri: 'http://api.tumblr.com/v2/blog/wprl.tumblr.com/posts/text', // Use your tumblr ID here. TODO | |
qs: querystring | |
}, | |
function (error, response, body) { | |
if(!response || response.statusCode !== 200){ //} || body.response.meta.status !==200 ){ | |
// TODO error handling | |
return callback(options); | |
} | |
// body is a JSON string and needs to be parsed to an object | |
body = JSON.parse(body); | |
// Add the post(s) to locals for the Mustache template | |
options.locals.posts = body.response.posts; | |
callback(options); | |
} | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment