Last active
December 21, 2015 22:29
-
-
Save pvandervelde/6375681 to your computer and use it in GitHub Desktop.
The snippets of code from my personal website made in Docpad
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
collections: | |
pages: -> | |
@getCollection("html").findAllLive({isPage:true},[{order:1}]).on "add", (model) -> | |
model.setMetaDefaults({layout:"default"}) | |
posts: (database) -> | |
database.findAllLive({relativeOutDirPath:'posts'},[{date:-1}]).on "add", (model) -> | |
model.setMetaDefaults({layout:"post"}) | |
projects: -> | |
@getCollection('html').findAllLive({relativeOutDirPath:'projects'},[{title:1}]).on "add", (model) -> | |
model.setMetaDefaults({layout:"project"}) | |
frontpage: -> | |
@getCollection("html").findAllLive({relativeOutDirPath: $in: ['posts','projects']},[{date: -1}]) |
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
<div id="post"> | |
<div id="post-header"> | |
<h2> | |
<% if @post.id is @document.id: %> | |
<%= @post.title %> | |
<% else: %> | |
<a href='<%= @post.url%>'><%= @post.title %></a> | |
<% end %> | |
</h2> | |
<div id="post-meta"> | |
<p> | |
<%= @post.date.toLocaleDateString() %> | Posted in | |
<% for tag in @post.tags: %> | |
<a id="post-category" href="/tags/<%= tag %>.html"><%= tag %></a> | |
<% end %> | |
</p> | |
</div> | |
</div> | |
<div id="post-content"> | |
<%- @post.contentRenderedWithoutLayouts %> | |
</div> | |
</div> |
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
--- | |
layout: "default" | |
--- | |
<!-- | |
Commenting is based on: http://ivanzuzak.info/2011/02/18/github-hosted-comments-for-github-hosted-blogs.html | |
--> | |
<div id="post"> | |
<%- @partial('post-content', {post: @document})%> | |
<div id="post-footer"> | |
<div> | |
<%- @getNavLinks() %> | |
</div> | |
</div> | |
<script type="text/javascript" src="http://datejs.googlecode.com/svn/trunk/build/date-en-US.js"></script> | |
<script type="text/javascript"> | |
$("#post p").each( function(index) { | |
if (index > 0 && $.trim($(this).text()).length > 0) { | |
$(this).attr("id", "par" + index.toString()); | |
var html = $(this).html(); | |
$(this).html(html + " <a href='#par" + index.toString() + "'>#</a>"); | |
} | |
}); | |
</script> | |
<div id="post-comments> | |
<h2>Comments</h2> | |
<div id="post-comment-header"> | |
Want to leave a comment? Visit <a href="https://github.com/<%= @site.githubuser %>/<%= @site.githubrepository %>/issues/<%= @document.commentIssueId %>"> this post's issue page on | |
GitHub</a> (you'll need a GitHub account). | |
</div> | |
</div> | |
<script type="text/javascript"> | |
function loadComments(data) { | |
for (var i=0; i<data.length; i++) { | |
var cuser = data[i].user.login; | |
var cuserlink = "https://www.github.com/" + data[i].user.login; | |
var clink = "https://github.com/<%= @site.githubuser %>/<%= @site.githubrepository %>/issues/<%= @document.commentIssueId %>#issuecomment-" + data[i].url.substring(data[i].url.lastIndexOf("/")+1); | |
var cbody = data[i].body_html; | |
var cavatarlink = data[i].user.avatar_url; | |
var cdate = Date.parse(data[i].created_at).toString("yyyy-MM-dd HH:mm:ss"); | |
$("#post-comments").append("<div id='post-comment'><div id='post-comment-header'><div id='post-comment-gravatar'>" + '<img src="' + cavatarlink + '" alt="" width="20" height="20">' + "</div><a id='post-comment-user' href=\""+ cuserlink + "\">" + cuser + "</a><a id='post-comment-date' href=\"" + clink + "\">" + cdate + "</a></div><div id='post-comment-body'>" + cbody + "</div></div>"); | |
} | |
} | |
$.ajax("https://api.github.com/repos/<%= @site.githubuser %>/<%= @site.githubrepository %>/issues/<%= @document.commentIssueId %>/comments", { | |
headers: {Accept: "application/vnd.github.full+json"}, | |
dataType: "json", | |
success: function(msg){ | |
loadComments(msg); | |
} | |
}); | |
</script> | |
</div> |
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
<div id="project-linkedposts"> | |
<h3>Posts referencing <%= @title %></h3> | |
<ul> | |
<% for doc in @getCollection('posts').findAll({tags: '$in': @title}).toJSON(): %> | |
<li><a href="<%= doc.url %>"><%= doc.title %></a></li> | |
<% end %> | |
</ul> | |
</div> |
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
--- | |
layout: "default" | |
--- | |
<div class="project"> | |
<h2><%- @document.title %></h2> | |
<div> | |
<%- @content %> | |
</div> | |
<div> | |
<%- @partial('project-linkedposts', { title: @document.title })%> | |
</div> | |
</div> |
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
<h2>Recent</h2> | |
<ul> | |
<% for recent in @getCollection("frontpage").toJSON()[0..9]: %> | |
<li><a href="<%= recent.url %>"><%= recent.title %></a></li> | |
<% end %> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment