Skip to content

Instantly share code, notes, and snippets.

@anthonymoralez
Last active April 28, 2017 20:55
Show Gist options
  • Select an option

  • Save anthonymoralez/75cc0607e19fdf956485d514736c2473 to your computer and use it in GitHub Desktop.

Select an option

Save anthonymoralez/75cc0607e19fdf956485d514736c2473 to your computer and use it in GitHub Desktop.
Adding Tags
<!DOCTYPE HTML>
<html lang='en'>
<head>
<!-- Elided: a bunch of header stuff -->
</head>
<body>
<nav class='navbar navbar-inverse' >
<div class='container-fluid'>
<div class='collapse navbar-collapse' >
<!-- Elided: Navbar top of the page -->
</div>
</div>
</nav>
<section class='content'>
<%= yield %>
</section>
</body>
</html>
<!DOCTYPE HTML>
<html lang='en'>
<head>
<!-- Elided: a bunch of header stuff -->
</head>
<body>
<nav class='navbar navbar-inverse' >
<div class='container-fluid'>
<div class='collapse navbar-collapse' >
<!-- Elided: Navbar top of the page -->
</div>
</div>
</nav>
<section class='container'>
<div class="row">
<div class="col-md-8">
<%= yield %>
</div>
<% if content_for(@item, :tags) %>
<div class="col-md-3">
<div class="tags panel panel-default affix">
<div class="panel-heading">Tags</div>
<div class="panel-body">
<%= content_for(@item, :tags) || '(none)' %>
</div>
</div>
</div>
<% end %>
</div>
</section>
</body>
</html>
<% render '/default.html' do %>
<% content_for :tags, tags_for(@item, base_url: "/") %>
<div class="post panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><%= item[:title] %></h3>
<aside>Posted at: <%= get_pretty_date(item) %></aside>
</div>
<article class="panel-body">
<%= yield %>
</article>
</div>
<% end %>
<% render '/default.html' do %>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><%= item[:title] %></h3>
<aside>Posted at: <%= get_pretty_date(item) %></aside>
</div>
<article class="panel-body">
<%= yield %>
</article>
</div>
<% end %>
preprocess do
tags = @items.map { |i| i[:tags] }.flatten.uniq
tags.each do |tag|
next unless tag
content = ''
attributes = { tag: tag }
identifier = "/tags/#{tag}"
@items.create(content, attributes, identifier)
end
end
compile '/tags/*' do
layout '/tags.*'
end
route '/tags/*' do
'/' + item.identifier.to_s.split('/')[-1] + '/index.html'
end
compile '/posts/**.md' do
filter :kramdown
filter :gists
layout '/post.*'
end
<% render '/default.html' do %>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><%= @item[:tag] %></h3>
</div>
<div class='panel-body'>
<% items_with_tag(@item[:tag]).each do |post| %>
<div class='post panel panel-default'>
<div class='panel-heading'>
<h1 class='panel-title'><%= link_to post[:title], post.path %></h1>
<aside>Posted at: <%= get_pretty_date post %></aside>
</div>
<article class='panel-body'>
<%= get_post_start post %>
</article>
</div>
<% end %>
</div>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment