Skip to content

Commit

Permalink
add tags
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Jul 27, 2016
1 parent c09fefc commit b90c1c8
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 3 deletions.
8 changes: 8 additions & 0 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<article role="main" class="blog-post">
{% if page.tags.size > 0 %}
<div class="blog-tags">
Tags:
{% for tag in page.tags %}
<a class="tag_list_link" href="/tag/{{ tag }}">{{ tag }}</a>
{% endfor %}
</div>
{% endif %}
{{ content }}
</article>

Expand Down
42 changes: 42 additions & 0 deletions _layouts/tag_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
layout: default
show-avatar: false
---

<h2 class="post_title">{{page.title}}:</h2>

<div class="posts-list">
{% for post in site.posts %}
{% for tag in post.tags %}
{% if tag == page.tag %}
<article class="post-preview">
<a href="{{ post.url | prepend: site.baseurl }}">
<h3 class="post-title">{{ post.title }}</h3>

{% if post.subtitle %}
<h4 class="post-subtitle">
{{ post.subtitle }}
</h4>
{% endif %}
</a>

<p class="post-meta">
Posted on {{ post.date | date: "%B %-d, %Y" }}
</p>

<div class="post-entry">
{{ post.content | strip_html | xml_escape | truncatewords: 50 }}
<a href="{{ post.url | prepend: site.baseurl }}" class="post-read-more">[Read&nbsp;More]</a>
</div>

<div class="blog-tags">
Tags:
{% for tag in post.tags %}
<a href="/tag/{{ tag }}">{{ tag }}</a>
{% endfor %}
</div>
</article>
{% endif %}
{% endfor %}
{% endfor %}
</div>
33 changes: 33 additions & 0 deletions _plugins/_tag_gen.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Jekyll
class TagIndex < Page
def initialize(site, base, dir, tag)
@site = site
@base = base
@dir = dir
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
self.data['tag'] = tag
tag_title_prefix = site.config['tag_title_prefix'] || 'Posts Tagged &ldquo;'
tag_title_suffix = site.config['tag_title_suffix'] || '&rdquo;'
self.data['title'] = "#{tag_title_prefix}#{tag}#{tag_title_suffix}"
end
end
class TagGenerator < Generator
safe true
def generate(site)
if site.layouts.key? 'tag_index'
dir = site.config['tag_dir'] || 'tag'
site.tags.keys.each do |tag|
write_tag_index(site, File.join(dir, tag), tag)
end
end
end
def write_tag_index(site, dir, tag)
index = TagIndex.new(site, site.source, dir, tag)
index.render(site.layouts, site.site_payload)
index.write(site.dest)
site.pages << index
end
end
end
3 changes: 2 additions & 1 deletion _posts/2015-01-04-first-post.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: post
title: First post!
tags: [random, exciting-stuff]
---

This is my first post, how exciting!
This is my first post, how exciting!
3 changes: 2 additions & 1 deletion _posts/2015-01-15-pirates.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: post
title: Pirates arrrr
tags: [pirates, random]
---

Piracy is typically an act of robbery or criminal violence at sea. The term can include acts committed on land, in the air, or in other major bodies of water or on a shore. It does not normally include crimes committed against persons traveling on the same vessel as the perpetrator (e.g. one passenger stealing from others on the same vessel). The term has been used throughout history to refer to raids across land borders by non-state agents.
Piracy is typically an act of robbery or criminal violence at sea. The term can include acts committed on land, in the air, or in other major bodies of water or on a shore. It does not normally include crimes committed against persons traveling on the same vessel as the perpetrator (e.g. one passenger stealing from others on the same vessel). The term has been used throughout history to refer to raids across land borders by non-state agents.
3 changes: 2 additions & 1 deletion _posts/2015-01-27-dear-diary.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: post
title: Dear diary
tags: [random, diary, school]
---

What is it with that Mary girl? Dragging me to school every day. As if I had a choice. What you don't hear in those nursery rhymes is that she starves me if I don't go to school with her; it's the only way I can stay alive! I'm thinking about being adopted by Little Bo Peep, sure I may get lost, but anything is better than being with Mary and those little brats at school (shudder, shudder).
What is it with that Mary girl? Dragging me to school every day. As if I had a choice. What you don't hear in those nursery rhymes is that she starves me if I don't go to school with her; it's the only way I can stay alive! I'm thinking about being adopted by Little Bo Peep, sure I may get lost, but anything is better than being with Mary and those little brats at school (shudder, shudder).
28 changes: 28 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,34 @@ footer .theme-by {
}
}

/* --- Tags --- */

.blog-tags {
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
color: #999;
font-size: 15px;
padding-top: 5px;
/* margin-bottom: 5px; */
}

.blog-tags a {
/* color: #999; */
color: #008AFF;
text-decoration: none;
padding: 0px 5px;
}

.blog-tags a:hover {
-moz-border-radius-topleft: 2px;
-moz-border-radius-topright: 2px;
-moz-border-radius-bottomright: 2px;
-moz-border-radius-bottomleft: 2px;
-webkit-border-radius: 2px 2px 2px 2px;
border-radius: 2px 2px 2px 2px;
color: #008AFF;
background-color: #CCC;
}

/* --- Post and page headers --- */

.intro-header {
Expand Down
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ <h3 class="post-subtitle">
<a href="{{ post.url | prepend: site.baseurl }}" class="post-read-more">[Read&nbsp;More]</a>
</div>

{% if post.tags.size > 0 %}
<div class="blog-tags">
Tags:
{% for tag in post.tags %}
<a href="/tag/{{ tag }}">{{ tag }}</a>
{% endfor %}
</div>
{% endif %}
</article>
{% endfor %}
</div>
Expand Down

0 comments on commit b90c1c8

Please sign in to comment.